Editing of Nordix Licenses to ONAP guidelines
[cps.git] / cps-path-parser / src / main / antlr4 / org / onap / cps / cpspath / parser / antlr4 / CpsPath.g4
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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: (cpsPathWithSingleLeafCondition | cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions) ancestorAxis? ;
24
25 ancestorAxis: SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
26
27 ancestorPath: yangElement (SLASH yangElement)* ;
28
29 cpsPathWithSingleLeafCondition: prefix singleValueCondition postfix? ;
30
31 /*
32 No need to ditinguish between cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions really!
33 See https://jira.onap.org/browse/CPS-436
34 */
35
36 cpsPathWithDescendant: descendant ;
37
38 cpsPathWithDescendantAndLeafConditions: descendant multipleValueConditions ;
39
40 descendant: SLASH prefix ;
41
42 prefix: (SLASH yangElement)* SLASH containerName ;
43
44 postfix: (SLASH yangElement)+ ;
45
46 yangElement: containerName listElementRef? ;
47
48 containerName: QName ;
49
50 listElementRef: multipleValueConditions ;
51
52 singleValueCondition: '[' leafCondition ']' ;
53
54 multipleValueConditions: '[' leafCondition (' and ' leafCondition)* ']' ;
55
56 leafCondition: '@' leafName '=' (IntegerLiteral | StringLiteral ) ;
57
58 //To Confirm: defintion of Lefname with external xPath grammar
59 leafName: QName ;
60
61 /*
62  * Lexer Rules
63  * Most of the lexer rules below are 'imporetd' from
64  * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
65  */
66
67 SLASH : '/';
68 COLONCOLON : '::' ;
69
70 // KEYWORDS
71
72 KW_ANCESTOR : 'ancestor' ;
73
74 IntegerLiteral : FragDigits ;
75 // Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
76 DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
77 DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
78 StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
79 fragment FragEscapeQuot : '""' ;
80 fragment FragEscapeApos : '\'';
81 fragment FragDigits : [0-9]+ ;
82
83 QName  : FragQName ;
84 NCName : FragmentNCName ;
85 fragment FragQName : FragPrefixedName | FragUnprefixedName ;
86 fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
87 fragment FragUnprefixedName : FragLocalPart ;
88 fragment FragPrefix : FragmentNCName ;
89 fragment FragLocalPart : FragmentNCName ;
90 fragment FragNCNameStartChar
91   :  'A'..'Z'
92   |  '_'
93   | 'a'..'z'
94   | '\u00C0'..'\u00D6'
95   | '\u00D8'..'\u00F6'
96   | '\u00F8'..'\u02FF'
97   | '\u0370'..'\u037D'
98   | '\u037F'..'\u1FFF'
99   | '\u200C'..'\u200D'
100   | '\u2070'..'\u218F'
101   | '\u2C00'..'\u2FEF'
102   | '\u3001'..'\uD7FF'
103   | '\uF900'..'\uFDCF'
104   | '\uFDF0'..'\uFFFD'
105   | '\u{10000}'..'\u{EFFFF}'
106   ;
107 fragment FragNCNameChar
108   :  FragNCNameStartChar | '-' | '.' | '0'..'9'
109   |  '\u00B7' | '\u0300'..'\u036F'
110   |  '\u203F'..'\u2040'
111   ;
112 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar*  ;
113
114 // https://www.w3.org/TR/REC-xml/#NT-Char
115
116 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
117   | '\u0020'..'\ud7ff'
118   | '\ue000'..'\ufffd'
119   | '\u{10000}'..'\u{10ffff}'
120  ;
121
122 // Skip all Whitespace
123 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
124
125 // handle characters which failed to match any other token (otherwise Antlr will ignore them)
126 ErrorCharacter : . ;