List of usage examples for org.antlr.v4.runtime NoViableAltException getStartToken
public Token getStartToken()
From source file:com.huawei.streaming.cql.semanticanalyzer.parser.CQLErrorStrategy.java
License:Apache License
/** * {@inheritDoc}/* w w w.j av a 2 s. com*/ */ @Override public void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input; if (tokens instanceof TokenStream) { if (e.getStartToken().getType() == Token.EOF) input = "<EOF>"; else input = getText(tokens, e.getStartToken(), e.getOffendingToken()); } else { input = "<unknown input>"; } String msg = "no viable alternative at input " + escapeWSAndQuote(input); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
From source file:com.sample.JavaErrorStrategy.java
License:BSD License
/** * This is called by {@link #reportError} when the exception is a * {@link NoViableAltException}./*from w w w.j a va 2s.c o m*/ * * @see #reportError * * @param recognizer * the parser instance * @param e * the recognition exception */ protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input; if (tokens != null) { if (e.getStartToken().getType() == Token.EOF) input = "<EOF>"; else input = tokens.getText(e.getStartToken(), e.getOffendingToken()); } else { input = "<unknown input>"; } String msg = "no viable alternative at input " + escapeWSAndQuote(input); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
From source file:kr.ac.korea.dbserver.parser.SQLErrorStrategy.java
License:Apache License
protected void reportNoViableAltException(@NotNull Parser recognizer, @NotNull NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String msg;//w w w.j a va 2 s .c o m Token token = e.getStartToken(); if (tokens != null) { if (tokens.LT(-1) != null && token.getType() == Token.EOF) { token = tokens.LT(-1); } msg = "syntax error at or near " + getTokenErrorDisplay(token); } else { msg = "no viable alternative at input " + escapeWSAndQuote("<unknown input>"); } recognizer.notifyErrorListeners(token, msg, e); }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.editor.RErrorStrategy.java
License:Open Source License
/** * This is called by {@link #reportError} when the exception is a * {@link NoViableAltException}./*from ww w . j av a 2 s . c o m*/ * * @see #reportError * * @param recognizer * the parser instance * @param e * the recognition exception */ protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input; if (tokens != null) { if (e.getStartToken().getType() == Token.EOF) input = "<EOF>"; else input = tokens.getText(e.getStartToken(), e.getOffendingToken()); } else { input = "<unknown input>"; } String msg = " no alternative available at input " + escapeWSAndQuote(input); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
From source file:org.beetl.core.parser.BeetlAntlrErrorStrategy.java
License:BSD License
protected void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input;// ww w .jav a2s . co m if (tokens instanceof TokenStream) { if (e.getStartToken().getType() == Token.EOF) input = "<>"; else input = tokens.getText(e.getStartToken(), e.getOffendingToken()); } else { input = "<>"; } // String msg = "no viable alternative at input " + escapeWSAndQuote(input); BeetlException exception = new BeetlParserException(BeetlException.PARSER_VIABLE_ERROR, escapeWSAndQuote(input), e); exception.token = this.getGrammarToken(e.getOffendingToken()); throw exception; }
From source file:org.eclipse.titan.common.parsers.ParserLogger.java
License:Open Source License
/** * Rule exception info in string format for logging purpose * @param aRule rule// w ww .ja va2 s .co m * @param aTokenNameResolver resolver to get token name * @return exception stack trace + some other info from the exception object */ private static String getExceptionInfo(final ParserRuleContext aRule, final TokenNameResolver aTokenNameResolver) { final RecognitionException e = aRule.exception; if (e == null) { return ""; } final StringBuilder sb = new StringBuilder(); sb.append("\naRule.getText() == " + aRule.getText()); sb.append("\ngetOffendingState() == " + e.getOffendingState()); sb.append("\ngetExpectedTokens() == ["); final List<Integer> expectedTokens = e.getExpectedTokens().toList(); for (int i = 0; i < expectedTokens.size(); i++) { if (i > 0) { sb.append(", "); } final int tokenType = expectedTokens.get(i); sb.append(getTokenName(tokenType, aTokenNameResolver)); } sb.append("]"); if (e instanceof NoViableAltException) { NoViableAltException nvae = (NoViableAltException) e; sb.append("\ngetStartToken() == " + getTokenInfo(nvae.getStartToken(), aTokenNameResolver)); sb.append("\ngetDeadEndConfigs() == " + nvae.getDeadEndConfigs()); } final StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); sb.append("\n" + errors.toString()); return sb.toString(); }
From source file:org.kaazing.k3po.lang.internal.parser.ScriptParserImpl.java
License:Open Source License
private ScriptParseException createScriptParseException(RobotParser parser, NoViableAltException nvae) { String desc = String.format("line %d:%d: ", nvae.getStartToken().getLine(), nvae.getOffendingToken().getCharPositionInLine()); String msg = String.format("%sunexpected character: '%s'", desc, escapeChar(nvae.getOffendingToken().getText().charAt(0))); return new ScriptParseException(msg); }