java类org.antlr.v4.runtime.InputMismatchException的实例源码

ParserErrorStrategy.java 文件源码 项目:elasticsearch_my 阅读 25 收藏 0 点赞 0 评论 0
@Override
public void recover(final Parser recognizer, final RecognitionException re) {
    final Token token = re.getOffendingToken();
    String message;

    if (token == null) {
        message = "no parse token found.";
    } else if (re instanceof InputMismatchException) {
        message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
                " was expecting one of [" + re.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
    } else if (re instanceof NoViableAltException) {
        if (token.getType() == PainlessParser.EOF) {
            message = "unexpected end of script.";
        } else {
            message = "invalid sequence of tokens near [" + getTokenErrorDisplay(token) + "].";
        }
    } else {
        message =  "unexpected token near [" + getTokenErrorDisplay(token) + "].";
    }

    Location location = new Location(sourceName, token == null ? -1 : token.getStartIndex());
    throw location.createError(new IllegalArgumentException(message, re));
}
FWPolicyErrorStrategy.java 文件源码 项目:oscm-app 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Make sure we don't attempt to recover inline; if the parser successfully
 * recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String policies = recognizer.getInputStream().getText();
    StringTokenizer tk = new StringTokenizer(policies, ";");
    String policy = "";
    int idx = 0;
    while (tk.hasMoreElements()) {
        policy = (String) tk.nextElement();
        idx += policy.length();
        if (idx >= e.getOffendingToken().getStartIndex()) {
            break;
        }
    }

    String message = Messages.get(Messages.DEFAULT_LOCALE,
            "error_invalid_firewallconfig", new Object[] {
                    e.getOffendingToken().getText(), policy });
    throw new RuntimeException(message);
}
FWPolicyErrorStrategy.java 文件源码 项目:oscm 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Make sure we don't attempt to recover inline; if the parser successfully
 * recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String policies = recognizer.getInputStream().getText();
    StringTokenizer tk = new StringTokenizer(policies, ";");
    String policy = "";
    int idx = 0;
    while (tk.hasMoreElements()) {
        policy = (String) tk.nextElement();
        idx += policy.length();
        if (idx >= e.getOffendingToken().getStartIndex()) {
            break;
        }
    }

    String message = Messages.get(Messages.DEFAULT_LOCALE,
            "error_invalid_firewallconfig", new Object[] {
                    e.getOffendingToken().getText(), policy });
    throw new RuntimeException(message);
}
ProtoParserDefinition.java 文件源码 项目:protobuf-jetbrains-plugin 阅读 23 收藏 0 点赞 0 评论 0
@Override
public String formatMessage(SyntaxError error) {
    RecognitionException exception = error.getException();
    if (exception instanceof InputMismatchException) {
        InputMismatchException mismatchException = (InputMismatchException) exception;
        RuleContext ctx = mismatchException.getCtx();
        int ruleIndex = ctx.getRuleIndex();
        switch (ruleIndex) {
            case ProtoParser.RULE_ident:
                return ProtostuffBundle.message("error.expected.identifier");
            default:
                break;
        }
    }
    return super.formatMessage(error);
}
KsqlParserErrorStrategy.java 文件源码 项目:ksql 阅读 24 收藏 0 点赞 0 评论 0
public void reportError(Parser recognizer, RecognitionException e) {
  if (!this.inErrorRecoveryMode(recognizer)) {
    this.beginErrorCondition(recognizer);
    if (e instanceof NoViableAltException) {
      this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
    } else if (e instanceof InputMismatchException) {
      this.reportInputMismatch(recognizer, (InputMismatchException) e);
    } else if (e instanceof FailedPredicateException) {
      this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
    } else {
      System.err.println("unknown recognition error type: " + e.getClass().getName());
      recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
    }

  }
}
FWPolicyErrorStrategy.java 文件源码 项目:development 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Make sure we don't attempt to recover inline; if the parser successfully
 * recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String policies = recognizer.getInputStream().getText();
    StringTokenizer tk = new StringTokenizer(policies, ";");
    String policy = "";
    int idx = 0;
    while (tk.hasMoreElements()) {
        policy = (String) tk.nextElement();
        idx += policy.length();
        if (idx >= e.getOffendingToken().getStartIndex()) {
            break;
        }
    }

    String message = Messages.get(Messages.DEFAULT_LOCALE,
            "error_invalid_firewallconfig", new Object[] {
                    e.getOffendingToken().getText(), policy });
    throw new RuntimeException(message);
}
DescriptiveErrorStrategy.java 文件源码 项目:groovy 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void recover(Parser recognizer, RecognitionException e) {
    for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
        context.exception = e;
    }

    if (PredictionMode.LL.equals(recognizer.getInterpreter().getPredictionMode())) {
        if (e instanceof NoViableAltException) {
            this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
        } else if (e instanceof InputMismatchException) {
            this.reportInputMismatch(recognizer, (InputMismatchException) e);
        } else if (e instanceof FailedPredicateException) {
            this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
        }
    }

    throw new ParseCancellationException(e);
}
QueryParserImpl.java 文件源码 项目:perspective-backend 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
    if (e instanceof InputMismatchException || e instanceof NoViableAltException) {
        String symbol = (offendingSymbol instanceof Token) ?
                ((Token) offendingSymbol).getText() : 
                String.valueOf(offendingSymbol);
        errors.add(String.format(
                "Unexpected input \'%s\' at %d:%d. Valid symbols are: %s",
                symbol,
                line,
                charPositionInLine,
                e.getExpectedTokens().toString(recognizer.getVocabulary())
        ));
    } else {
        errors.add(String.format("Parse error: \'%s\' near \'%s\' at %d:%d", msg, String.valueOf(offendingSymbol), line, charPositionInLine));
    }
}
ZomicASTCompiler.java 文件源码 项目:vzome-core 阅读 22 收藏 0 点赞 0 评论 0
public Walk compile( CharStream input, ErrorHandler errors ) {
     try  {
         return compile( input );
     } catch (ParseCancellationException ex) {
int line = ErrorHandler.UNKNOWN;
int column = ErrorHandler.UNKNOWN;
String msg = "Parser Cancelled.";
Throwable cause = ex.getCause();
if( cause instanceof InputMismatchException ) {
    InputMismatchException immEx = (InputMismatchException) cause;
    Token offender = immEx.getOffendingToken();
    if( offender != null ) {
        line = offender.getLine();
        column = offender.getCharPositionInLine();
        String txt = offender.getText();
        if(txt != null) {
            msg = " Unexpected Token '" + txt + "'.";
        }
    }
}
         errors.parseError( line, column, msg );
     }      
     return getProgram();
 }
ZomicASTCompiler.java 文件源码 项目:vzome-core 阅读 22 收藏 0 点赞 0 评论 0
Axis generate() {
            try {
                Axis axis = namingConvention.getAxis(axisColor, indexFullName() );
                // This check has been moved into a thorough unit test instead of a runtime check.
                // but I'll leave the code commented out here in case additional colors are eventually supported and need debugging
//              String check = namingConvention.getName( axis );
//              if ( axis != namingConvention.getAxis(axisColor, check ) ) {
//                  log( axisColor + " " + indexFullName() + " mapped to " + check );
//              }
                if(axis == null) {
                    InputMismatchException imex = new InputMismatchException(parser);
                    logger.log(Level.WARNING, imex.getMessage(), imex);
                    throw imex;
                }
                return axis;
            //} catch( ArrayIndexOutOfBoundsException ex ){
            //} catch( NullPointerException  ex ) {
            } catch( RuntimeException ex) {
                String msg = "bad axis specification: '" + axisColor + " " + indexFullName() + "'";
                logger.warning(msg);
                throw new RuntimeException( msg, ex);
            } 
        }
BeetlAntlrErrorStrategy.java 文件源码 项目:beetl2.0 阅读 22 收藏 0 点赞 0 评论 0
/** Make sure we don't attempt to recover inline; if the parser
    * successfully recovers, it won't throw an exception.
    */
    @Override
    public Token recoverInline(Parser recognizer) throws RecognitionException
    {
        // SINGLE TOKEN DELETION
        Token matchedSymbol = singleTokenDeletion(recognizer);
        if (matchedSymbol != null)
        {
            // we have deleted the extra token.
            // now, move past ttype token as if all were ok
            recognizer.consume();
            return matchedSymbol;
        }

        // SINGLE TOKEN INSERTION
        if (singleTokenInsertion(recognizer))
        {
            return getMissingSymbol(recognizer);
        }

//      BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR);
//      exception.pushToken(this.getGrammarToken(recognizer.getCurrentToken()));
//      throw exception;
        throw new InputMismatchException(recognizer);
    }
GraphParser.java 文件源码 项目:digraph-parser 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException {
    String msg = "mismatched input " + getTokenErrorDisplay(e.getOffendingToken());
    msg += " expecting one of " + e.getExpectedTokens().toString(recognizer.getTokenNames());
    RecognitionException ex = new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
    ex.initCause(e);
    throw ex;
}
AntlrErrorString.java 文件源码 项目:kalang 阅读 21 收藏 0 点赞 0 评论 0
public static String exceptionString(Parser parser, RecognitionException ex) {
    if (ex instanceof FailedPredicateException) {
        return failedPredicate((FailedPredicateException) ex);
    } else if (ex instanceof InputMismatchException) {
        return inputMismatch((InputMismatchException) ex);
    } else if (ex instanceof NoViableAltException) {
        return noViableAlt(parser, (NoViableAltException) ex);
    } else {
        System.err.println("unknown recognition exception:" + ex);
        return ex.toString();
    }
}
GrammarParserInterpreter.java 文件源码 项目:codebuff 阅读 24 收藏 0 点赞 0 评论 0
@Override
        public Token recoverInline(Parser recognizer) throws RecognitionException {
            int errIndex = recognizer.getInputStream().index();
            if ( firstErrorTokenIndex == -1 ) {
                firstErrorTokenIndex = errIndex; // latch
            }
//          System.err.println("recoverInline: error at " + errIndex);
            InputMismatchException e = new InputMismatchException(recognizer);
//          TokenStream input = recognizer.getInputStream(); // seek EOF
//          input.seek(input.size() - 1);
            throw e;
        }
DescriptiveErrorStrategy.java 文件源码 项目:groovy 阅读 22 收藏 0 点赞 0 评论 0
@Override
public Token recoverInline(Parser recognizer)
        throws RecognitionException {

    this.recover(recognizer, new InputMismatchException(recognizer)); // stop parsing
    return null;
}
OsiamAntlrErrorListener.java 文件源码 项目:resource-server 阅读 19 收藏 0 点赞 0 评论 0
/**
 * {@inheritDoc}
 * <p/>
 * The method is overridden to throw an exception if the parsed input has an invalid syntax.
 */
@Override
public void syntaxError(Recognizer<?, ?> recognizer, @Nullable Object offendingSymbol, int line,
        int charPositionInLine, String msg, @Nullable RecognitionException e) {

    String errorMessage = msg;
    if (e instanceof InputMismatchException && msg.endsWith(" expecting VALUE")) {
        errorMessage += ". Please make sure that all values are surrounded by double quotes.";
    }

    throw new IllegalArgumentException(errorMessage);
}
ParserExceptionErrorStrategyImpl.java 文件源码 项目:KIARA 阅读 19 收藏 0 点赞 0 评论 0
@Override
public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException {
    String msg = "";
    msg += "In file " + recognizer.getSourceName() + " at line " + recognizer.getContext().start.getLine() + ": ";
    msg += "Mismatched input " + getTokenErrorDisplay(e.getOffendingToken());
    msg += " expecting one of "+e.getExpectedTokens().toString(recognizer.getTokenNames()) + "\n";
    msg += "Line Number " + recognizer.getContext().start.getLine() + ", Column " + recognizer.getContext().start.getCharPositionInLine() + ";";
    RecognitionException ex = new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext());
    ex.initCause(e);
    throw ex;
}
ParsingUtils.java 文件源码 项目:intellij-plugin-v4 阅读 19 收藏 0 点赞 0 评论 0
@Override
        public Token recoverInline(Parser recognizer) throws RecognitionException {
            int errIndex = recognizer.getInputStream().index();
            if ( firstErrorTokenIndex == -1 ) {
                firstErrorTokenIndex = errIndex; // latch
            }
//          System.err.println("recoverInline: error at " + errIndex);
            InputMismatchException e = new InputMismatchException(recognizer);
            TokenStream input = recognizer.getInputStream(); // seek EOF
            input.seek(input.size() - 1);
            throw e; // throw after seek so exception has bad token
        }
BeetlAntlrErrorStrategy.java 文件源码 项目:beetl2.0 阅读 22 收藏 0 点赞 0 评论 0
@Override
public void reportError(Parser recognizer, RecognitionException e)
{
    // if we've already reported an error and have not matched a token
    // yet successfully, don't report any errors.
    if (inErrorRecoveryMode(recognizer))
    {
        //          System.err.print("[SPURIOUS] ");
        return; // don't report spurious errors
    }
    beginErrorCondition(recognizer);
    if (e instanceof NoViableAltException)
    {
        reportNoViableAlternative(recognizer, (NoViableAltException) e);
    }
    else if (e instanceof InputMismatchException)
    {
        reportInputMismatch(recognizer, (InputMismatchException) e);
    }
    else if (e instanceof FailedPredicateException)
    {
        reportFailedPredicate(recognizer, (FailedPredicateException) e);
    }
    else
    {
        //          System.err.println("unknown recognition error type: " + e.getClass().getName());
        BeetlException exception = new BeetlException(BeetlException.PARSER_UNKNOW_ERROR, e.getClass().getName(), e);
        //          exception.token = this.getGrammarToken(e.getOffendingToken());
        exception.pushToken(this.getGrammarToken(e.getOffendingToken()));

        throw exception;
    }
}
BeetlAntlrErrorStrategy.java 文件源码 项目:beetl2.0 阅读 22 收藏 0 点赞 0 评论 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;

}
CompileErrorStrategy.java 文件源码 项目:BigDataScript 阅读 18 收藏 0 点赞 0 评论 0
/** Make sure we don't attempt to recover inline; if the parser
 *  successfully recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String message = "Cannot parse input, near '" + e.getOffendingToken().getText() + "'";
    CompilerMessage cm = new CompilerMessage(e.getOffendingToken().getInputStream().getSourceName(), e.getOffendingToken().getLine(), -1, message, MessageType.ERROR);
    CompilerMessages.get().add(cm);

    // Add exception to all contexts
    for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent())
        context.exception = e;

    throw new ParseCancellationException(e);
}
CapitulatingErrorStrategy.java 文件源码 项目:rapidminer 阅读 21 收藏 0 点赞 0 评论 0
@Override
protected void reportInputMismatch(Parser recognizer, InputMismatchException e) {
    // change error message from default implementation
    String msg = "mismatched input " + getTokenErrorDisplay(e.getOffendingToken()) + " expecting operator";
    recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
PopModelParserErrorStrategy.java 文件源码 项目:PhyDyn 阅读 21 收藏 0 点赞 0 评论 0
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    throw new RuntimeException(new InputMismatchException(recognizer));
}
JavadocDetailNodeParser.java 文件源码 项目:checkstyle-backport-jre6 阅读 20 收藏 0 点赞 0 评论 0
@Override
public Token recoverInline(Parser recognizer) {
    reportError(recognizer, new InputMismatchException(recognizer));
    return super.recoverInline(recognizer);
}
AntlrErrorString.java 文件源码 项目:kalang 阅读 22 收藏 0 点赞 0 评论 0
public static String inputMismatch(InputMismatchException e) {
    return "mismatched input:" + e.getOffendingToken().getText();
}
RecognitionErrorStrategy.java 文件源码 项目:ftc 阅读 16 收藏 0 点赞 0 评论 0
@Override
public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException {
    onErrorCallback.notifyOnError(e.getOffendingToken(), null, e.getExpectedTokens());
}
OperandExtractorTests.java 文件源码 项目:Simulizer 阅读 19 收藏 0 点赞 0 评论 0
private ParserRuleContext giveParseException(ParserRuleContext ctx) {
    ctx.exception = new InputMismatchException(parserDoNotUseDirectly.p);
    return ctx;
}
ProgramExtractorTests.java 文件源码 项目:Simulizer 阅读 19 收藏 0 点赞 0 评论 0
@SuppressWarnings("unused")
private ParserRuleContext giveParseException(ParserRuleContext ctx) {
    ctx.exception = new InputMismatchException(parserDoNotUseDirectly.p);
    return ctx;
}
KsqlParserErrorStrategy.java 文件源码 项目:ksql 阅读 20 收藏 0 点赞 0 评论 0
protected void reportInputMismatch(Parser recognizer, InputMismatchException e) {
  String msg =
      "Syntax error. There is a mismatch between the expected term and te term in the query. "
      + "Please check the line and column in the query.";
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
CapitulatingErrorStrategy.java 文件源码 项目:rapidminer-studio 阅读 19 收藏 0 点赞 0 评论 0
@Override
protected void reportInputMismatch(Parser recognizer, InputMismatchException e) {
    // change error message from default implementation
    String msg = "mismatched input " + getTokenErrorDisplay(e.getOffendingToken()) + " expecting operator";
    recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}


问题


面经


文章

微信
公众号

扫码关注公众号