[antlr-interest] File comments aka. unclosed comments

Ramon Verbruggen Ramon.Verbruggen at quintiq.com
Tue Oct 30 07:46:23 PDT 2007


I have spent quite some time trying to figure this out, and searched the
internet extensively (including the antlr mailing list archives) but
could not find anything related, so as a last resort I am posting this
here.

I am trying to replace our current parser (ancient YACC++) with an
ANTLR generated parser and really want to maintain complete backwards
compatibility.

For reasons that are lost in time, our language (Quill) supports
unclosed comments (or comments until the end of file), so apart from the
normal (albeit nested) block comment '/* ... */', just inserting '/*' in
a code body effectively comments out the rest of the code in the file.

I currently have something like this:

Q_Comment_nested
	:	'/*' ( options {greedy=false;} : Q_Comment_nested | .)*
'*/' {$channel=HIDDEN;}
	;

Q_Unclosed_comment
	:	'/*' ( options {greedy=false;} : ~'*/')* EOF
{$channel=HIDDEN;}
	;

The above (obviously) reports an unreachable alternative and a
recursive overflow because the unclosed comment matches anything that
the nested comment matches as well.

I have tried many different solutions like:

Q_Comment_nested
	:	'/*' ( options {greedy=false;} : Q_Comment_nested | .)*
( '*/' | EOF) {$channel=HIDDEN;}
	;

or:

Q_Comment_nested
	:	'/*' ( options {greedy=false;} : (~'*/'))* '*/'?
{$channel=HIDDEN;}
	;

Whatever I tried, I just cannot seem to get it right!

I am open to suggestions ( I know, 'comments are ugly', 'use source
control or ifdef instead of comments' etc., but this should be possible,
right?!)

Ramon Verbruggen

Join Quintessence 07 - the annual global Quintiq conference on November
20th! www.quintiq.com/quintessence


This message contains information that may be privileged or confidential
and is the property of Quintiq. It is only intended for the person to
whom it is addressed. If you are not the intended recipient, you are not
authorized to read, print, retain, copy, disseminate, distribute or use
this message or any part thereof. If you have received this message in
error, please notify the sender immediately and delete all copies of
this message. Please note that e-mails are susceptible to change,
therefore they are not binding.


More information about the antlr-interest mailing list