AttributeError: 'tuple' object has no attribute 'asjson'

179 views Asked by At

When I would like to test my EBNF grammar, I have the error :

AttributeError: 'tuple' object has no attribute 'asjson'

Code :

if not filename or filename == '-':
    text = sys.stdin.read()
else:
    with open(filename) as f:
        text = f.read()

grammarname = 'grammars/CTEST.ebnf'
grammarData = open(grammarname).read()
parser = tatsu.compile(grammarData, asmodel=True)

model = parser.parse(text)
print()
print('# MODEL TYPE IS:', type(model).__name__)
print(json.dumps(model.asjson(), indent=4))
print()

How can i verify my grammar file ?

1

There are 1 answers

0
canbax On

It totally depends on what parser.parse returns. It might return multiple values.

For example: return a_variable, another_variable is a valid syntax in python. If it returns multiple values, they come as a tuple. You should read them like model[0] or alternatively you can make a, b = parser.parse(text)