[antlr-interest] Is it safe to overwrite the Lexer's text?

Bjoern Doebel doebel at tudos.org
Tue Aug 28 05:47:10 PDT 2007


Gavin Lambert wrote:
> At 00:11 29/08/2007, Bjoern Doebel wrote:
>>I have a language consisting of source code and comments. I have a
>>lexer and parser that create an AST of it. I would like to use the
>>created syntax tree as a starting point for several tools. Some of
>>them will need access to the comments, some of them won't. I
>>cannot just ignore the comments, but I also don't want to store
>>all of them inside the AST. Instead, inside the lexer I recognize
>>comments, copy them (current value of self.text) into a separate
>>table and replace the comment's text by overwriting self.text with
>>an index referencing the comment's table entry.
> 
> Isn't that what channels are for?

Maybe. TDAR isn't very verbose on this topic and only mentions hidden
channels for whitespaces. From my reading I understood that parsers can
only read from exactly one channel (TDAR, p. 25). However, for my purposes
I would need only the non-comment channel in some cases and both channels
in other cases. Is there any documenation on how to do this with channels?

Bjoern


More information about the antlr-interest mailing list