[antlr-interest] Code generation weirdness?

Darien Hager darien.hager at etelos-inc.com
Tue Jan 29 17:02:08 PST 2008


Very much a newbie experimenting here, so apologies for imprecision and
misunderstandings in advance.

I'm using AntlrWorks 1.16, and the generated code for Python breaks
when combined with the JSON grammar on the wiki. Interpreter/Debugger does
fine.

It appears that a python class named "object" is created in jsonParser.py,
matching the grammar's rule of the same name.  (Not the AST tree label,
that's all upper-case)

The problem is that choosing the name "object" is probably a bad idea for
many reasons, and things blow up.
_______
Traceback (most recent call last):
File "jsonParser.py", line 44, in <module>
class jsonParser(Parser):
File "jsonParser.py", line 593, in jsonParser
class array_return(object):
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
_______

Changing the grammar's AST tree label to "j_object" fixes the problems.

Is there a reason that these generated classnames don't have some sort of
default prefix for language safety? Could such a thing be reasonably
implemented? It seems like a big pitfall that grammar rule names can
collide with target language keywords.
It's possible that there was some warning about this kind of bug and I
missed it...


-- 
Darien Hager
Developer
Etelos, Inc.
darien at etelos.com

http://www.etelos.com
"Revolutionizing the way applications are developed, distributed and
consumed."

This e-mail message, including attachments, may contain confidential
information for the sole use of the intended recipient(s). If you are not
the intended recipient, then this is notice that any use, disclosure,
dissemination, distribution or copying is strictly prohibited. If you have
received this message in error please contact the sender by reply mail and
destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080129/0745b495/attachment.html 


More information about the antlr-interest mailing list