Analyzer analyzer = new Analyzer(atn, parser.getVocabulary(), specialRules, specialTokens, ignoredRules, parser.getTokenStream()); Multimap<Integer, String> candidates = analyzer.process(currentState, currentToken.getTokenIndex(), context);
protected void reportMissingToken(final Parser recognizer) { if (!this.inErrorRecoveryMode(recognizer)) { this.beginErrorCondition(recognizer); final Token t = recognizer.getCurrentToken(); final IntervalSet expecting = this.getExpectedTokens(recognizer); final String msg = "missing " + expecting.toString(recognizer.getVocabulary()) + " at " + this .getTokenErrorDisplay(t); recognizer.notifyErrorListeners(t, msg, (RecognitionException) null); } } }
protected void reportUnwantedToken(final Parser recognizer) { if (!this.inErrorRecoveryMode(recognizer)) { this.beginErrorCondition(recognizer); final Token t = recognizer.getCurrentToken(); final String tokenName = this.getTokenErrorDisplay(t); final IntervalSet expecting = this.getExpectedTokens(recognizer); final String msg = "extraneous input " + tokenName + " expecting " + expecting.toString(recognizer.getVocabulary()); recognizer.notifyErrorListeners(t, msg, (RecognitionException) null); } }
public String getTokenName(int t) { if (t == Token.EOF) { return "EOF"; } Vocabulary vocabulary = parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY; String displayName = vocabulary.getDisplayName(t); if (displayName.equals(Integer.toString(t))) { return displayName; } return displayName + "<" + t + ">"; }
/** For debugging and other purposes. */ public List<String> getDFAStrings() { synchronized (_interp.decisionToDFA) { List<String> s = new ArrayList<String>(); for (int d = 0; d < _interp.decisionToDFA.length; d++) { DFA dfa = _interp.decisionToDFA[d]; s.add( dfa.toString(getVocabulary()) ); } return s; } }
/** For debugging and other purposes. */ public void dumpDFA() { synchronized (_interp.decisionToDFA) { boolean seenOne = false; for (int d = 0; d < _interp.decisionToDFA.length; d++) { DFA dfa = _interp.decisionToDFA[d]; if ( !dfa.states.isEmpty() ) { if ( seenOne ) System.out.println(); System.out.println("Decision " + dfa.decision + ":"); System.out.print(dfa.toString(getVocabulary())); seenOne = true; } } } }
System.out.println("DFA=\n"+dfa.toString(parser!=null?parser.getVocabulary():VocabularyImpl.EMPTY_VOCABULARY));
/** * This is called by {@link #reportError} when the exception is an * {@link InputMismatchException}. * * @see #reportError * * @param recognizer the parser instance * @param e the recognition exception */ protected void reportInputMismatch(Parser recognizer, InputMismatchException e) { String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+ " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary()); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
/** * This method is called to report a syntax error which requires the * insertion of a missing token into the input stream. At the time this * method is called, the missing token has not yet been inserted. When this * method returns, {@code recognizer} is in error recovery mode. * * <p>This method is called when {@link #singleTokenInsertion} identifies * single-token insertion as a viable recovery strategy for a mismatched * input error.</p> * * <p>The default implementation simply returns if the handler is already in * error recovery mode. Otherwise, it calls {@link #beginErrorCondition} to * enter error recovery mode, followed by calling * {@link Parser#notifyErrorListeners}.</p> * * @param recognizer the parser instance */ protected void reportMissingToken(Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); Token t = recognizer.getCurrentToken(); IntervalSet expecting = getExpectedTokens(recognizer); String msg = "missing "+expecting.toString(recognizer.getVocabulary())+ " at "+getTokenErrorDisplay(t); recognizer.notifyErrorListeners(t, msg, null); }
/** * This method is called to report a syntax error which requires the removal * of a token from the input stream. At the time this method is called, the * erroneous symbol is current {@code LT(1)} symbol and has not yet been * removed from the input stream. When this method returns, * {@code recognizer} is in error recovery mode. * * <p>This method is called when {@link #singleTokenDeletion} identifies * single-token deletion as a viable recovery strategy for a mismatched * input error.</p> * * <p>The default implementation simply returns if the handler is already in * error recovery mode. Otherwise, it calls {@link #beginErrorCondition} to * enter error recovery mode, followed by calling * {@link Parser#notifyErrorListeners}.</p> * * @param recognizer the parser instance */ protected void reportUnwantedToken(Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); Token t = recognizer.getCurrentToken(); String tokenName = getTokenErrorDisplay(t); IntervalSet expecting = getExpectedTokens(recognizer); String msg = "extraneous input "+tokenName+" expecting "+ expecting.toString(recognizer.getVocabulary()); recognizer.notifyErrorListeners(t, msg, null); }
parser.getVocabulary(), Arrays.asList(parser.getRuleNames()), parser.getATNWithBypassAlts(),
/** For debugging and other purposes. */ public List<String> getDFAStrings() { synchronized (_interp.decisionToDFA) { List<String> s = new ArrayList<String>(); for (int d = 0; d < _interp.decisionToDFA.length; d++) { DFA dfa = _interp.decisionToDFA[d]; s.add( dfa.toString(getVocabulary()) ); } return s; } }
public String getTokenName(int t) { if (t == Token.EOF) { return "EOF"; } Vocabulary vocabulary = parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY; String displayName = vocabulary.getDisplayName(t); if (displayName.equals(Integer.toString(t))) { return displayName; } return displayName + "<" + t + ">"; }
/** For debugging and other purposes. */ public List<String> getDFAStrings() { synchronized (_interp.decisionToDFA) { List<String> s = new ArrayList<String>(); for (int d = 0; d < _interp.decisionToDFA.length; d++) { DFA dfa = _interp.decisionToDFA[d]; s.add( dfa.toString(getVocabulary()) ); } return s; } }
@NotNull public String getTokenName(int t) { if (t == Token.EOF) { return "EOF"; } Vocabulary vocabulary = parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY; String displayName = vocabulary.getDisplayName(t); if (displayName.equals(Integer.toString(t))) { return displayName; } return displayName + "<" + t + ">"; }
/** For debugging and other purposes. */ public List<String> getDFAStrings() { List<String> s = new ArrayList<String>(); for (int d = 0; d < _interp.atn.decisionToDFA.length; d++) { DFA dfa = _interp.atn.decisionToDFA[d]; s.add( dfa.toString(getVocabulary(), getRuleNames()) ); } return s; }
else tokenText = "<missing "+recognizer.getVocabulary().getDisplayName(expectedTokenType)+">"; Token current = currentSymbol; Token lookback = recognizer.getInputStream().LT(-1);
if ( debug ) System.out.println("DFA after predictATN: "+ dfa.toString(parser.getVocabulary())); return alt;
@Override public Token recoverInline(final Parser recognizer) throws RecognitionException { final Token token = recognizer.getCurrentToken(); final String message = "unexpected token [" + getTokenErrorDisplay(token) + "]" + " was expecting one of [" + recognizer.getExpectedTokens().toString(recognizer.getVocabulary()) + "]."; Location location = new Location(sourceName, token.getStartIndex()); throw location.createError(new IllegalArgumentException(message)); }
@Override public void reportInputMismatch(Parser parser, InputMismatchException e) { setErrorState(parser); Token offendingToken = e.getOffendingToken(); String mismatchedToken = getTokenErrorDisplay(offendingToken); String expectedToken = e.getExpectedTokens().toString(parser.getVocabulary()); DiagnosticPos pos = getPosition(offendingToken); dlog.error(pos, DiagnosticCode.MISMATCHED_INPUT, mismatchedToken, expectedToken); }