org.antlr.v4.runtime.Parser.notifyErrorListeners()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中org.antlr.v4.runtime.Parser.notifyErrorListeners()方法的一些代码示例,展示了Parser.notifyErrorListeners()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.notifyErrorListeners()方法的具体详情如下:
包路径:org.antlr.v4.runtime.Parser
类名称:Parser
方法名:notifyErrorListeners

Parser.notifyErrorListeners介绍

暂无

代码示例

代码示例来源: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: confluentinc/ksql

public void reportError(final Parser recognizer, final RecognitionException e) {
 if (!this.inErrorRecoveryMode(recognizer)) {
  this.beginErrorCondition(recognizer);
  if (e instanceof NoViableAltException) {
   this.reportNoViableAlternative(recognizer, (NoViableAltException) e);
  } else if (e instanceof InputMismatchException) {
   this.reportInputMismatch(recognizer, (InputMismatchException) e);
  } else if (e instanceof FailedPredicateException) {
   this.reportFailedPredicate(recognizer, (FailedPredicateException) e);
  } else {
   System.err.println("unknown recognition error type: " + e.getClass().getName());
   recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
  }
 }
}

代码示例来源:origin: confluentinc/ksql

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);
  }
 }
}

代码示例来源:origin: confluentinc/ksql

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);
 }
}

代码示例来源:origin: confluentinc/ksql

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);
}

代码示例来源:origin: org.antlr/antlr4-runtime

public final void notifyErrorListeners(String msg)	{
  notifyErrorListeners(getCurrentToken(), msg, null);
}

代码示例来源:origin: org.antlr/antlr4-runtime

@Override
public void reportAttemptingFullContext(Parser recognizer,
                    DFA dfa,
                    int startIndex,
                    int stopIndex,
                    BitSet conflictingAlts,
                    ATNConfigSet configs)
{
  String format = "reportAttemptingFullContext d=%s, input='%s'";
  String decision = getDecisionDescription(recognizer, dfa);
  String text = recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex));
  String message = String.format(format, decision, text);
  recognizer.notifyErrorListeners(message);
}

代码示例来源:origin: org.antlr/antlr4-runtime

@Override
public void reportContextSensitivity(Parser recognizer,
                   DFA dfa,
                   int startIndex,
                   int stopIndex,
                   int prediction,
                   ATNConfigSet configs)
{
  String format = "reportContextSensitivity d=%s, input='%s'";
  String decision = getDecisionDescription(recognizer, dfa);
  String text = recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex));
  String message = String.format(format, decision, text);
  recognizer.notifyErrorListeners(message);
}

代码示例来源:origin: org.antlr/antlr4-runtime

@Override
public void reportAmbiguity(Parser recognizer,
              DFA dfa,
              int startIndex,
              int stopIndex,
              boolean exact,
              BitSet ambigAlts,
              ATNConfigSet configs)
{
  if (exactOnly && !exact) {
    return;
  }
  String format = "reportAmbiguity d=%s: ambigAlts=%s, input='%s'";
  String decision = getDecisionDescription(recognizer, dfa);
  BitSet conflictingAlts = getConflictingAlts(ambigAlts, configs);
  String text = recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex));
  String message = String.format(format, decision, conflictingAlts, text);
  recognizer.notifyErrorListeners(message);
}

代码示例来源:origin: org.antlr/antlr4-runtime

/**
 * This is called by {@link #reportError} when the exception is a
 * {@link FailedPredicateException}.
 *
 * @see #reportError
 *
 * @param recognizer the parser instance
 * @param e the recognition exception
 */
protected void reportFailedPredicate(Parser recognizer,
                   FailedPredicateException e)
{
  String ruleName = recognizer.getRuleNames()[recognizer._ctx.getRuleIndex()];
  String msg = "rule "+ruleName+" "+e.getMessage();
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}

代码示例来源:origin: org.antlr/antlr4-runtime

recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), 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: org.antlr/antlr4-runtime

/**
 * 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);
}

代码示例来源:origin: org.antlr/antlr4-runtime

/**
 * 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);
}

代码示例来源:origin: org.antlr/antlr4-runtime

/**
 * 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);
}

代码示例来源:origin: batfish/batfish

@Override
public void reportError(Parser recognizer, RecognitionException e) {
 if (!(e instanceof BatfishRecognitionException)) {
  recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
 }
}

代码示例来源:origin: org.bitbucket.goalhub.krTools.krLanguages/swiprolog

@Override
public void reportFailedPredicate(Parser parser, FailedPredicateException e) {
  parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()),
      getException("FailedPredicate", parser));
}

代码示例来源:origin: org.bitbucket.goalhub.krTools.krLanguages/swiprolog

@Override
public void reportNoViableAlternative(Parser parser, NoViableAltException e) throws RecognitionException {
  parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()),
      getException("NoViableAlternative", parser));
}

代码示例来源:origin: org.bitbucket.goalhub.grammar/languageTools

@Override
public void reportNoViableAlternative(Parser parser, NoViableAltException e) throws RecognitionException {
  parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()),
      getException("NoViableAlternative", parser));
}

代码示例来源: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));
}

相关文章