[antlr-interest] C# generated code refering rules

Gavin Lambert antlr at mirality.co.nz
Thu Jul 5 14:11:37 PDT 2007


At 00:06 6/07/2007, Johannes Luber wrote:
 >The problem is simply that rule names are translated 1:1 into
 >function names. The workaround for now is to change the rule
 >in the grammar into something else. For consistency of rule
 >naming use the source I mentioned in my lats email's PS. This
 >problem appears also if you happen to use a member name of
 >the parser class like "input".  Unfortunately
 >Terence didn't integrate a name mangling option yet which would
 >prefix all rule names in functions.

There is a standard mangling scheme for the lexer; and I think the 
C target does some extra mangling of its own anyway :)

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 ;)



More information about the antlr-interest mailing list