[antlr-interest] Nested multi-line comments

John B. Brodie jbb at acm.org
Sat Oct 24 16:31:19 PDT 2009


Greetings!
On Sat, 2009-10-24 at 17:40 +0100, Peter Boughton wrote:
> How do I support nested comments with ANTLR?
> 

This is what I use:

// multiple-line comments
ML_COMMENT : NESTED_COMMENTARY { $channel=HIDDEN; } ;

fragment NESTED_COMMENTARY :
      '/*'
      ( options {greedy=false;} : . )*
      ( NESTED_COMMENTARY ( options {greedy=false;} : . )* )*
      '*/'
   ;

(note that this works using ANTLR 3.1.3 from Mar 2009, kinda old but I
think should still work with current ANTLR versions)

Perhaps you can adapt it to your language....
Hope this helps
   -jbb




More information about the antlr-interest mailing list