[antlr-interest] BUG - Antlr is snooping in comments
Randall R Schulz
rschulz at sonic.net
Fri Oct 12 12:57:32 PDT 2007
On Friday 12 October 2007 12:44, Austin Hastings wrote:
> /* There's a comment here, too. */
> scope Mumble {
> int foo; /* Comment at the end? (x = 1) */
> }
>
>
> After scratching my head for a while over a mysterious error message,
> I finally got the example case above.
>
> From what I can tell, ANTLR treats the curly braces as delimiting
> some mysterious other language -- this is decent, since it is trying
> to be language-agnostic. But the error message is a killer:
>
> ...
There are other pitfalls of using target language comments within action
blocks.
The one I've encountered is the inadvisability of using
end-of-line-terminated comments. Many of the substitutions that the
ANTLR code generator applies to the content of action blocks have
embedded newlines. So if you try to comment out something with, say,
a // comment (taking C / C++ or Java as the target language) you may
end up with some baffling syntax errors when you compile the result.
I suppose under certain circumstances you could even get syntactically
valid code that didn't do what you wanted (or did more, I guess you'd
say).
> =Austin
You have been warned...
Randall Schulz
More information about the antlr-interest
mailing list