org.antlr.v4.runtime.InputMismatchException.getExpectedTokens()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中org.antlr.v4.runtime.InputMismatchException.getExpectedTokens()方法的一些代码示例,展示了InputMismatchException.getExpectedTokens()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InputMismatchException.getExpectedTokens()方法的具体详情如下:
包路径:org.antlr.v4.runtime.InputMismatchException
类名称:InputMismatchException
方法名:getExpectedTokens

InputMismatchException.getExpectedTokens介绍

暂无

代码示例

代码示例来源:origin: org.antlr/antlr4-runtime

/**
 * This is called by {@link #reportError} when the exception is an
 * {@link InputMismatchException}.
 *
 * @see #reportError
 *
 * @param recognizer the parser instance
 * @param e the recognition exception
 */
protected void reportInputMismatch(Parser recognizer,
                  InputMismatchException e)
{
  String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+
  " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary());
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}

代码示例来源:origin: org.antlr/antlr4-runtime

Token tok = e.getOffendingToken();
int expectedTokenType = Token.INVALID_TYPE;
if ( !ime.getExpectedTokens().isNil() ) {
  expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element

代码示例来源:origin: bkiers/Liqp

private static String createMessage(RecognitionException e) {
 Token offendingToken = e.getOffendingToken();
 String[] inputLines = e.getInputStream().toString().split("\r?\n|\r");
 String errorLine = inputLines[offendingToken.getLine() - 1];
 StringBuilder message = new StringBuilder(String.format("\nError on line %s, column %s:\n",
     offendingToken.getLine(), offendingToken.getCharPositionInLine()));
 message.append(errorLine).append("\n");
 for (int i = 0; i < offendingToken.getCharPositionInLine(); i++) {
  message.append(" ");
 }
 message.append("^");
 if (e instanceof InputMismatchException) {
  InputMismatchException ime = (InputMismatchException)e;
  return String.format("%s\nmatched '%s' as token <%s>, expecting token <%s>",
    message, offendingToken.getText(), tokenName(offendingToken.getType()), tokenNames(ime.getExpectedTokens()));
 }
 if (e instanceof FailedPredicateException) {
  FailedPredicateException fpe = (FailedPredicateException)e;
  return String.format("%s\nfailed predicate '%s' after position %s",
    message, fpe.getPredicate(), offendingToken.getCharPositionInLine());
 }
 if (e instanceof NoViableAltException || e instanceof LexerNoViableAltException) {
  return String.format("%s\ncould not decide what path to take, at position %s",
    message, offendingToken.getCharPositionInLine());
 }
 return message + "\nAn unknown error occurred!";
}

代码示例来源:origin: org.ballerinalang/ballerina-lang

@Override
public void reportInputMismatch(Parser parser, InputMismatchException e) {
  setErrorState(parser);
  Token offendingToken = e.getOffendingToken();
  String mismatchedToken = getTokenErrorDisplay(offendingToken);
  String expectedToken = e.getExpectedTokens().toString(parser.getVocabulary());
  DiagnosticPos pos = getPosition(offendingToken);
  dlog.error(pos, DiagnosticCode.MISMATCHED_INPUT, mismatchedToken, expectedToken);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * This is called by {@link #reportError} when the exception is an
 * {@link InputMismatchException}.
 *
 * @see #reportError
 *
 * @param recognizer the parser instance
 * @param e the recognition exception
 */
protected void reportInputMismatch(Parser recognizer,
                  InputMismatchException e)
{
  String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+
  " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary());
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}

代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime

/**
 * This is called by {@link #reportError} when the exception is an
 * {@link InputMismatchException}.
 *
 * @see #reportError
 *
 * @param recognizer the parser instance
 * @param e the recognition exception
 */
protected void reportInputMismatch(Parser recognizer,
                  InputMismatchException e)
{
  String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+
  " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary());
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * This is called by {@link #reportError} when the exception is an
 * {@link InputMismatchException}.
 *
 * @see #reportError
 *
 * @param recognizer the parser instance
 * @param e the recognition exception
 */
protected void reportInputMismatch(Parser recognizer,
                  InputMismatchException e)
{
  String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+
  " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary());
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}

代码示例来源:origin: espertechinc/esper

if (mismatched.getExpectedTokens().size() > 1) {
  StringWriter writer = new StringWriter();
  writer.append("any of the following tokens {");
  String delimiter = "";
  for (int i = 0; i < mismatched.getExpectedTokens().size(); i++) {
    writer.append(delimiter);
    if (i > 5) {
      writer.append("...");
      writer.append(Integer.toString(mismatched.getExpectedTokens().size() - 5));
      writer.append(" more");
      break;
    writer.append(getTokenText(parser, mismatched.getExpectedTokens().get(i)));
  expected = getTokenText(parser, mismatched.getExpectedTokens().get(0));

代码示例来源:origin: com.espertech/esper-compiler

if (mismatched.getExpectedTokens().size() > 1) {
  StringWriter writer = new StringWriter();
  writer.append("any of the following tokens {");
  String delimiter = "";
  for (int i = 0; i < mismatched.getExpectedTokens().size(); i++) {
    writer.append(delimiter);
    if (i > 5) {
      writer.append("...");
      writer.append(Integer.toString(mismatched.getExpectedTokens().size() - 5));
      writer.append(" more");
      break;
    writer.append(getTokenText(parser, mismatched.getExpectedTokens().get(i)));
  expected = getTokenText(parser, mismatched.getExpectedTokens().get(0));

代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime

/**
 * This is called by {@link #reportError} when the exception is an
 * {@link InputMismatchException}.
 *
 * @see #reportError
 *
 * @param recognizer the parser instance
 * @param e the recognition exception
 */
protected void reportInputMismatch(@NotNull Parser recognizer,
                  @NotNull InputMismatchException e)
{
  String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken(recognizer))+
  " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary());
  notifyErrorListeners(recognizer, msg, e);
}

代码示例来源:origin: javamonkey/beetl2.0

protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e)
{
  Token t1 = recognizer.getInputStream().LT(-1);
  String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 "
      + e.getExpectedTokens().toString(recognizer.getTokenNames());
  BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e);
  //		exception.token = this.getGrammarToken(e.getOffendingToken());
  exception.pushToken(this.getGrammarToken(t1));
  throw exception;
}

代码示例来源:origin: com.ibeetl/beetl

protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e)
{
  Token t1 = recognizer.getInputStream().LT(-1);
  String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 "
      + e.getExpectedTokens().toString(recognizer.getTokenNames());
  BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e);
  //		exception.token = this.getGrammarToken(e.getOffendingToken());
  exception.pushToken(this.getGrammarToken(t1));
  throw exception;
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

Token tok = e.getOffendingToken();
int expectedTokenType = Token.INVALID_TYPE;
if ( !ime.getExpectedTokens().isNil() ) {
  expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element

代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime

Token tok = e.getOffendingToken();
int expectedTokenType = Token.INVALID_TYPE;
if ( !ime.getExpectedTokens().isNil() ) {
  expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element

代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime

InputMismatchException ime = (InputMismatchException)e;
Token tok = e.getOffendingToken();
int expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
Token errToken =
  getTokenFactory().create(new Pair<TokenSource, CharStream>(tok.getTokenSource(), tok.getTokenSource().getInputStream()),

相关文章