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
|
return x
|
||||||
case _:
|
case _:
|
||||||
raise ValueError
|
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):
|
def test_expressions(expr, expected):
|
||||||
parsed = cfg.cfg_grammar().parse_string(expr)
|
value = cfg.parse_and_evaluate(expr)
|
||||||
value = cfg.evaluate(parsed[0])
|
|
||||||
assert value == expected
|
assert value == expected
|
||||||
|
|
Loading…
Reference in a new issue