protected void reportNoViableAlternative(final Parser recognizer, final NoViableAltException e) { final TokenStream tokens = recognizer.getInputStream(); final String input; if (tokens != null) { if (e.getStartToken().getType() == -1) { input = "<EOF>"; } else { input = tokens.getText(e.getStartToken(), e.getOffendingToken()); } } else { input = "<unknown input>"; } final String msg = "no viable alternative at input " + this.escapeWSAndQuote(input); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
TokenStream tokens = recognizer.getInputStream(); Token token = tokens.LT(1); ATNState state = recognizer.getInterpreter().atn.states.get(recognizer.getState());
/** Consume tokens until one matches the given token set. */ protected void consumeUntil(Parser recognizer, IntervalSet set) { // System.err.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")"); int ttype = recognizer.getInputStream().LA(1); while (ttype != Token.EOF && !set.contains(ttype) ) { //System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]); // recognizer.getInputStream().consume(); recognizer.consume(); ttype = recognizer.getInputStream().LA(1); } } }
public NoViableAltException(Parser recognizer) { // LL(1) error this(recognizer, recognizer.getInputStream(), recognizer.getCurrentToken(), recognizer.getCurrentToken(), null, recognizer._ctx); }
public InputMismatchException(Parser recognizer) { super(recognizer, recognizer.getInputStream(), recognizer._ctx); this.setOffendingToken(recognizer.getCurrentToken()); }
public InputMismatchException(Parser recognizer, int state, ParserRuleContext ctx) { super(recognizer, recognizer.getInputStream(), ctx); this.setOffendingState(state); this.setOffendingToken(recognizer.getCurrentToken()); } }
/** reset the parser's state */ public void reset() { if ( getInputStream()!=null ) getInputStream().seek(0); _errHandler.reset(this); _ctx = null; _syntaxErrors = 0; matchedEOF = false; setTrace(false); _precedenceStack.clear(); _precedenceStack.push(0); ATNSimulator interpreter = getInterpreter(); if (interpreter != null) { interpreter.reset(); } }
public FailedPredicateException(Parser recognizer, String predicate, String message) { super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx); ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState()); AbstractPredicateTransition trans = (AbstractPredicateTransition)s.transition(0); if (trans instanceof PredicateTransition) { this.ruleIndex = ((PredicateTransition)trans).ruleIndex; this.predicateIndex = ((PredicateTransition)trans).predIndex; } else { this.ruleIndex = 0; this.predicateIndex = 0; } this.predicate = predicate; this.setOffendingToken(recognizer.getCurrentToken()); }
int currentSymbolType = recognizer.getInputStream().LA(1);
int nextTokenType = recognizer.getInputStream().LA(2); IntervalSet expecting = getExpectedTokens(recognizer); if ( expecting.contains(nextTokenType) ) {
if ( lastErrorIndex==recognizer.getInputStream().index() && lastErrorStates != null && lastErrorStates.contains(recognizer.getState()) ) { lastErrorIndex = recognizer.getInputStream().index(); if ( lastErrorStates==null ) lastErrorStates = new IntervalSet(); lastErrorStates.add(recognizer.getState());
/** * This is called by {@link #reportError} when the exception is a * {@link NoViableAltException}. * * @see #reportError * * @param recognizer the parser instance * @param e the recognition exception */ protected void reportNoViableAlternative(Parser recognizer, 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); }
Token o = getCurrentToken(); if (o.getType() != EOF) { getInputStream().consume();
TokenStream tokens = recognizer.getInputStream(); int la = tokens.LA(1);
else tokenText = "<missing "+recognizer.getVocabulary().getDisplayName(expectedTokenType)+">"; Token current = currentSymbol; Token lookback = recognizer.getInputStream().LT(-1); if ( current.getType() == Token.EOF && lookback!=null ) { current = lookback;
@Override public void recover(Parser recognizer, RecognitionException e) { int errIndex = recognizer.getInputStream().index(); if ( firstErrorTokenIndex == -1 ) { firstErrorTokenIndex = errIndex; // latch } // System.err.println("recover: error at " + errIndex); TokenStream input = recognizer.getInputStream(); if ( input.index()<input.size()-1 ) { // don't consume() eof recognizer.consume(); // just kill this bad token and let it continue. } }
@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 void recover(Parser recognizer, RecognitionException e) { int errIndex = recognizer.getInputStream().index(); if ( firstErrorTokenIndex == -1 ) { firstErrorTokenIndex = errIndex; // latch } // System.err.println("recover: error at " + errIndex); TokenStream input = recognizer.getInputStream(); if ( input.index()<input.size()-1 ) { // don't consume() eof recognizer.consume(); // just kill this bad token and let it continue. } }
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; }
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; }