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 comparativeOperators ( IntegerLiteral | StringLiteral) ;
54 booleanOperators : ( KW_AND | KW_OR ) ;
56 comparativeOperators : ( EQ | GT | LT | GE | LE ) ;
58 invalidPostFix : (AT | CB | COLONCOLON | comparativeOperators ).+ ;
62 * Most of the lexer rules below are inspired by
63 * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
82 KW_ANCESTOR : 'ancestor' ;
84 KW_TEXT_FUNCTION: 'text()' ;
86 KW_CONTAINS_FUNCTION: 'contains' ;
88 IntegerLiteral : FragDigits ;
89 // Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
90 DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
91 DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
92 StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
93 fragment FragEscapeQuot : '""' ;
94 fragment FragEscapeApos : '\'' ;
95 fragment FragDigits : [0-9]+ ;
98 NCName : FragmentNCName ;
99 fragment FragQName : FragPrefixedName | FragUnprefixedName ;
100 fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
101 fragment FragUnprefixedName : FragLocalPart ;
102 fragment FragPrefix : FragmentNCName ;
103 fragment FragLocalPart : FragmentNCName ;
104 fragment FragNCNameStartChar
119 | '\u{10000}'..'\u{EFFFF}'
121 fragment FragNCNameChar
122 : FragNCNameStartChar | '-' | '.' | '0'..'9'
123 | '\u00B7' | '\u0300'..'\u036F'
126 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
128 // https://www.w3.org/TR/REC-xml/#NT-Char
130 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
133 | '\u{10000}'..'\u{10ffff}'
136 // Skip all Whitespace
137 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
139 // handle characters which failed to match any other token (otherwise Antlr will ignore them)