@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)); }
/** * 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); }
@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); }
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); } } }
@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); }
@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)); } }
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(); }
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); } }
/** 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); }
@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; }
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(); } }
@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; }
@Override public Token recoverInline(Parser recognizer) throws RecognitionException { this.recover(recognizer, new InputMismatchException(recognizer)); // stop parsing return null; }
/** * {@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); }
@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; }
@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 }
@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; } }
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; }
/** 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); }
@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); }
@Override public Token recoverInline(Parser recognizer) throws RecognitionException { throw new RuntimeException(new InputMismatchException(recognizer)); }
@Override public Token recoverInline(Parser recognizer) { reportError(recognizer, new InputMismatchException(recognizer)); return super.recoverInline(recognizer); }
public static String inputMismatch(InputMismatchException e) { return "mismatched input:" + e.getOffendingToken().getText(); }
@Override public void reportInputMismatch(Parser recognizer, InputMismatchException e) throws RecognitionException { onErrorCallback.notifyOnError(e.getOffendingToken(), null, e.getExpectedTokens()); }
private ParserRuleContext giveParseException(ParserRuleContext ctx) { ctx.exception = new InputMismatchException(parserDoNotUseDirectly.p); return ctx; }
@SuppressWarnings("unused") private ParserRuleContext giveParseException(ParserRuleContext ctx) { ctx.exception = new InputMismatchException(parserDoNotUseDirectly.p); return ctx; }
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); }
protected String createInputMismatchErrorMessage(Parser recognizer, InputMismatchException e) { return "Unexpected input: " + getTokenErrorDisplay(e.getOffendingToken(recognizer)) + "; Expecting " + e.getExpectedTokens().toString(recognizer.getVocabulary()); }
protected void reportInputMismatch(Parser recognizer, InputMismatchException e) { notifyErrorListeners(recognizer, this.createInputMismatchErrorMessage(recognizer, e), e); }
/** * @see DefaultErrorStrategy#reportInputMismatch */ @Override protected void reportInputMismatch(Parser recognizer, InputMismatchException e) { super.reportInputMismatch(recognizer, e); }
@Override public Token recoverInline(final Parser recognizer) throws RecognitionException { throw new InputMismatchException(recognizer); }