views:

150

answers:

2

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

+1  A: 

When you construct a CommonTokenStream, you tell it what channel to use. Tokens on other channels will not be visible to the parser.

280Z28
I refer to this http://www.antlr.org/wiki/pages/viewpage.action?pageId=557063. But not being an expert in ANTLR not understand how to use these methods.thanks
Batman
+1  A: 

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.

chollida