Add cfg.parse_and_evaluate()

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-02-28 13:59:41 +01:00
parent 61e7b5fc7a
commit d326bb0180
2 changed files with 5 additions and 2 deletions

View file

@ -111,3 +111,7 @@ def evaluate(expr, nested=False):
return x
case _:
raise ValueError
def parse_and_evaluate(expr):
parsed = cfg_grammar().parse_string(expr)
return evaluate(parsed[0])

View file

@ -55,6 +55,5 @@ def test_pyparsing_run_tests():
])
def test_expressions(expr, expected):
parsed = cfg.cfg_grammar().parse_string(expr)
value = cfg.evaluate(parsed[0])
value = cfg.parse_and_evaluate(expr)
assert value == expected