상속: IWritableToken
예제 #1
0
        public virtual CommonToken Create(Sharpen.Tuple <ITokenSource, ICharStream> source, int type, string text, int channel, int start, int stop, int line, int charPositionInLine)
        {
            CommonToken t = new CommonToken(source, type, channel, start, stop);

            t.Line   = line;
            t.Column = charPositionInLine;
            if (text != null)
            {
                t.Text = text;
            }
            else
            {
                if (copyText && source.Item2 != null)
                {
                    t.Text = source.Item2.GetText(Interval.Of(start, stop));
                }
            }
            return(t);
        }
예제 #2
0
 public virtual CommonToken Create(Tuple<ITokenSource, ICharStream> source, int type, string text,
     int channel, int start, int stop, int line, int charPositionInLine)
 {
     CommonToken t = new CommonToken(source, type, channel, start, stop);
     t.Line = line;
     t.Column = charPositionInLine;
     if (text != null)
     {
         t.Text = text;
     }
     else
     {
         if (copyText && source.Item2 != null)
         {
             t.Text = source.Item2.GetText(Interval.Of(start, stop));
         }
     }
     return t;
 }
예제 #3
0
      //@Override
      //public Token nextToken() {

      //  // Check if the end-of-file is ahead and there are still some DEDENTS expected.
          
      //  if (_input.LA(1) == EOF && !this.indents.isEmpty()) {

      //    // Remove any trailing EOF tokens from our buffer.
      //    for (int i = tokens.size() - 1; i >= 0; i--) {
      //      if (tokens.get(i).getType() == EOF) {
      //        tokens.remove(i);
      //      }
      //    }

      //    // First emit an extra line break that serves as the end of the statement.
      //    this.emit(commonToken(Python3Parser.NEWLINE, "\n"));

      //    // Now emit as much DEDENT tokens as needed.
      //    while (!indents.isEmpty()) {
      //      this.emit(createDedent());
      //      indents.pop();
      //    }

      //    // Put the EOF back on the token stream.
      //    this.emit(commonToken(Python3Parser.EOF, "<EOF>"));
      //  }

      //  Token next = super.nextToken();

      //  if (next.getChannel() == Token.DEFAULT_CHANNEL) {
      //    // Keep track of the last token on the default channel.
      //    this.lastToken = next;
      //  }

      //  return tokens.isEmpty() ? next : tokens.poll();
      //}

    private IToken createDedent()
    {
        CommonToken dedent = new CommonToken(Python3Parser.DEDENT, "");
        dedent.Line = lastToken.Line;
        return dedent;
    }
예제 #4
0
파일: Trees.cs 프로젝트: sharwell/antlr4cs
 /// <summary>
 /// Replace any subtree siblings of root that are completely to left
 /// or right of lookahead range with a CommonToken(Token.INVALID_TYPE,"...")
 /// node.
 /// </summary>
 /// <remarks>
 /// Replace any subtree siblings of root that are completely to left
 /// or right of lookahead range with a CommonToken(Token.INVALID_TYPE,"...")
 /// node. The source interval for t is not altered to suit smaller range!
 /// WARNING: destructive to t.
 /// </remarks>
 /// <since>4.5.1</since>
 public static void StripChildrenOutOfRange(ParserRuleContext t, ParserRuleContext root, int startIndex, int stopIndex)
 {
     if (t == null)
     {
         return;
     }
     for (int i = 0; i < t.ChildCount; i++)
     {
         IParseTree child = t.GetChild(i);
         Interval range = child.SourceInterval;
         if (child is ParserRuleContext && (range.b < startIndex || range.a > stopIndex))
         {
             if (IsAncestorOf(child, root))
             {
                 // replace only if subtree doesn't have displayed root
                 CommonToken abbrev = new CommonToken(TokenConstants.InvalidType, "...");
                 t.children.Set(i, new TerminalNodeImpl(abbrev));
             }
         }
     }
 }