[antlr-interest] simple grammar with wildcard
Shaoting Cai
caishaoting at gmail.com
Wed Apr 23 08:30:13 PDT 2008
Hi Jason,
The fragment rule NONQUOTE hides the ID rule.
# is 35, ~ is 126
'a'..'z' and 'A'..'Z' is within 35..126
> fragment
> NONQUOTE
> :' '..'!'|'#'..'~'|'\r'|'\n';
-Shaoting
On Wed, Apr 23, 2008 at 7:46 AM, jason zhang <jasonzhang2002 at gmail.com> wrote:
> Hi, All
> I have a simple grammar. I can not get it work. Help is appreciated.
> My input text is like this
> name:"value". The value can span multiple line.
> My grammar is like this
> -------------------
> grammar Test;
> program : attribute*;
> attribute : n=ID ':' '"' e=ATTRVALUE '"' LINEBREAK{
> System.out.println("match attrname==============="+$n.text+"
> attrvalue="+$e.text);};
>
>
> ATTRVALUE:NONQUOTE*;
> ID :('a'..'z'|'A'..'Z'|'0'..'9'|'-'|'_')+;
> WS : ( '\t' | ' ' )+ { $channel = HIDDEN; } ;
> LINEBREAK
> : '\r'?'\n';
> //printable ASCII character except ", including \r and \n.
> fragment
> NONQUOTE
> :' '..'!'|'#'..'~'|'\r'|'\n';
> ---------------------
> When I check this grammar through antlrWorks, I got the error like " The
> following token definitions are unreachable: ID,LINEBREAK".
>
> -jason
>
>
>
>
>
>
>
More information about the antlr-interest
mailing list