Add cfg.parse_and_evaluate()
This commit is contained in:
parent
61e7b5fc7a
commit
d326bb0180
2 changed files with 5 additions and 2 deletions
|
@ -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])
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue