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? 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 parent : ( SLASH yangElement)* ;
34 prefix : parent SLASH containerName ;
36 descendant : SLASH prefix ;
38 incorrectPrefix : SLASH SLASH SLASH+ ;
40 yangElement : containerName listElementRef? ;
42 containerName : QName ;
44 listElementRef : OB leafCondition ( booleanOperators leafCondition)* CB ;
46 multipleLeafConditions : OB leafCondition ( booleanOperators leafCondition)* CB ;
48 leafCondition : AT leafName EQ ( IntegerLiteral | StringLiteral) ;
52 booleanOperators : ( KW_AND | KW_OR ) ;
54 invalidPostFix : (AT | CB | COLONCOLON | EQ ).+ ;
58 * Most of the lexer rules below are inspired by
59 * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
71 KW_ANCESTOR : 'ancestor' ;
73 KW_TEXT_FUNCTION: 'text()' ;
76 IntegerLiteral : FragDigits ;
77 // Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
78 DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
79 DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
80 StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
81 fragment FragEscapeQuot : '""' ;
82 fragment FragEscapeApos : '\'' ;
83 fragment FragDigits : [0-9]+ ;
86 NCName : FragmentNCName ;
87 fragment FragQName : FragPrefixedName | FragUnprefixedName ;
88 fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
89 fragment FragUnprefixedName : FragLocalPart ;
90 fragment FragPrefix : FragmentNCName ;
91 fragment FragLocalPart : FragmentNCName ;
92 fragment FragNCNameStartChar
107 | '\u{10000}'..'\u{EFFFF}'
109 fragment FragNCNameChar
110 : FragNCNameStartChar | '-' | '.' | '0'..'9'
111 | '\u00B7' | '\u0300'..'\u036F'
114 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
116 // https://www.w3.org/TR/REC-xml/#NT-Char
118 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
121 | '\u{10000}'..'\u{10ffff}'
124 // Skip all Whitespace
125 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
127 // handle characters which failed to match any other token (otherwise Antlr will ignore them)