2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 Nordix Foundation
4 * Modifications Copyright (C) 2023 TechMahindra Ltd
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
24 cpsPath : ( prefix | descendant | incorrectPrefix ) multipleLeafConditions? textFunctionCondition? containsFunctionCondition? ancestorAxis? invalidPostFix?;
26 ancestorAxis : SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
28 ancestorPath : yangElement ( SLASH yangElement)* ;
30 textFunctionCondition : SLASH leafName OB KW_TEXT_FUNCTION EQ StringLiteral CB ;
32 containsFunctionCondition : OB KW_CONTAINS_FUNCTION OP AT leafName COMMA StringLiteral CP CB ;
34 parent : ( SLASH yangElement)* ;
36 prefix : parent SLASH containerName ;
38 descendant : SLASH prefix ;
40 incorrectPrefix : SLASH SLASH SLASH+ ;
42 yangElement : containerName listElementRef? ;
44 containerName : QName ;
46 listElementRef : OB leafCondition ( booleanOperators leafCondition)* CB ;
48 multipleLeafConditions : OB leafCondition ( booleanOperators leafCondition)* CB ;
50 leafCondition : AT leafName EQ ( IntegerLiteral | StringLiteral) ;
54 booleanOperators : ( KW_AND | KW_OR ) ;
56 invalidPostFix : (AT | CB | COLONCOLON | EQ ).+ ;
60 * Most of the lexer rules below are inspired by
61 * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
76 KW_ANCESTOR : 'ancestor' ;
78 KW_TEXT_FUNCTION: 'text()' ;
80 KW_CONTAINS_FUNCTION: 'contains' ;
82 IntegerLiteral : FragDigits ;
83 // Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
84 DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
85 DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
86 StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
87 fragment FragEscapeQuot : '""' ;
88 fragment FragEscapeApos : '\'' ;
89 fragment FragDigits : [0-9]+ ;
92 NCName : FragmentNCName ;
93 fragment FragQName : FragPrefixedName | FragUnprefixedName ;
94 fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
95 fragment FragUnprefixedName : FragLocalPart ;
96 fragment FragPrefix : FragmentNCName ;
97 fragment FragLocalPart : FragmentNCName ;
98 fragment FragNCNameStartChar
113 | '\u{10000}'..'\u{EFFFF}'
115 fragment FragNCNameChar
116 : FragNCNameStartChar | '-' | '.' | '0'..'9'
117 | '\u00B7' | '\u0300'..'\u036F'
120 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
122 // https://www.w3.org/TR/REC-xml/#NT-Char
124 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
127 | '\u{10000}'..'\u{10ffff}'
130 // Skip all Whitespace
131 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
133 // handle characters which failed to match any other token (otherwise Antlr will ignore them)