This project is read-only.

Multi-line comment block recognizing

Oct 14, 2014 at 12:14 PM
Hi, everybody!
How I must create rule for multiline comment recognizing? Comment begin with ( and end with )
I tried the follow grammar:
        COMMENT      -> '(*' .* '*)' ;
this works fine when source text has one comment block only. But when source text has an several comment blocks, then recognized terminal contains whole symbols from the first matching '(' to the last matching ')'
Oct 14, 2014 at 12:52 PM

To do this you can use the language difference operator, noted '-'. So for your case:
COMMENT -> '(*' (.* - (.* '*/' .*)) '*)' ;
This rule will match any string beginning with (, ending with ) and a string or zero or more characters inside. Except that the inner string cannot contain the *) sequence.
In practice, this will solve your issue because this is the formal definition of the informal 'the comment ends at the first *) occurence'.

As an additional note, this project has been moved to bitbucket at:

I hope this helps!

Oct 14, 2014 at 7:27 PM
Thanks, Laurent! It's perfect, but it has a small mistake, right notation:
COMMENT -> '(*' (.* - (.* '*)' .*)) '*)' ;
Also, this similar solution I found in your extras\Grammars\