summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2020-11-06 22:25:12 -0300
committerSoniEx2 <endermoneymod@gmail.com>2020-11-06 22:25:12 -0300
commitff3628c36eab5ec19ab850e9126a951f5c203568 (patch)
treed05f7bf27b0141f779a013bcfa22a16543b33c18
parent436939628ff1c5bbc37d5c91c4a7c68d83f12f49 (diff)
Fix subvalue not parsing predicates
-rw-r--r--abdl/_parser.py2
-rw-r--r--setup.py2
-rw-r--r--testing/test_abdl.py16
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):