[antlr-interest] C# generated code refering rules

Micheal J open.zone at virgin.net
Thu Jul 5 14:29:32 PDT 2007


Hi,

> > But in any case, the C# code generator could work around 
> this by using 
> > the @ prefix.  (ie. @class is always an identifier, never a 
> keyword.) 
> > Ideally, it should only quote the ones that actually need 
> it (by being 
> > in the keyword list), but I'm not sure how easy that is to do in 
> > StringTemplate.  Failing that it could just quote everything ;)
> > 
> 
> Your suggestion doesn't work in general, as "@(" is not a 
> valid identifier. It would work though to put for all token 
> names, as they are generated right now, although it 
> considered to be a bad style to use e.g. "@id". And this 
> doesn't solve all collisions like for "input".

The "@(" issue is moot as "(" isn't a valid token_ref or rule_ref identifier
in ANTLR either.

Generating an "@" prefix for all token and rule references is doable but
isn't general enough. As you correctly pointed out, it won't resolve name
collisions with existing members such as "input".

The ANTLR tool itself will support  a more general scheme such as the old
name mangling prefix/suffix grammar option in due course.

Micheal

-----------------------
The best way to contact me is via the list/forum. My time is very limited.



More information about the antlr-interest mailing list