[antlr-interest] simple grammar with wildcard

Johannes Luber jaluber at gmx.de
Wed Apr 23 09:53:39 PDT 2008


jason zhang schrieb:
> Hi, cai
> I removed the NONQUOTE definition and use wildcard.
> ------------------------------
> grammar Test;
> 
> program : attribute*;
> attribute : n=ID ':' '"' e=(.*)'"' LINEBREAK{ System.out.println("match 
> attrname==============="+$n.text+" attrvalue="+$e.text);};
> ID    :    ('a'..'z'|'A'..'Z'|'0'..'9'|'-'|'_')+;
> WS : ( '\t' | ' ' )+     { $channel=HIDDEN; } ;   
> LINEBREAK
>     :    '\r'?'\n';
> --------------------------------
> When I test this grammar by running generated java code. The e is not 
> set by the generated java code anywhere. I got a NullPointerException. 
> How can I capture the value (.*) ?
> 
> thanks
> 
> -jason

You have encountered a known bug. One can't use "e=(...)" yet. Either 
you can forgo the parentheses or you have to create a new subrule.

Johannes


More information about the antlr-interest mailing list