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. --Loring ----- Original Message ---- > From: Christian Convey <[email protected]> > To: Loring Craymer <[email protected]> > Cc: John B. Brodie <[email protected]>; [email protected] > Sent: Sun, June 6, 2010 3:56:10 PM > Subject: Re: [antlr-interest] Parsing whole-line comments? > > On Sun, Jun 6, 2010 at 6:49 PM, Loring Craymer < > ymailto="mailto:[email protected]" > href="mailto:[email protected]">[email protected]> 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. List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
