matchWildcard method

Token matchWildcard()

Match current input symbol as a wildcard. If the symbol type matches (i.e. has a value greater than 0), {@link ANTLRErrorStrategy#reportMatch} and {@link #consume} are called to complete the match process.

If the symbol type does not match, {@link ANTLRErrorStrategy#recoverInline} is called on the current error strategy to attempt recovery. If {@link #getBuildParseTree} is [true] and the token index of the symbol returned by {@link ANTLRErrorStrategy#recoverInline} is -1, the symbol is added to the parse tree by calling {@link Parser#createErrorNode(ParserRuleContext, Token)}. then {@link ParserRuleContext#addErrorNode(ErrorNode)}

@return the matched symbol @throws RecognitionException if the current input symbol did not match a wildcard and the error strategy could not recover from the mismatched symbol

Implementation

Token matchWildcard() {
  var t = currentToken;
  if (t.type > 0) {
    errorHandler.reportMatch(this);
    consume();
  } else {
    t = errorHandler.recoverInline(this);
    if (buildParseTree && t.tokenIndex == -1) {
      // we must have conjured up a new token during single token insertion
      // if it's not the current symbol
      context!.addErrorNode(createErrorNode(context!, t));
    }
  }

  return t;
}