本文整理了Java中org.antlr.v4.runtime.InputMismatchException
类的一些代码示例,展示了InputMismatchException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InputMismatchException
类的具体详情如下:
包路径:org.antlr.v4.runtime.InputMismatchException
类名称:InputMismatchException
[英]This signifies any kind of mismatched input exceptions such as when the current input does not match the expected token.
[中]这表示任何类型的不匹配输入异常,例如当前输入与预期令牌不匹配时。
代码示例来源:origin: prestodb/presto
@Override
public Token recoverInline(Parser recognizer)
throws RecognitionException
{
if (nextTokensContext == null) {
throw new InputMismatchException(recognizer);
}
else {
throw new InputMismatchException(recognizer, nextTokensState, nextTokensContext);
}
}
});
代码示例来源:origin: confluentinc/ksql
protected void reportInputMismatch(final Parser recognizer, final InputMismatchException e) {
final String msg =
"Syntax error. There is a mismatch between the expected term and te term in the query. "
+ "Please check the line and column in the query.";
recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
代码示例来源:origin: org.antlr/antlr4-runtime
public InputMismatchException(Parser recognizer) {
super(recognizer, recognizer.getInputStream(), recognizer._ctx);
this.setOffendingToken(recognizer.getCurrentToken());
}
代码示例来源:origin: org.antlr/antlr4-runtime
public InputMismatchException(Parser recognizer, int state, ParserRuleContext ctx) {
super(recognizer, recognizer.getInputStream(), ctx);
this.setOffendingState(state);
this.setOffendingToken(recognizer.getCurrentToken());
}
}
代码示例来源:origin: org.antlr/antlr4-runtime
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
TokenStream tokens = recognizer.getInputStream();
int la = tokens.LA(1);
throw new InputMismatchException(recognizer);
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
TokenStream tokens = recognizer.getInputStream();
int la = tokens.LA(1);
throw new InputMismatchException(recognizer);
代码示例来源:origin: org.antlr/antlr4-runtime
/** Make sure we don't attempt to recover inline; if the parser
* successfully recovers, it won't throw an exception.
*/
@Override
public Token recoverInline(Parser recognizer)
throws RecognitionException
{
InputMismatchException e = new InputMismatchException(recognizer);
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new ParseCancellationException(e);
}
代码示例来源:origin: org.antlr/antlr4-runtime
/**
* 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);
}
代码示例来源:origin: com.tunnelvisionlabs/antlr4
@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;
}
代码示例来源:origin: org.antlr/antlr4-runtime
recognizer.consume();
return matchedSymbol;
e = new InputMismatchException(recognizer);
} else {
e = new InputMismatchException(recognizer, nextTokensState, nextTokensContext);
代码示例来源:origin: org.ballerinalang/ballerina-lang
@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);
}
代码示例来源:origin: javamonkey/beetl2.0
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;
}
代码示例来源:origin: org.bitbucket.goalhub.krTools.krLanguages/swiprolog
@Override
public void reportInputMismatch(Parser parser, InputMismatchException e) {
parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()),
getException("InputMismatch", parser));
}
代码示例来源:origin: espertechinc/esper
if (mismatched.getExpectedTokens().size() > 1) {
StringWriter writer = new StringWriter();
writer.append("any of the following tokens {");
String delimiter = "";
for (int i = 0; i < mismatched.getExpectedTokens().size(); i++) {
writer.append(delimiter);
if (i > 5) {
writer.append("...");
writer.append(Integer.toString(mismatched.getExpectedTokens().size() - 5));
writer.append(" more");
break;
writer.append(getTokenText(parser, mismatched.getExpectedTokens().get(i)));
expected = getTokenText(parser, mismatched.getExpectedTokens().get(0));
int offendingTokenType = mismatched.getOffendingToken().getType();
String unexpected = getTokenText(parser, offendingTokenType);
代码示例来源:origin: apache/incubator-shardingsphere
private void tryToExecuteByID(final Parser recognizer, final InputMismatchException cause) {
Token token = cause.getOffendingToken();
CommonToken commonToken;
if (token instanceof CommonToken) {
commonToken = (CommonToken) token;
} else {
throw cause;
}
int previousType = commonToken.getType();
if (previousType > identifierTokenIndex) {
return;
}
commonToken.setType(identifierTokenIndex);
try {
super.sync(recognizer);
} catch (InputMismatchException ex) {
if (cause.getOffendingToken() == ex.getOffendingToken()) {
commonToken.setType(previousType);
throw cause;
}
tryToExecuteByID(recognizer, ex);
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
commonToken.setType(previousType);
throw cause;
}
}
}
代码示例来源:origin: org.antlr/antlr4-runtime
Token tok = e.getOffendingToken();
int expectedTokenType = Token.INVALID_TYPE;
if ( !ime.getExpectedTokens().isNil() ) {
expectedTokenType = ime.getExpectedTokens().getMinElement(); // get any element
代码示例来源:origin: batfish/batfish
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
if (inErrorRecoveryMode(recognizer)) {
return;
TokenStream tokens = recognizer.getInputStream();
int la = tokens.LA(1);
IntervalSet nextTokens = recognizer.getATN().nextTokens(s);
throw new InputMismatchException(recognizer);
代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime
ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
TokenStream tokens = recognizer.getInputStream();
int la = tokens.LA(1);
throw new InputMismatchException(recognizer);
代码示例来源:origin: cn.wanghaomiao/JsoupXpath
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
InputMismatchException e = new InputMismatchException(recognizer);
for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new ParseCancellationException(e);
}
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* 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);
}
内容来源于网络,如有侵权,请联系作者删除!