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

PreviousTokenOnChannel() protected method

Given a starting index, return the index of the previous token on channel.
Given a starting index, return the index of the previous token on channel. Return i if tokens[i] is on channel. Return -1 if there are no tokens on channel between i and 0.

If i specifies an index at or after the EOF token, the EOF token index is returned. This is due to the fact that the EOF token is treated as though it were on every channel.

protected PreviousTokenOnChannel ( int i, int channel ) : int
i int
channel int
return int
        protected internal virtual int PreviousTokenOnChannel(int i, int channel)
        {
            Sync(i);
            if (i >= Size)
            {
                // the EOF token is on every channel
                return Size - 1;
            }
            while (i >= 0)
            {
                IToken token = tokens[i];
                if (token.Type == TokenConstants.EOF || token.Channel == channel)
                {
                    return i;
                }
                i--;
            }
            return i;
        }