From ff3628c36eab5ec19ab850e9126a951f5c203568 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Fri, 6 Nov 2020 22:25:12 -0300 Subject: Fix subvalue not parsing predicates --- abdl/_parser.py | 2 +- setup.py | 2 +- testing/test_abdl.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/abdl/_parser.py b/abdl/_parser.py index a8b17ce..3c38ab2 100644 --- a/abdl/_parser.py +++ b/abdl/_parser.py @@ -103,7 +103,7 @@ def _build_syntax(): + Empty().setParseAction(_vm.End.action)) # multiple value matching - valuesubtree = (Suppress("(") + Group(subtree) + valuesubtree = (Suppress("(") + Group(type_[...] + subtree) + (Suppress(")") | unexpected_token | unexpected_end) + Optional("?", default="")) valuesubtree.setParseAction(_vm.ValueSubtree.action) diff --git a/setup.py b/setup.py index 8a4e81a..15f07b8 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,3 @@ import setuptools -setuptools.setup(name="gan0f74bd87a23b515b45da7e6f5d9cc82380443dab", version="2.2.0", packages=["abdl"], install_requires=["pyparsing >= 2.4.2"]) +setuptools.setup(name="gan0f74bd87a23b515b45da7e6f5d9cc82380443dab", version="2.2.1", packages=["abdl"], install_requires=["pyparsing >= 2.4.2"]) diff --git a/testing/test_abdl.py b/testing/test_abdl.py index 79a0edf..4b151b0 100644 --- a/testing/test_abdl.py +++ b/testing/test_abdl.py @@ -269,6 +269,22 @@ def test_optional_value_subtree(): matcher = pat.match({'bar': 2}) assert list(matcher) == [{'bar': ('bar', 2)}] +def test_predicate_on_subvalue(): + # make sure predicates on subvalues compile + pat = abdl.compile("(:?$dict->foo'foo'?)?(->bar'bar')", dict(dict=dict)) + matcher = pat.match({'foo': 1, 'bar': 2}) + assert list(matcher) == [{'foo': ('foo', 1), 'bar': ('bar', 2)}] + matcher = pat.match({'bar': 2}) + assert list(matcher) == [{'bar': ('bar', 2)}] + try: + # this should fail on the 'bar' match + next(pat.match([]), None) + except abdl.exceptions.ValidationError: + # but we don't really have a way of checking which part failed + pass + else: + assert False + # FIXME #@hypothesis.given(objtree, st.text()) #def test_exhaustive(foo, pat): -- cgit 1.4.1