[antlr-interest] Grammar for block comments?

Andy Doddington andy at doddington.net
Thu Jul 17 00:56:32 PDT 2008


Gavin Lambert wrote:
> At 05:53 17/07/2008, Andy Doddington wrote:
> >> COMMENT: '/*' (~'*' | '*' ~'/')* '*/' { $channel = HIDDEN; };
> >>
> >Your suggestion made a lot of sense - however, it doesn't seem to
> >have had any effect on my problem, which seems strange - even the
> >error message is identical :-(
>
> Very strange; something like that has always worked for me.
>
> Well, I suppose one more thing you could try is to force the lookahead 
> with a synpred:
>
> COMMENT
>   : '/*'
>     ( ~'*'
>     | ('*' ~'/') => '*' ~'/'
>     )*
>     '*/'
>   { $channel = HIDDEN; }
>   ;
>
>
I haven't had a chance to test this in my app, but when I run it inside 
AntlrWorks I get a:

            FailedPredicateException(COMMENT, {synpred1}?)

As an aside, doesn't the fact that this relatively simple case seems so 
hard to crack indicate that Antlr may have
a problem? I offer this as a humble suggestion from a complete newbie - 
it seems like a great tool otherwise! :-)

AD


More information about the antlr-interest mailing list