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 ?
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 likemodel[0]
or alternatively you can makea, b = parser.parse(text)