diff --git a/requirements.txt b/requirements.txt index 6789459..bba8f10 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ jinja2 +pyparsing requests tqdm diff --git a/rust2rpm/cfg.py b/rust2rpm/cfg.py index 5e3d10b..79567e6 100644 --- a/rust2rpm/cfg.py +++ b/rust2rpm/cfg.py @@ -5,9 +5,9 @@ import platform import sys import pyparsing as pp -from pyparsing.exceptions import ParseException +from pyparsing import ParseException -pp.ParserElement.enable_packrat() +pp.ParserElement.enablePackrat() # ConfigurationPredicate : # ConfigurationOption @@ -33,14 +33,14 @@ pp.ParserElement.enable_packrat() IDENT_CHARS = pp.alphas + '_', pp.alphanums + '_' def _call(word, arg): - return pp.Group(pp.Literal(word) + pp.Suppress('(') + arg + pp.Suppress(')'), aslist=True) + return pp.Group(pp.Literal(word) + pp.Suppress('(') + arg + pp.Suppress(')')) @functools.cache def cfg_grammar(): pred = pp.Forward() ident = pp.Word(IDENT_CHARS[0], IDENT_CHARS[1]) - option = pp.Group(ident + pp.Optional(pp.Suppress('=') + pp.quotedString), aslist=True) + option = pp.Group(ident + pp.Optional(pp.Suppress('=') + pp.quotedString)) not_ = _call('not', pred) @@ -96,6 +96,8 @@ def evaluate_variable(name): def evaluate(expr, nested=False): # print(f'evaluate: {expr}') + if hasattr(expr, 'asList'): + expr = expr.asList() # compat with pyparsing 2.7.x match expr: case ['cfg', expr] if not nested: return evaluate(expr, True) @@ -116,5 +118,5 @@ def evaluate(expr, nested=False): raise ValueError def parse_and_evaluate(expr): - parsed = cfg_grammar().parse_string(expr) + parsed = cfg_grammar().parseString(expr) return evaluate(parsed[0]) diff --git a/rust2rpm/tests/test_cfg.py b/rust2rpm/tests/test_cfg.py index 4a86abb..949b529 100644 --- a/rust2rpm/tests/test_cfg.py +++ b/rust2rpm/tests/test_cfg.py @@ -5,7 +5,7 @@ from rust2rpm import cfg def test_pyparsing_run_tests(): g = cfg.cfg_grammar() - g.run_tests("""\ + g.runTests("""\ cfg(target_os = "macos") cfg(any(foo, bar)) cfg(all(unix, target_pointer_width = "32"))