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 parent : ( SLASH yangElement)* ;
33 prefix : parent SLASH containerName ;
35 descendant : SLASH prefix ;
37 incorrectPrefix : SLASH SLASH SLASH+ ;
39 yangElement : containerName listElementRef? ;
41 containerName : QName ;
43 listElementRef : OB leafCondition ( KW_AND leafCondition)* CB ;
45 multipleLeafConditions : OB leafCondition ( KW_AND leafCondition)* CB ;
47 leafCondition : AT leafName EQ ( IntegerLiteral | StringLiteral) ;
51 invalidPostFix : (AT | CB | COLONCOLON | EQ ).+ ;
55 * Most of the lexer rules below are inspired by
56 * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
68 KW_ANCESTOR : 'ancestor' ;
70 KW_TEXT_FUNCTION: 'text()' ;
72 IntegerLiteral : FragDigits ;
73 // Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
74 DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
75 DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
76 StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
77 fragment FragEscapeQuot : '""' ;
78 fragment FragEscapeApos : '\'' ;
79 fragment FragDigits : [0-9]+ ;
82 NCName : FragmentNCName ;
83 fragment FragQName : FragPrefixedName | FragUnprefixedName ;
84 fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
85 fragment FragUnprefixedName : FragLocalPart ;
86 fragment FragPrefix : FragmentNCName ;
87 fragment FragLocalPart : FragmentNCName ;
88 fragment FragNCNameStartChar
103 | '\u{10000}'..'\u{EFFFF}'
105 fragment FragNCNameChar
106 : FragNCNameStartChar | '-' | '.' | '0'..'9'
107 | '\u00B7' | '\u0300'..'\u036F'
110 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
112 // https://www.w3.org/TR/REC-xml/#NT-Char
114 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
117 | '\u{10000}'..'\u{10ffff}'
120 // Skip all Whitespace
121 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
123 // handle characters which failed to match any other token (otherwise Antlr will ignore them)