[antlr-interest] Parsing whole-line comments?

Christian Convey christian.convey at gmail.com
Sun Jun 6 17:27:42 PDT 2010


On Sun, Jun 6, 2010 at 8:16 PM, Loring Craymer <lgcraymer at yahoo.com> wrote:
> Then you probably would want to handle this special case with a custom subclass of ANTLRFileStream that checks to see if the first line begins with 'C' and consumes the line (but not the newline following) if it does.  (You would also need to subclass CommonTokenStream if you need to keep that first comment).  This is not the most elegant solution, perhaps, but it provides optimal performance at about the same implementation cost as any of the alternatives.
>
> Lexer modes would be another way of handling this problem, but they are not currently supported in ANTLR 3.  For that matter, this would also not be a problem if ANTLR lexer grammars were true context free grammars that supported start symbols, but then you would have to deal with writing the top level Tokens rule yourself--probably not a good trade.

Thanks for all the ideas.  It sounds like for now I'm going to want to
just hand-write my parser.  The language in question really is dead
simple, it's just line-orientation that seems to be complicating the
picture so much.

- Christian


More information about the antlr-interest mailing list