List of usage examples for org.antlr.v4.runtime.misc IntervalSet toString
public String toString(Vocabulary vocabulary)
From source file:com.github.jknack.handlebars.internal.HbsErrorStrategy.java
License:Apache License
@Override public void reportMissingToken(final Parser recognizer) { if (errorRecoveryMode) { return;/*from w w w . j av a 2 s .c o m*/ } Token offendingToken = recognizer.getCurrentToken(); IntervalSet expecting = getExpectedTokens(recognizer); String msg = expecting.toString(recognizer.getTokenNames()); recognizer.notifyErrorListeners(offendingToken, msg, null); }
From source file:com.sample.JavaErrorStrategy.java
License:BSD License
/** * 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>//from w w w . ja v a 2 s . c o m * 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(@NotNull 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.getTokenNames()); recognizer.notifyErrorListeners(t, msg, null); }
From source file:com.sample.JavaErrorStrategy.java
License:BSD License
/** * 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>// w w w .j av a2 s. c om * 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(@NotNull Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); Token t = recognizer.getCurrentToken(); IntervalSet expecting = getExpectedTokens(recognizer); String msg = "missing " + expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t); recognizer.notifyErrorListeners(t, msg, null); }
From source file:de.up.ling.irtg.codec.ExceptionErrorStrategy.java
@Override public void reportMissingToken(Parser recognizer) { beginErrorCondition(recognizer);//ww w . j ava 2 s .c om Token t = recognizer.getCurrentToken(); IntervalSet expecting = getExpectedTokens(recognizer); String msg = getTokenPosition(t) + ": missing " + expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t); throw new RecognitionException(msg, recognizer, recognizer.getInputStream(), recognizer.getContext()); }
From source file:de.up.ling.irtg.codec.ExceptionErrorStrategy.java
@Override protected void reportNoViableAlternative(Parser parser, NoViableAltException nvae) { Token t = parser.getCurrentToken();/*ww w. ja v a2s. c o m*/ IntervalSet expecting = getExpectedTokens(parser); String msg = getTokenPosition(t) + ": no viable alternative: " + expecting.toString(parser.getTokenNames()) + " at " + getTokenErrorDisplay(t); throw new RecognitionException(msg, parser, parser.getInputStream(), parser.getContext()); }
From source file:de.up.ling.irtg.codec.ExceptionErrorStrategy.java
@Override protected void reportFailedPredicate(Parser parser, FailedPredicateException fpe) { Token t = parser.getCurrentToken();/*from ww w.j a va 2 s .c o m*/ IntervalSet expecting = getExpectedTokens(parser); String msg = getTokenPosition(t) + ": failed predicate '" + fpe.getMessage() + "': " + expecting.toString(parser.getTokenNames()) + " at " + getTokenErrorDisplay(t); throw new RecognitionException(msg, parser, parser.getInputStream(), parser.getContext()); }
From source file:de.up.ling.irtg.codec.ExceptionErrorStrategy.java
@Override protected void reportUnwantedToken(Parser parser) { Token t = parser.getCurrentToken();/* w w w . j av a 2s .co m*/ IntervalSet expecting = getExpectedTokens(parser); String msg = getTokenPosition(t) + ": expected token " + expecting.toString(parser.getTokenNames()) + ", but got " + getTokenErrorDisplay(t) + "."; throw new RecognitionException(msg, parser, parser.getInputStream(), parser.getContext()); }
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 FailedPredicateException}./*from www . jav a 2s .c o m*/ * * @see #reportError * * @param recognizer * the parser instance * @param e * the recognition exception */ protected void reportUnwantedToken(@NotNull 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 the following symbols: " + "\n" + expecting.toString(recognizer.getTokenNames()); recognizer.notifyErrorListeners(t, msg, null); }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.editor.RErrorStrategy.java
License:Open Source License
/** * 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>/*from w ww .jav a2s.com*/ * 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(@NotNull Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); Token t = recognizer.getCurrentToken(); IntervalSet expecting = getExpectedTokens(recognizer); String msg = "missing " + expecting.toString(recognizer.getTokenNames()) + " at " + getTokenErrorDisplay(t); recognizer.notifyErrorListeners(t, msg, null); }
From source file:org.ballerinalang.composer.service.workspace.rest.datamodel.BallerinaComposerErrorStrategy.java
License:Open Source License
@Override public void reportMissingToken(Parser parser) { Token token = parser.getCurrentToken(); IntervalSet expecting = getExpectedTokens(parser); Token missingSymbol = getMissingSymbol(parser); int line = missingSymbol.getLine(); int position = getMissingSymbol(parser).getCharPositionInLine(); String missingToken = expecting.toString(parser.getVocabulary()); String msg = getSourceLocation(parser, line, position) + "missing " + missingToken + " before " + getTokenErrorDisplay(token); errorTokens.add(createError(line, position, msg)); }