I am new to ANTLR and want to clarify some basic concepts.
-
Is the parser receiving a Token stream from the lexer? If yes, how does the hidden channel concept fit into this Token stream? Does it mean for each token in the stream, it got an attribute showing which channel it belongs to?
-
I want to access the hidden channel tokens (white-spaces or comments) that is, say, preceding my own token in the parser. I think I must explicitly write some code. Is it through org.antlr.runtime.TokenStream.get()? What parameter value should be given to it?
A
TokenStreamis wrapped around the lexer. By default, theParser“polls” this stream for tokens as needed (i.e. the input is not tokenized in one go, but is buffered).The default
TokenStreamwill only produce tokens placed on theDEFAULTchannel. You can change the channel during parsing however (or read from more than one channel) [1].Correct, see [1].
[1] How do I get an Antlr Parser rule to read from both default AND hidden channel