summaryrefslogtreecommitdiffstats
path: root/cps-path-parser/src/main/antlr4/org
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2021-05-20 16:44:21 +0100
committerToineSiebelink <toine.siebelink@est.tech>2021-06-01 10:12:55 +0100
commitc37678a3eb62685d32a1581729e2a4e26002bffc (patch)
tree1901f7e3517ae339f99905f7ffc0021553874842 /cps-path-parser/src/main/antlr4/org
parent9de3b68373dd8554e64f34bb3093403521f8759f (diff)
Introducing Antlr4 for cpsPath parsing
-created new module for cpPathParser -added antlr rule for cpsPathWithSingleLeafCondition -added antlr rule for cpsPathWithDescendant (and with leaf conditions) -added antlr rule for ancestor axis -added unit test (copied from existing CpsPathQuerySpec) -udpated cps-ri to use new cpPathQuery from parser module -'imported' lexer rules from publix xPath grammar -Re-used existing CpsPathException but conversion happens in cps-ri to prevent additional dependency in cps-path-parser module Issue-ID: CPS-376 Change-Id: I2c5df98969402cbf69f6573c52705879450ce606 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Diffstat (limited to 'cps-path-parser/src/main/antlr4/org')
-rw-r--r--cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4123
1 files changed, 123 insertions, 0 deletions
diff --git a/cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4 b/cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4
new file mode 100644
index 0000000000..86095459ee
--- /dev/null
+++ b/cps-path-parser/src/main/antlr4/org/onap/cps/cpspath/parser/antlr4/CpsPath.g4
@@ -0,0 +1,123 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+grammar CpsPath ;
+
+cpsPath: (cpsPathWithSingleLeafCondition | cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions) ancestorAxis? ;
+
+ancestorAxis: SLASH KW_ANCESTOR COLONCOLON ancestorPath ;
+
+ancestorPath: yangElement (SLASH yangElement)* ;
+
+cpsPathWithSingleLeafCondition: prefix singleValueCondition ;
+
+/*
+No need to ditinguish between cpsPathWithDescendant | cpsPathWithDescendantAndLeafConditions really!
+See https://jira.onap.org/browse/CPS-436
+*/
+
+cpsPathWithDescendant: descendant ;
+
+cpsPathWithDescendantAndLeafConditions: descendant multipleValueConditions ;
+
+descendant: SLASH prefix ;
+
+prefix: (SLASH yangElement)* SLASH containerName ;
+
+yangElement: containerName listElementRef? ;
+
+containerName: QName ;
+
+listElementRef: multipleValueConditions ;
+
+singleValueCondition: '[' leafCondition ']' ;
+
+multipleValueConditions: '[' leafCondition (' and ' leafCondition)* ']' ;
+
+leafCondition: '@' leafName '=' (IntegerLiteral | StringLiteral ) ;
+
+//To Confirm: defintion of Lefname with external xPath grammar
+leafName: QName ;
+
+/*
+ * Lexer Rules
+ * Most of the lexer rules below are 'imporetd' from
+ * https://raw.githubusercontent.com/antlr/grammars-v4/master/xpath/xpath31/XPath31.g4
+ */
+
+SLASH : '/';
+COLONCOLON : '::' ;
+
+// KEYWORDS
+
+KW_ANCESTOR : 'ancestor' ;
+
+IntegerLiteral : FragDigits ;
+// Add below type definitions for leafvalue comparision in https://jira.onap.org/browse/CPS-440
+DecimalLiteral : ('.' FragDigits) | (FragDigits '.' [0-9]*) ;
+DoubleLiteral : (('.' FragDigits) | (FragDigits ('.' [0-9]*)?)) [eE] [+-]? FragDigits ;
+StringLiteral : ('"' (FragEscapeQuot | ~[^"])*? '"') | ('\'' (FragEscapeApos | ~['])*? '\'') ;
+fragment FragEscapeQuot : '""' ;
+fragment FragEscapeApos : '\'';
+fragment FragDigits : [0-9]+ ;
+
+QName : FragQName ;
+NCName : FragmentNCName ;
+fragment FragQName : FragPrefixedName | FragUnprefixedName ;
+fragment FragPrefixedName : FragPrefix ':' FragLocalPart ;
+fragment FragUnprefixedName : FragLocalPart ;
+fragment FragPrefix : FragmentNCName ;
+fragment FragLocalPart : FragmentNCName ;
+fragment FragNCNameStartChar
+ : 'A'..'Z'
+ | '_'
+ | 'a'..'z'
+ | '\u00C0'..'\u00D6'
+ | '\u00D8'..'\u00F6'
+ | '\u00F8'..'\u02FF'
+ | '\u0370'..'\u037D'
+ | '\u037F'..'\u1FFF'
+ | '\u200C'..'\u200D'
+ | '\u2070'..'\u218F'
+ | '\u2C00'..'\u2FEF'
+ | '\u3001'..'\uD7FF'
+ | '\uF900'..'\uFDCF'
+ | '\uFDF0'..'\uFFFD'
+ | '\u{10000}'..'\u{EFFFF}'
+ ;
+fragment FragNCNameChar
+ : FragNCNameStartChar | '-' | '.' | '0'..'9'
+ | '\u00B7' | '\u0300'..'\u036F'
+ | '\u203F'..'\u2040'
+ ;
+fragment FragmentNCName : FragNCNameStartChar FragNCNameChar* ;
+
+// https://www.w3.org/TR/REC-xml/#NT-Char
+
+fragment FragChar : '\u0009' | '\u000a' | '\u000d'
+ | '\u0020'..'\ud7ff'
+ | '\ue000'..'\ufffd'
+ | '\u{10000}'..'\u{10ffff}'
+ ;
+
+// Skip all Whitespace
+Whitespace : ('\u000d' | '\u000a' | '\u0020' | '\u0009')+ -> skip ;
+
+// handle characters which failed to match any other token (otherwise Antlr will ignore them)
+ErrorCharacter : . ;