[antlr-interest] Nested multi-line comments

John B. Brodie jbb at acm.org
Sun Oct 25 07:23:59 PDT 2009


On Sun, 2009-10-25 at 01:03 +0100, Peter Boughton wrote:
> Thanks John, but this doesn't appear to be working.
> (I'm using antlr 3.2 with antlrworks 1.3)
> 
> I tried it both as provided and with changing the comment start/end
> characters, and both of these give the same error in the generated
> Java code:
> 
> 	C:\tmp\antlr\__Test__.java:14: cannot find symbol
> 	symbol  : method ML_COMMENT()
> 	location: class cfml_comment_testParser
> 	            g.ML_COMMENT();
> 	             ^
> 	1 error
> 
> I'm testing this with a very basic set of rules at the moment:
> 
> 	grammar cfml_comment_test;
> 	
> 	ML_COMMENT : NESTED_COMMENTARY { $channel=HIDDEN; } ;
> 	
> 	fragment NESTED_COMMENTARY :
> 	     '<!---'
> 	     ( options {greedy=false;} : . )*
> 	     ( NESTED_COMMENTARY ( options {greedy=false;} : . )* )*
> 	     '--->'
> 	  ;
> 	
> 	WS : ( ' ' | '\t' | '\n' | '\r' ) {$channel=HIDDEN;} ;
> 	
> 	TEXT: ~'<' ;
> 	
> 	code: ( ML_COMMENT | WS | TEXT )+;
> 
> 
> Any ideas?

just upgraded to ANTLR 3.2 as contained in the ANTLRWorks 1.3 jar file.

and now, for me, the above grammar compiles without any error.

perhaps, as someone else suggested, you have a problem with your test
rig? I notice that the identifier `g` appears *nowhere* in your posted
grammar, yet the compiler error message references `g`.....


as an aside, your Parser rule `code` is trying to recognize both
ML_COMMENT and WS which are HIDDEN Tokens -- the Lexer will never
deliver those Tokens to the Parser (that is, after all, the whole
purpose of the HIDDEN channel).







More information about the antlr-interest mailing list