Fix XPathExpr parsing 31/81031/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Mar 2019 12:04:46 +0000 (13:04 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Mar 2019 14:29:00 +0000 (15:29 +0100)
The parser mistakenly treated filter/path concatenation as a binary
expression, which lead to its inability to parse leafrefs, which
contain such a concatenation in predicates.

This fixes the parser to correctly use XPathExpr in this case.

Change-Id: Ica1ac3ee7d099273dccdf8565da2a69d9f11c046
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-xpath-api/src/main/java/org/opendaylight/yangtools/yang/xpath/api/YangPathExpr.java
yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/AntlrXPathParser.java
yang/yang-xpath-impl/src/test/java/org/opendaylight/yangtools/yang/xpath/impl/XPathParserTest.java

index d695d2ec41eb4b759a5b5512f52eb8483ade4aaa..47577c8b6938ae8e76ef3f6a9723d942d4a7c8c7 100644 (file)
@@ -44,7 +44,7 @@ public class YangPathExpr implements YangExpr {
         return new YangPathExpr(filterExpr);
     }
 
-    public static YangExpr of(final YangExpr expr, final YangLocationPath locationPath) {
+    public static YangPathExpr of(final YangExpr expr, final YangLocationPath locationPath) {
         return new WithLocation(expr, locationPath);
     }
 
index 1366bbe334012b186647af689f5d018a12ece3fe..2c7f506cc1aff934c256a727104cb917e0e45cc8 100644 (file)
@@ -56,6 +56,7 @@ import org.opendaylight.yangtools.yang.xpath.api.YangNaryExpr;
 import org.opendaylight.yangtools.yang.xpath.api.YangNaryOperator;
 import org.opendaylight.yangtools.yang.xpath.api.YangNegateExpr;
 import org.opendaylight.yangtools.yang.xpath.api.YangNumberExpr;
+import org.opendaylight.yangtools.yang.xpath.api.YangPathExpr;
 import org.opendaylight.yangtools.yang.xpath.api.YangVariableReferenceExpr;
 import org.opendaylight.yangtools.yang.xpath.api.YangXPathAxis;
 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression;
@@ -267,10 +268,9 @@ final class AntlrXPathParser implements YangXPathParser {
         }
 
         verifyChildCount(expr, 3);
-
-        // FIXME: this actually is a concatenation
-        return parseOperator(expr.getChild(1)).exprWith(filter,
-            parseRelativeLocationPath(getChild(expr, RelativeLocationPathContext.class, 2)));
+        final Deque<Step> steps = parseLocationPathSteps(getChild(expr, RelativeLocationPathContext.class, 2));
+        parseStepShorthand(expr.getChild(1)).ifPresent(steps::addFirst);
+        return YangPathExpr.of(filter, YangLocationPath.of(false, steps));
     }
 
     private YangExpr parsePredicate(final PredicateContext expr) {
index 3fe300bd0fd969b9ef6f2207719f5005cbe57fba..3b363d3eb779a1fc7bd5b558b020020924ce1086 100644 (file)
@@ -39,6 +39,8 @@ public class XPathParserTest {
 
     @Test
     public void testSmoke() throws XPathExpressionException {
+        parseExpr("../a[foo = current()/foo]");
+
         parseExpr("3 + 5");
         parseExpr("/a/b");
         parseExpr("a/b");