BufferedTokenStream with functionality to filter
token streams to tokens on a particular channel (tokens where
Token#getChannel returns a particular value).
This token stream provides access to all tokens by index or when calling
methods like getText. The channel filtering is only used for code
accessing tokens via the lookahead methods LA, LT, and
LB.
By default, tokens are placed on the default channel
(Token#DEFAULT_CHANNEL), but may be reassigned by using the
->channel(HIDDEN) lexer command, or by using an embedded action to
call Lexer#setChannel.
Note
lexer rules which use the ->skip lexer command or call
Lexer#skip do not produce tokens at all, so input text matched by
such a rule will not be available as part of the token stream, regardless of
channel.
| Modifier and Type | Field and Description |
|---|---|
| protected int | channel
Specifies the channel to use for filtering tokens. |
| Access | Constructor and Description |
|---|---|
| public | CommonTokenStream(TokenSource
The token source. tokenSource)Constructs a new |
| public | CommonTokenStream(TokenSource
The token source. tokenSource, int The channel to use for filtering tokens. channel)Constructs a new |
| Modifier and Type | Method and Description |
|---|---|
| protected int | adjustSeekIndex(int
The target token index. i)Overrides org. |
| public int | |
| protected Token | |
| public Token | LT(int k)
Overrides org. Implements org. Token instance associated with the value returned by
LA(k).
|
| channel | back to summary |
|---|---|
| protected int channel Specifies the channel to use for filtering tokens.
The default value is | |
| CommonTokenStream | back to summary |
|---|---|
| public CommonTokenStream(TokenSource tokenSource) Constructs a new
| |
| CommonTokenStream | back to summary |
|---|---|
| public CommonTokenStream(TokenSource tokenSource, int channel) Constructs a new
| |
| adjustSeekIndex | back to summary |
|---|---|
| protected int adjustSeekIndex(int i) Overrides org. Doc from org. Allowed derived classes to modify the behavior of operations which change
the current stream position by adjusting the target token index of a seek
operation. The default implementation simply returns For example,
| |
| getNumberOfOnChannelTokens | back to summary |
|---|---|
| public int getNumberOfOnChannelTokens() Count EOF just once. | |
| LB | back to summary |
|---|---|
| protected Token LB(int k) Overrides org.
| |
| LT | back to summary |
|---|---|
| public Token LT(int k) Overrides org. Implements org. Doc from org. Get the
| |