[antlr-interest] Preserving Comments

Laurent Caillette laurent.caillette at gmail.com
Mon Jul 14 00:40:50 PDT 2008


You'll have to define a rule making the comment a "first-class person"
in your grammar. By now comments are silently swallowed by your
parser.
I've no idea of how your grammar looks like but you may have to define
the whitespace as a rule itself, and include the comments inside the
whitespace rule.

Regards,

c.
http://novelang.sf.net

On Mon, Jul 14, 2008 at 9:13 AM,  <nilesh.kapile at tcs.com> wrote:
>
> Hello,
>
> I need to preserve comments and want to collect it in some data structure.
>  How can we do that in ANTLR?
>
> Currently, I've following rule for comments:
>
> LINE_COMMENT
>     :  '//' ~('\n'|'\r')* '\r'? '\n'   {$channel=HIDDEN;}
>     ;


More information about the antlr-interest mailing list