[antlr-interest] antlr-interest Digest, Vol 30, Issue 33

Mark Venbrux mark.venbrux at gmail.com
Tue May 15 16:09:50 PDT 2007


>
> Subject: Re: [antlr-interest] Separating text from comment in a source
> file
> Mark Venbrux wrote:
> > Hi,
> >
> > I would like to separate text from comment in a source file. In the end
> > I would like to keep the source code as is, and to process the comments.
> > I tried the following grammar, but it doesn't work as expected.
> > Warning: [17:01:59] warning(201): d:\temp\antlr.g:26:40: The following
> > alternatives are unreachable: 1
> > This is about the TEXT rule.
> >
> > Comments are picked up, but text is skipped. What is wrong here?
> >
> > Cheers,
> > Mark
>
> Why is filter=true? With your grammar you don't actually skip anything
> but match all text into some tokens. If this isn't enough, then you need
> to change TEXT into something like that:


Thanks for the quick response.
OK I cleaned up my grammar. In AWorks I now get:
line 1:0 required (...)+ loop did not match anything at character 'l'
line 1:1 required (...)+ loop did not match anything at character 'i'
line 1:2 required (...)+ loop did not match anything at character 'n'
line 1:3 required (...)+ loop did not match anything at character 'e'
....
with an early exit exception. I also fiddled with syntactic predicates but
this doesn't work either.
Should be simple enough though? This is the grammar:

> grammar MiCoGen;
>
>  file:  (
>                 ML_COMMENT  {System.out.print("CS: "+$ML_COMMENT.text);}
>         |       TEXT        {System.out.print("TE: "+$TEXT.text);}
>         )+
>         ;
>
>
>  ML_COMMENT : '/*' (options {greedy=false;} : .)+ '*/' ;
>
>  TEXT :  (options {greedy=false;} : ~COMMENT_STARTER )+;
>
>  COMMENT_STARTER : '/*';
>
>




-- 
Mvg,
    Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070516/9f1337ed/attachment.html 


More information about the antlr-interest mailing list