[antlr-interest] Parsing comments

Soren Holstebroe holstebroe at gmail.com
Thu Sep 17 09:59:50 PDT 2009


Thank you for your answer,

As i understand it, your suggestion considers the whole template line as a
single token, but I don't want the template token to eat up the rest of the
line, since this is where my template wrapping grammar would be.

My grammar will have rules like this:

wrap_option
    : WRAP_OPTION_BEGIN
    (  'WRAP'
    | 'TEMPLATE' '<' type_specifier (',' type_specifier)* '>'
    )
    ;

so I need something to match '//' WS* '@' as my WRAP_OPTION_BEGIN.

Soren

2009/9/17 Indhu Bharathi <indhu.b at s7software.com>

>  Try using semantic predicates to look-ahead and decide whether to emit
> SLCOMMENT or TEMPLATE
>
>
>
> Something like:
>
>
>
> fragment SLCOMMENT
>
>                 :               ;
>
>
>
> fragment TEMPLATE
>
>                 :               ;
>
>
>
> SLCOMMENT_OR_TEMPLATE
>
>                 :               '//' (
>
>                                                 { input.LA(1)=='@' }?=> (
> options {greedy=false;} : . )* EOL    { $type=TEMPLATE; }
>
>                                 |              ( options {greedy=false;} :
> . )* EOL    { $type=SLCOMMENT; }
>
>                                 )
>
>                 ;
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090917/42f9c3c2/attachment.html 


More information about the antlr-interest mailing list