예제 #1
0
파일: Parser.java 프로젝트: antlr/antlr4
  /**
   * 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.
   *
   * <p>If the symbol type does not match, {@link ANTLRErrorStrategy#recoverInline} is called on the
   * current error strategy to attempt recovery. If {@link #getBuildParseTree} is {@code 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 ParserRuleContext#addErrorNode}.
   *
   * @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
   */
  public Token matchWildcard() throws RecognitionException {
    Token t = getCurrentToken();
    if (t.getType() > 0) {
      _errHandler.reportMatch(this);
      consume();
    } else {
      t = _errHandler.recoverInline(this);
      if (_buildParseTrees && t.getTokenIndex() == -1) {
        // we must have conjured up a new token during single token insertion
        // if it's not the current symbol
        _ctx.addErrorNode(t);
      }
    }

    return t;
  }
예제 #2
0
 public void replace(String programName, Token from, Token to, Object text) {
   replace(programName, from.getTokenIndex(), to.getTokenIndex(), text);
 }
예제 #3
0
 public void insertBefore(String programName, Token t, Object text) {
   insertBefore(programName, t.getTokenIndex(), text);
 }
예제 #4
0
 @Override
 public Interval getSourceInterval() {
   if (start == null || stop == null) return Interval.INVALID;
   return Interval.of(start.getTokenIndex(), stop.getTokenIndex());
 }
예제 #5
0
 public String toString(Token start, Token stop) {
   if (start != null && stop != null) {
     return toString(start.getTokenIndex(), stop.getTokenIndex());
   }
   return null;
 }