[antlr-interest] Reg Multi-line comments

Gokulakannan Somasundaram gokul007 at gmail.com
Thu Jul 16 05:08:25 PDT 2009


Thanks.. I think it looks good atleast to me.. But i think  i would go with
using @init part, but instead of overriding the nextToken, i will override
the getErrorMessage() function. I just feel that compairson for every
nextToken call might be slightly costly.

But thanks for the solution.

Gokul.

On Thu, Jul 16, 2009 at 5:05 PM, Michael <micha-1 at fantasymail.de> wrote:

> Am Thursday 16 July 2009 12:14:55 schrieb Gokulakannan Somasundaram:
> > Hi,
> >    I am trying to filter out multi-line comments, for which i am using
> the
> > following Token definition (provided in antlr.org)
> > ML_COMMENT
> >
> >     :    '/*' ( options { greedy = false; } : .* ) '*/' { skip(); };
> >
>
> I have done it like this:
> in the lexer I added a member openComment:
>
> @member {
>        boolean openComment = false;
>
>        //override nextToken:
>        @Override
>        public Token nextToken() {
>                Token t = super.nextToken();
>                if (t == Token.EOF_TOKEN && openComment) {
>                        System.err.println("gotcha!");
>                }
>                return t;
>        }
>
> }
>
>
> change your comment rule :
>
> ML_COMMENT
> @init { openComment = true: }
>    :    '/*' ( options { greedy = false; } : .* ) '*/' { openComment =
> false;
> skip(); };
>
>
>
>
> don't know if this is nice, but it works :-)
>  Michael
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090716/9714bffe/attachment.html 


More information about the antlr-interest mailing list