[antlr-interest] Parsing whole-line comments?

Christian Convey christian.convey at gmail.com
Sun Jun 6 15:56:10 PDT 2010


On Sun, Jun 6, 2010 at 6:49 PM, Loring Craymer <lgcraymer at yahoo.com> wrote:
> You can, of course, do
>
> COMMENT : '\n' 'C' (~'\n')+ ;
>
> NEWLINE: '\n' ;
>
> (the ordering matters for ANTLR 3's DFA construction), but the approach Brodie suggested is the common idiom since it costs less in terms of performance and does not depend on the quirks of ANTLR DFA construction.  "Start of line" is a semantic notion, whereas '\n' 'C' specifies syntax.


Thanks.  How would you handle the case where the very first line in
the file is a comment line?  That is, there's no preceding newline
sequence.


More information about the antlr-interest mailing list