/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2023 TechMahindra Ltd
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
grammar CpsPath ;
-cpsPath: (cpsPathWithSingleLeafCondition | cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions) ancestorAxis? ;
+cpsPath : ( prefix | descendant | incorrectPrefix ) multipleLeafConditions? textFunctionCondition? containsFunctionCondition? ancestorAxis? invalidPostFix?;
-ancestorAxis: SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
+ancestorAxis : SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
-ancestorPath: yangElement (SLASH yangElement)* ;
+ancestorPath : yangElement ( SLASH yangElement)* ;
-cpsPathWithSingleLeafCondition: prefix singleValueCondition postfix? ;
+textFunctionCondition : SLASH leafName OB KW_TEXT_FUNCTION EQ StringLiteral CB ;
-/*
-No need to ditinguish between cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions really!
-See https://jira.onap.org/browse/CPS-436
-*/
+containsFunctionCondition : OB KW_CONTAINS_FUNCTION OP AT leafName COMMA StringLiteral CP CB ;
-cpsPathWithDescendant: descendant ;
+parent : ( SLASH yangElement)* ;
-cpsPathWithDescendantAndLeafConditions: descendant multipleValueConditions ;
+prefix : parent SLASH containerName ;
-descendant: SLASH prefix ;
+descendant : SLASH prefix ;
-prefix: (SLASH yangElement)* SLASH containerName ;
+incorrectPrefix : SLASH SLASH SLASH+ ;
-postfix: (SLASH yangElement)+ ;
+yangElement : containerName listElementRef? ;
-yangElement: containerName listElementRef? ;
+containerName : QName ;
-containerName: QName ;
+listElementRef : OB leafCondition ( booleanOperators leafCondition)* CB ;
-listElementRef: multipleValueConditions ;
+multipleLeafConditions : OB leafCondition ( booleanOperators leafCondition)* CB ;
-singleValueCondition: '[' leafCondition ']' ;
+leafCondition : AT leafName EQ ( IntegerLiteral | StringLiteral) ;
-multipleValueConditions: '[' leafCondition (' and ' leafCondition)* ']' ;
+leafName : QName ;
-leafCondition: '@' leafName '=' (IntegerLiteral | StringLiteral ) ;
+booleanOperators : ( KW_AND | KW_OR ) ;
-//To Confirm: defintion of Lefname with external xPath grammar
-leafName: QName ;
+invalidPostFix : (AT | CB | COLONCOLON | EQ ).+ ;
/*
* Lexer Rules
- * Most of the lexer rules below are 'imporetd' from
+ * Most of the lexer rules below are inspired by
* https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
*/
-SLASH : '/';
+AT : '@' ;
+CB : ']' ;
COLONCOLON : '::' ;
+EQ : '=' ;
+OB : '[' ;
+SLASH : '/' ;
+COMMA : ',' ;
+OP : '(' ;
+CP : ')' ;
// KEYWORDS
KW_ANCESTOR : 'ancestor' ;
+KW_AND : 'and' ;
+KW_TEXT_FUNCTION: 'text()' ;
+KW_OR : 'or' ;
+KW_CONTAINS_FUNCTION: 'contains' ;
IntegerLiteral : FragDigits ;
// Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
fragment FragEscapeQuot : '""' ;
-fragment FragEscapeApos : '\'';
+fragment FragEscapeApos : '\'' ;
fragment FragDigits : [0-9]+ ;
QName : FragQName ;
| '\u00B7' | '\u0300'..'\u036F'
| '\u203F'..'\u2040'
;
-fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
+fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
// https://www.w3.org/TR/REC-xml/#NT-Char
| '\u0020'..'\ud7ff'
| '\ue000'..'\ufffd'
| '\u{10000}'..'\u{10ffff}'
- ;
+ ;
// Skip all Whitespace
Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;