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

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

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

Parser.getCurrentToken介绍

[英]Match needs to return the current input symbol, which gets put into the label for the associated token ref; e.g., x=ID.
[中]Match需要返回当前输入符号,该符号被放入相关令牌ref的标签中;e、 g.,x=ID。

代码示例

代码示例来源:origin: prestodb/presto

currentToken = parser.getCurrentToken();
context = parser.getContext();

代码示例来源:origin: graphql-java/graphql-java

private InvalidSyntaxException mkException(Parser recognizer, RecognitionException cause) {
  String sourcePreview = null;
  String offendingToken = null;
  SourceLocation sourceLocation = null;
  Token currentToken = recognizer.getCurrentToken();
  if (currentToken != null) {
    int line = currentToken.getLine();
    int column = currentToken.getCharPositionInLine();
    offendingToken = currentToken.getText();
    sourcePreview = mkPreview(line);
    sourceLocation = new SourceLocation(line, column, sourceName);
  }
  return new InvalidSyntaxException(sourceLocation, null, sourcePreview, offendingToken, cause);
}

代码示例来源: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: apache/incubator-shardingsphere

/**
   * Get matched token by token type.
   *
   * @param tokenType token type
   * @return matched token
   * @throws RecognitionException mismatch throw exception
   */
  public Token getMatchedToken(final int tokenType) throws RecognitionException {
    Token result = parser.getCurrentToken();
    boolean isIdentifierCompatible = false;
    if (identifierTokenIndex == tokenType && identifierTokenIndex > result.getType()) {
      isIdentifierCompatible = true;
    }
    if (result.getType() == tokenType || isIdentifierCompatible) {
      if (Token.EOF != tokenType && isIdentifierCompatible && result instanceof CommonToken) {
        ((CommonToken) result).setType(identifierTokenIndex);
      }
      parser.getErrorHandler().reportMatch(parser);
      parser.consume();
    } else {
      result = parser.getErrorHandler().recoverInline(parser);
      if (parser.getBuildParseTree() && -1 == result.getTokenIndex()) {
        parser.getContext().addErrorNode(parser.createErrorNode(parser.getContext(), result));
      }
    }
    return result;
  }
}

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

public NoViableAltException(Parser recognizer) { // LL(1) error
  this(recognizer,
     recognizer.getInputStream(),
     recognizer.getCurrentToken(),
     recognizer.getCurrentToken(),
     null,
     recognizer._ctx);
}

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

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

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

public FailedPredicateException(Parser recognizer,
                String predicate,
                String message)
{
  super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx);
  ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
  AbstractPredicateTransition trans = (AbstractPredicateTransition)s.transition(0);
  if (trans instanceof PredicateTransition) {
    this.ruleIndex = ((PredicateTransition)trans).ruleIndex;
    this.predicateIndex = ((PredicateTransition)trans).predIndex;
  }
  else {
    this.ruleIndex = 0;
    this.predicateIndex = 0;
  }
  this.predicate = predicate;
  this.setOffendingToken(recognizer.getCurrentToken());
}

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

Token t = getCurrentToken();
if (t.getType() > 0) {
  _errHandler.reportMatch(this);

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

Token t = getCurrentToken();
if ( t.getType()==ttype ) {
  if ( ttype==Token.EOF ) {

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

Token matchedSymbol = recognizer.getCurrentToken();

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

Token o = getCurrentToken();
if (o.getType() != EOF) {
  getInputStream().consume();

代码示例来源:origin: io.virtdata/virtdata-lib-realer

public NoViableAltException(Parser recognizer) { // LL(1) error
  this(recognizer,
     recognizer.getInputStream(),
     recognizer.getCurrentToken(),
     recognizer.getCurrentToken(),
     null,
     recognizer._ctx);
}

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

Token currentSymbol = recognizer.getCurrentToken();
IntervalSet expecting = getExpectedTokens(recognizer);
int expectedTokenType = Token.INVALID_TYPE;

代码示例来源:origin: org.ballerinalang/language-server-core

private boolean isInFirstTokenOfCursorLine(Parser recognizer) {
  Token currentToken = recognizer.getCurrentToken();
  if (firstTokenOfCursorLine == null) {
    firstTokenOfCursorLine = getFirstTokenOfCursorLine(recognizer);
  }
  return firstTokenOfCursorLine != null && currentToken.getTokenIndex() == firstTokenOfCursorLine.getTokenIndex();
}

代码示例来源:origin: org.ballerinalang/ballerina-lang

@Override
public void reportUnwantedToken(Parser parser) {
  if (parser.getContext().exception != null || inErrorRecoveryMode(parser)) {
    return;
  }
  beginErrorCondition(parser);
  setErrorState(parser);
  Token token = parser.getCurrentToken();
  DiagnosticPos pos = getPosition(getMissingSymbol(parser));
  dlog.error(pos, DiagnosticCode.EXTRANEOUS_INPUT, getTokenErrorDisplay(token));
}

相关文章

微信公众号

最新文章

更多