[antlr-interest] About literal supports unicode

Ha Luong haluongvn at gmail.com
Sat Jun 13 07:51:39 PDT 2009


Dear all,

I tried to use the grammar for accepting the unicode string as follow:
//modify T.g in the example source of ANTLR book
grammar T;
options {
    language=Java;
}
@members {
String s;
}
r : ID '#' {s = $ID.text; System.out.println("found "+s);} ;
ID: ('a'..'z'|'\u00e0')+ ; //\u00e0
WS: (' '|'\n'|'\r')+ {skip();} ; // ignore whitespace

and do these commands in cygwin:
java org.antlr.Tool T.g
javac *.java

If I test the literal 'a', it is ok
java Test
a #
^Z
found a

but the literal 'à', it has error:
java Test
à
#
^Z
line 1:0 no viable alternative at character 'à'
line 2:0 missing ID at '#'
found <missing ID>

Could you please help me how can I add the literal unicode in ANTLR grammar?


Thank you very much,
Ha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090613/9e9a81e5/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_literal_unicode.zip
Type: application/zip
Size: 809 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090613/9e9a81e5/attachment.zip 


More information about the antlr-interest mailing list