List of usage examples for org.antlr.v4.runtime NoViableAltException getDeadEndConfigs
public ATNConfigSet getDeadEndConfigs()
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 w w . ja va 2 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(); }