2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
23 cpsPath : ( prefix | descendant | incorrectPrefix ) multipleLeafConditions? textFunctionCondition? ancestorAxis? invalidPostFix?;
25 ancestorAxis : SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
27 ancestorPath : yangElement ( SLASH yangElement)* ;
29 textFunctionCondition : SLASH leafName OB KW_TEXT_FUNCTION EQ StringLiteral CB ;
31 prefix : ( SLASH yangElement)* SLASH containerName ;
33 descendant : SLASH prefix ;
35 incorrectPrefix : SLASH SLASH SLASH+ ;
37 yangElement : containerName listElementRef? ;
39 containerName : QName ;
41 listElementRef : OB leafCondition ( KW_AND leafCondition)* CB ;
43 multipleLeafConditions : OB leafCondition ( KW_AND leafCondition)* CB ;
45 leafCondition : AT leafName EQ ( IntegerLiteral | StringLiteral) ;
49 invalidPostFix : (AT | CB | COLONCOLON | EQ ).+ ;
53 * Most of the lexer rules below are inspired by
54 * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
66 KW_ANCESTOR : 'ancestor' ;
68 KW_TEXT_FUNCTION: 'text()' ;
70 IntegerLiteral : FragDigits ;
71 // Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
72 DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
73 DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
74 StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
75 fragment FragEscapeQuot : '""' ;
76 fragment FragEscapeApos : '\'' ;
77 fragment FragDigits : [0-9]+ ;
80 NCName : FragmentNCName ;
81 fragment FragQName : FragPrefixedName | FragUnprefixedName ;
82 fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
83 fragment FragUnprefixedName : FragLocalPart ;
84 fragment FragPrefix : FragmentNCName ;
85 fragment FragLocalPart : FragmentNCName ;
86 fragment FragNCNameStartChar
101 | '\u{10000}'..'\u{EFFFF}'
103 fragment FragNCNameChar
104 : FragNCNameStartChar | '-' | '.' | '0'..'9'
105 | '\u00B7' | '\u0300'..'\u036F'
108 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
110 // https://www.w3.org/TR/REC-xml/#NT-Char
112 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
115 | '\u{10000}'..'\u{10ffff}'
118 // Skip all Whitespace
119 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
121 // handle characters which failed to match any other token (otherwise Antlr will ignore them)