Antlr4.Runtime.BufferedTokenStream.GetTokens C# (CSharp) Method

GetTokens() public method

Given a start and stop index, return a List of all tokens in the token type BitSet . Return if no tokens were found. This method looks at both on and off channel tokens.
public GetTokens ( int start, int stop, BitSet types ) : IList
start int
stop int
types Antlr4.Runtime.Sharpen.BitSet
return IList
        public virtual IList<IToken> GetTokens(int start, int stop, BitSet types)
        {
            LazyInit();
            if (start < 0 || stop >= tokens.Count || stop < 0 || start >= tokens.Count)
            {
                throw new ArgumentOutOfRangeException("start " + start + " or stop " + stop + " not in 0.." + (tokens.Count - 1));
            }
            if (start > stop)
            {
                return null;
            }
            // list = tokens[start:stop]:{T t, t.getType() in types}
            IList<IToken> filteredTokens = new List<IToken>();
            for (int i = start; i <= stop; i++)
            {
                IToken t = tokens[i];
                if (types == null || types.Get(t.Type))
                {
                    filteredTokens.Add(t);
                }
            }
            if (filteredTokens.Count == 0)
            {
                filteredTokens = null;
            }
            return filteredTokens;
        }

Same methods

BufferedTokenStream::GetTokens ( ) : IList
BufferedTokenStream::GetTokens ( int start, int stop ) : IList
BufferedTokenStream::GetTokens ( int start, int stop, int ttype ) : IList

Usage Example

 public static int GetTrailingTriviaTokenEndIndex(IToken token, BufferedTokenStream tokenStream, int triviaChannel = -1)
 {
     IList<IToken> tokens = tokenStream.GetTokens();
     int i = token.TokenIndex + 1;
     int lastTriviaToken = token.TokenIndex;
     while (i < tokens.Count)
     {
         IToken t = tokens[i];
         string text = t.Text;
         if (t.Channel == 0)
         {
             return lastTriviaToken;
         }
         else if (text.Contains('\r') || text.Contains('\n'))
         {
             if (string.IsNullOrWhiteSpace(text)) return lastTriviaToken;
             else return i;
         }
         else if (triviaChannel < 0 || t.Channel == triviaChannel)
         {
             lastTriviaToken = i;
         }
         ++i;
     }
     return lastTriviaToken;
 }
All Usage Examples Of Antlr4.Runtime.BufferedTokenStream::GetTokens