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