[antlr-interest] Rewriting tokens in AST grammar

Federico Di Gregorio fog at initd.org
Wed Dec 19 15:37:08 PST 2007


Hi,

first of all let me say that ANTLR is great. I used COCO/R before but
ANTLR error reporting and recovering are just much much better.

After the kudos, my little problem with an AST grammar (RDF turtle). I
recognize various kinds of literals at the token level:

literal
	: s=quotedString (LANG | DATATYPE)? -> ^(LITERAL $s LANG? DATATYPE?)
	| INTEGER -> ^(LITERAL INTEGER)
	| DOUBLE  -> ^(LITERAL DOUBLE)
	| DECIMAL -> ^(LITERAL DECIMAL)
	| BOOLEAN -> ^(LITERAL BOOLEAN)
	;

and everything works, but it would be much better to rewrite them in a
uniform way here in the AST generation and not in the tree walker. I
know that I can't do that but I'd show you what I'd like to do anyway
hoping there is a right way I have missed:

literal
	: s=quotedString (LANG | DATATYPE)? -> ^(LITERAL $s LANG? DATATYPE?)
	| INTEGER -> ^(LITERAL INTEGER DATATYPE["xsd:int"])
	| DOUBLE  -> ^(LITERAL DOUBLE DATATYPE["xsd:double"])
	...

and so on. In brief I'd like to generate the fake token that is implicit
in the literal type.

Many thanks,
federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                fog at debian.org
INIT.D Developer                                           fog at initd.org
  Those who do not study Lisp are doomed to reimplement it. Poorly.
                                     -- from Karl M. Hegbloom .signature
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Questa =?ISO-8859-1?Q?=E8?= una parte del messaggio
	firmata digitalmente
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20071220/3b7c01e9/attachment.bin 


More information about the antlr-interest mailing list