Alex Rivera | Logout

Python metaclass and ModGrammar

Asked 2011-08-15T12:32:17.990
13

I found (after another question here on StackOverflow) this interesting library written in Python which goal is the grammar parsing.

http://code.google.com/p/modgrammar/

And I also found this tutorial regarding it:

http://packages.python.org/modgrammar/tutorial.html

So, after reading all the tutorial, I understood that this is what I'm looking for! I tried to write the first example in the tutorial:

from modgrammar import *
class MyGrammar (Grammar):
  grammar = (LITERAL("Hello,"), LITERAL("world!"))

but I ran into this error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from modgrammar import *
  File "/Users/tesi/Desktop/Prova/modgrammar/__init__.py", line 503
    class Grammar(metaclass=GrammarClass):
                           ^
SyntaxError: invalid syntax

The problem seems to be in the metaclass declaration. Might be I have to add a "compilation flag" when I call the python interpreter? Some good news?! :) Thx

Edit
Report

1 Answer

1

Yeah, this is Python3 library http://code.google.com/p/modgrammar/source/browse/setup.py#32

Python2x doesn't support class Grammar(metaclass=GrammarClass)

answered 2011-08-15T12:42:40.157

Your Answer