From cfc500b4192c356a3499040ebb714ec0b5f26584 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Thu, 3 Jun 2021 16:05:08 +0100 Subject: Improve error handling on unexpected 'postfix' Issue-ID: CPS-450 Signed-off-by: ToineSiebelink Change-Id: Ia8be460f4235f7f0c24498f861dbe42137111772 --- .../src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4 | 4 +++- .../src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'cps-path-parser/src/main') diff --git a/cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4 b/cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4 index 86095459ee..a4fd58e9c0 100644 --- a/cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4 +++ b/cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4 @@ -25,7 +25,7 @@ ancestorAxis: SLASH KW_ANCESTOR COLONCOLON ancestorPath ; ancestorPath: yangElement (SLASH yangElement)* ; -cpsPathWithSingleLeafCondition: prefix singleValueCondition ; +cpsPathWithSingleLeafCondition: prefix singleValueCondition postfix? ; /* No need to ditinguish between cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions really! @@ -40,6 +40,8 @@ descendant: SLASH prefix ; prefix: (SLASH yangElement)* SLASH containerName ; +postfix: (SLASH yangElement)+ ; + yangElement: containerName listElementRef? ; containerName: QName ; diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java index a67cbeb870..afe01f644c 100644 --- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java +++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java @@ -28,6 +28,7 @@ import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.CpsPathWithDescendantCon import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.CpsPathWithSingleLeafConditionContext; import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.LeafConditionContext; import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.MultipleValueConditionsContext; +import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.PostfixContext; import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.PrefixContext; import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.SingleValueConditionContext; @@ -42,6 +43,11 @@ public class CpsPathBuilder extends CpsPathBaseListener { cpsPathQuery.setXpathPrefix(ctx.getText()); } + @Override + public void exitPostfix(final PostfixContext ctx) { + throw new IllegalStateException(String.format("Unsupported postfix %s encountered in CpsPath.", ctx.getText())); + } + @Override public void exitLeafCondition(final LeafConditionContext ctx) { Object comparisonValue = null; -- cgit 1.2.3-korg