0

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 Answer 1

0

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.