[antlr-interest] Adding one newline changes tokens recognized

Jan van Mansum janvanmansum at gmail.com
Mon Oct 6 08:02:52 PDT 2008


Hello group,

I have the following grammar:

--- TestComment.g ---
grammar TestComment;

input
    :    (statement ';')*
    ;

statement
    :    ANNOTATION
    ;

ANNOTATION
       :       '--!' .*  '\n'
       ;

COMMENT
    :       '--' .* '\r'? '\n' {$channel = HIDDEN;}
       ;

WS    :    (' '|'\n'|'\r'|'\t')+ {$channel = HIDDEN;}
    ;
---

And the following input (without the double quotes):

"--!myAnnotation
;"

This doesn't work. "--!myAnnotation" is considered an ordinary comment by
Antlr and hidden. I don't understand why, as I thought that antlr should
match the tokens in order, and so find that ANNOTATION matches the input.

If I add one more newline to the file that does happen.

Can anyone explain to me why that is? I am puzzled.

I am using antlr 3.0.1 by the way.

Thanks for any help,

best regards,

-- 
Jan van Mansum
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081006/66565ec4/attachment.html 


More information about the antlr-interest mailing list