From d326bb018032cb78484a8939df6c3b863940fc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 28 Feb 2022 13:59:41 +0100 Subject: [PATCH] Add cfg.parse_and_evaluate() --- rust2rpm/cfg.py | 4 ++++ rust2rpm/tests/test_cfg.py | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rust2rpm/cfg.py b/rust2rpm/cfg.py index efccf87..9385b20 100644 --- a/rust2rpm/cfg.py +++ b/rust2rpm/cfg.py @@ -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]) diff --git a/rust2rpm/tests/test_cfg.py b/rust2rpm/tests/test_cfg.py index ea89b6b..4a86abb 100644 --- a/rust2rpm/tests/test_cfg.py +++ b/rust2rpm/tests/test_cfg.py @@ -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