Fix Delete uses case with '/' in path
[cps.git] / cps-path-parser / src / main / antlr4 / org / onap / cps / cpspath / parser / antlr4 / CpsPath.g4
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 grammar CpsPath ;
22
23 cpsPath : ( prefix | descendant | incorrectPrefix ) multipleLeafConditions? textFunctionCondition? ancestorAxis? invalidPostFix?;
24
25 ancestorAxis : SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
26
27 ancestorPath : yangElement ( SLASH yangElement)* ;
28
29 textFunctionCondition : SLASH leafName OB KW_TEXT_FUNCTION EQ StringLiteral CB ;
30
31 parent : ( SLASH yangElement)* ;
32
33 prefix : parent SLASH containerName ;
34
35 descendant : SLASH prefix ;
36
37 incorrectPrefix : SLASH SLASH SLASH+ ;
38
39 yangElement : containerName listElementRef? ;
40
41 containerName : QName ;
42
43 listElementRef :  OB leafCondition ( KW_AND leafCondition)* CB ;
44
45 multipleLeafConditions : OB leafCondition ( KW_AND leafCondition)* CB ;
46
47 leafCondition : AT leafName EQ ( IntegerLiteral | StringLiteral) ;
48
49 leafName : QName ;
50
51 invalidPostFix : (AT | CB | COLONCOLON | EQ ).+ ;
52
53 /*
54  * Lexer Rules
55  * Most of the lexer rules below are inspired by
56  * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
57  */
58
59 AT : '@' ;
60 CB : ']' ;
61 COLONCOLON : '::' ;
62 EQ : '=' ;
63 OB : '[' ;
64 SLASH : '/' ;
65
66 // KEYWORDS
67
68 KW_ANCESTOR : 'ancestor' ;
69 KW_AND : 'and' ;
70 KW_TEXT_FUNCTION: 'text()' ;
71
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]+ ;
80
81 QName  : FragQName ;
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
89   :  'A'..'Z'
90   |  '_'
91   | 'a'..'z'
92   | '\u00C0'..'\u00D6'
93   | '\u00D8'..'\u00F6'
94   | '\u00F8'..'\u02FF'
95   | '\u0370'..'\u037D'
96   | '\u037F'..'\u1FFF'
97   | '\u200C'..'\u200D'
98   | '\u2070'..'\u218F'
99   | '\u2C00'..'\u2FEF'
100   | '\u3001'..'\uD7FF'
101   | '\uF900'..'\uFDCF'
102   | '\uFDF0'..'\uFFFD'
103   | '\u{10000}'..'\u{EFFFF}'
104   ;
105 fragment FragNCNameChar
106   :  FragNCNameStartChar | '-' | '.' | '0'..'9'
107   |  '\u00B7' | '\u0300'..'\u036F'
108   |  '\u203F'..'\u2040'
109   ;
110 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
111
112 // https://www.w3.org/TR/REC-xml/#NT-Char
113
114 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
115   | '\u0020'..'\ud7ff'
116   | '\ue000'..'\ufffd'
117   | '\u{10000}'..'\u{10ffff}'
118   ;
119
120 // Skip all Whitespace
121 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
122
123 // handle characters which failed to match any other token (otherwise Antlr will ignore them)
124 ErrorCharacter : . ;