a4fd58e9c00094a0c4b6f6c4df32bf73b6578f7e
[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  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 grammar CpsPath ;
21
22 cpsPath: (cpsPathWithSingleLeafCondition | cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions) ancestorAxis? ;
23
24 ancestorAxis: SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
25
26 ancestorPath: yangElement (SLASH yangElement)* ;
27
28 cpsPathWithSingleLeafCondition: prefix singleValueCondition postfix? ;
29
30 /*
31 No need to ditinguish between cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions really!
32 See https://jira.onap.org/browse/CPS-436
33 */
34
35 cpsPathWithDescendant: descendant ;
36
37 cpsPathWithDescendantAndLeafConditions: descendant multipleValueConditions ;
38
39 descendant: SLASH prefix ;
40
41 prefix: (SLASH yangElement)* SLASH containerName ;
42
43 postfix: (SLASH yangElement)+ ;
44
45 yangElement: containerName listElementRef? ;
46
47 containerName: QName ;
48
49 listElementRef: multipleValueConditions ;
50
51 singleValueCondition: '[' leafCondition ']' ;
52
53 multipleValueConditions: '[' leafCondition (' and ' leafCondition)* ']' ;
54
55 leafCondition: '@' leafName '=' (IntegerLiteral | StringLiteral ) ;
56
57 //To Confirm: defintion of Lefname with external xPath grammar
58 leafName: QName ;
59
60 /*
61  * Lexer Rules
62  * Most of the lexer rules below are 'imporetd' from
63  * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
64  */
65
66 SLASH : '/';
67 COLONCOLON : '::' ;
68
69 // KEYWORDS
70
71 KW_ANCESTOR : 'ancestor' ;
72
73 IntegerLiteral : FragDigits ;
74 // Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
75 DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
76 DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
77 StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
78 fragment FragEscapeQuot : '""' ;
79 fragment FragEscapeApos : '\'';
80 fragment FragDigits : [0-9]+ ;
81
82 QName  : FragQName ;
83 NCName : FragmentNCName ;
84 fragment FragQName : FragPrefixedName | FragUnprefixedName ;
85 fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
86 fragment FragUnprefixedName : FragLocalPart ;
87 fragment FragPrefix : FragmentNCName ;
88 fragment FragLocalPart : FragmentNCName ;
89 fragment FragNCNameStartChar
90   :  'A'..'Z'
91   |  '_'
92   | 'a'..'z'
93   | '\u00C0'..'\u00D6'
94   | '\u00D8'..'\u00F6'
95   | '\u00F8'..'\u02FF'
96   | '\u0370'..'\u037D'
97   | '\u037F'..'\u1FFF'
98   | '\u200C'..'\u200D'
99   | '\u2070'..'\u218F'
100   | '\u2C00'..'\u2FEF'
101   | '\u3001'..'\uD7FF'
102   | '\uF900'..'\uFDCF'
103   | '\uFDF0'..'\uFFFD'
104   | '\u{10000}'..'\u{EFFFF}'
105   ;
106 fragment FragNCNameChar
107   :  FragNCNameStartChar | '-' | '.' | '0'..'9'
108   |  '\u00B7' | '\u0300'..'\u036F'
109   |  '\u203F'..'\u2040'
110   ;
111 fragment FragmentNCName : FragNCNameStartChar FragNCNameChar*  ;
112
113 // https://www.w3.org/TR/REC-xml/#NT-Char
114
115 fragment FragChar : '\u0009' | '\u000a' | '\u000d'
116   | '\u0020'..'\ud7ff'
117   | '\ue000'..'\ufffd'
118   | '\u{10000}'..'\u{10ffff}'
119  ;
120
121 // Skip all Whitespace
122 Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
123
124 // handle characters which failed to match any other token (otherwise Antlr will ignore them)
125 ErrorCharacter : . ;