[Cps Path Parser] Remove unneeded validation in grammar 83/138883/2
authordanielhanrahan <daniel.hanrahan@est.tech>
Sat, 31 Aug 2024 21:06:12 +0000 (22:06 +0100)
committerDaniel Hanrahan <daniel.hanrahan@est.tech>
Wed, 4 Sep 2024 14:58:01 +0000 (14:58 +0000)
The invalid prefix/postfix is not needed; existing tests show
that PathParsingException is thrown in for invalid paths.

Issue-ID: CPS-2365
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I202f0ca0bc5eb768fc3af711180405882dafc22d

cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4
cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java

index 3aef120..be8d968 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation
+ *  Copyright (C) 2021-2024 Nordix Foundation
  *  Modifications Copyright (C) 2023 TechMahindra Ltd
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,7 @@
 
 grammar CpsPath ;
 
-cpsPath : ( prefix | descendant | incorrectPrefix ) multipleLeafConditions? textFunctionCondition? containsFunctionCondition? ancestorAxis? invalidPostFix?;
+cpsPath : ( prefix | descendant ) multipleLeafConditions? textFunctionCondition? containsFunctionCondition? ancestorAxis? EOF ;
 
 ancestorAxis : SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
 
@@ -43,8 +43,6 @@ prefix : parent SLASH containerName ;
 
 descendant : SLASH prefix ;
 
-incorrectPrefix : SLASH SLASH SLASH+ ;
-
 yangElement : containerName listElementRef? ;
 
 containerName : QName ;
@@ -61,8 +59,6 @@ booleanOperators : ( KW_AND | KW_OR ) ;
 
 comparativeOperators : ( EQ | GT | LT | GE | LE ) ;
 
-invalidPostFix : (AT | CB | COLONCOLON | comparativeOperators ).+ ;
-
 /*
  * Lexer Rules
  * Most of the lexer rules below are inspired by
index 0bb0923..66964bb 100644 (file)
@@ -29,7 +29,6 @@ import org.onap.cps.cpspath.parser.antlr4.CpsPathBaseListener;
 import org.onap.cps.cpspath.parser.antlr4.CpsPathParser;
 import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.AncestorAxisContext;
 import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.DescendantContext;
-import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.IncorrectPrefixContext;
 import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.LeafConditionContext;
 import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.MultipleLeafConditionsContext;
 import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.PrefixContext;
@@ -57,11 +56,6 @@ public class CpsPathBuilder extends CpsPathBaseListener {
 
     private final List<String> comparativeOperators = new ArrayList<>();
 
-    @Override
-    public void exitInvalidPostFix(final CpsPathParser.InvalidPostFixContext ctx) {
-        throw new PathParsingException(ctx.getText());
-    }
-
     @Override
     public void exitPrefix(final PrefixContext ctx) {
         cpsPathQuery.setXpathPrefix(normalizedXpathBuilder.toString());
@@ -72,11 +66,6 @@ public class CpsPathBuilder extends CpsPathBaseListener {
         cpsPathQuery.setNormalizedParentPath(normalizedXpathBuilder.toString());
     }
 
-    @Override
-    public void exitIncorrectPrefix(final IncorrectPrefixContext ctx) {
-        throw new PathParsingException("CPS path can only start with one or two slashes (/)");
-    }
-
     @Override
     public void exitLeafCondition(final LeafConditionContext ctx) {
         final Object comparisonValue;