Can you use a token defined in the lexer in a hidden channel in a single rule of the parser as if it were a normal token? The generated code is Java...
thanks
Can you use a token defined in the lexer in a hidden channel in a single rule of the parser as if it were a normal token? The generated code is Java...
thanks
When you construct a CommonTokenStream, you tell it what channel to use. Tokens on other channels will not be visible to the parser.
Yes you can use a hidden token in the Parser.
We do this all the time. The only problem is that you need to know when to look for it.
Antlr has a few pieces of terminology that it uses.
A Hidden
token just travels on a separate stream. The user can always check for hidden tokens by calling getHiddenAfter
or getHiddenBefore
on a currently matched token.
Note: There may be more than one token hidden, before or after, a matched token so you should iterate through them.
A Discarded
token is actually removed when you tell the lexer to discard it. It will never be seen by you again.