Java 类org.antlr.v4.runtime.InputMismatchException 实例源码

项目:elasticsearch_my    文件:ParserErrorStrategy.java   
@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));
}
项目:oscm-app    文件:FWPolicyErrorStrategy.java   
/**
 * 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);
}
项目:oscm    文件:FWPolicyErrorStrategy.java   
/**
 * 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);
}
项目:protobuf-jetbrains-plugin    文件:ProtoParserDefinition.java   
@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);
}
项目:ksql    文件:KsqlParserErrorStrategy.java   
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);
    }

  }
}
项目:development    文件:FWPolicyErrorStrategy.java   
/**
 * 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);
}
项目:groovy    文件:DescriptiveErrorStrategy.java   
@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);
}
项目:perspective-backend    文件:QueryParserImpl.java   
@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));
    }
}
项目:vzome-core    文件:ZomicASTCompiler.java   
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();
 }
项目:vzome-core    文件:ZomicASTCompiler.java   
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);
            } 
        }
项目:beetl2.0    文件:BeetlAntlrErrorStrategy.java   
/** 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);
    }
项目:digraph-parser    文件:GraphParser.java   
@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;
}
项目:kalang    文件:AntlrErrorString.java   
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();
    }
}
项目:codebuff    文件:GrammarParserInterpreter.java   
@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;
        }
项目:groovy    文件:DescriptiveErrorStrategy.java   
@Override
public Token recoverInline(Parser recognizer)
        throws RecognitionException {

    this.recover(recognizer, new InputMismatchException(recognizer)); // stop parsing
    return null;
}
项目:resource-server    文件:OsiamAntlrErrorListener.java   
/**
 * {@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);
}
项目:KIARA    文件:ParserExceptionErrorStrategyImpl.java   
@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;
}
项目:intellij-plugin-v4    文件:ParsingUtils.java   
@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
        }
项目:beetl2.0    文件:BeetlAntlrErrorStrategy.java   
@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;
    }
}
项目:beetl2.0    文件:BeetlAntlrErrorStrategy.java   
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;

}
项目:BigDataScript    文件:CompileErrorStrategy.java   
/** 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);
}
项目:rapidminer    文件:CapitulatingErrorStrategy.java   
@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);
}
项目:PhyDyn    文件:PopModelParserErrorStrategy.java   
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    throw new RuntimeException(new InputMismatchException(recognizer));
}
项目:checkstyle-backport-jre6    文件:JavadocDetailNodeParser.java   
@Override
public Token recoverInline(Parser recognizer) {
    reportError(recognizer, new InputMismatchException(recognizer));
    return super.recoverInline(recognizer);
}
项目:kalang    文件:AntlrErrorString.java   
public static String inputMismatch(InputMismatchException e) {
    return "mismatched input:" + e.getOffendingToken().getText();
}
项目:ftc    文件:RecognitionErrorStrategy.java   
@Override
public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException {
    onErrorCallback.notifyOnError(e.getOffendingToken(), null, e.getExpectedTokens());
}
项目:Simulizer    文件:OperandExtractorTests.java   
private ParserRuleContext giveParseException(ParserRuleContext ctx) {
    ctx.exception = new InputMismatchException(parserDoNotUseDirectly.p);
    return ctx;
}
项目:Simulizer    文件:ProgramExtractorTests.java   
@SuppressWarnings("unused")
private ParserRuleContext giveParseException(ParserRuleContext ctx) {
    ctx.exception = new InputMismatchException(parserDoNotUseDirectly.p);
    return ctx;
}
项目:ksql    文件:KsqlParserErrorStrategy.java   
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);
}
项目:rapidminer-studio    文件:CapitulatingErrorStrategy.java   
@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);
}
项目:groovy    文件:DescriptiveErrorStrategy.java   
protected String createInputMismatchErrorMessage(Parser recognizer,
                                                 InputMismatchException e) {
    return "Unexpected input: " + getTokenErrorDisplay(e.getOffendingToken(recognizer)) +
            "; Expecting " + e.getExpectedTokens().toString(recognizer.getVocabulary());
}
项目:groovy    文件:DescriptiveErrorStrategy.java   
protected void reportInputMismatch(Parser recognizer,
                                   InputMismatchException e) {

    notifyErrorListeners(recognizer, this.createInputMismatchErrorMessage(recognizer, e), e);
}
项目:infix    文件:FixRulesErrorStrategy.java   
/**
 * @see DefaultErrorStrategy#reportInputMismatch
 */
@Override
protected void reportInputMismatch(Parser recognizer, InputMismatchException e) {
    super.reportInputMismatch(recognizer, e);
}
项目:syncope    文件:SCIMFilterErrorHandler.java   
@Override
public Token recoverInline(final Parser recognizer) throws RecognitionException {
    throw new InputMismatchException(recognizer);
}
项目:checkstyle    文件:JavadocDetailNodeParser.java   
@Override
public Token recoverInline(Parser recognizer) {
    reportError(recognizer, new InputMismatchException(recognizer));
    return super.recoverInline(recognizer);
}