Hotfix for stmtsep use in YangParser grammar. 48/10448/1
authorLukas Sedlak <lsedlak@cisco.com>
Thu, 28 Aug 2014 13:03:56 +0000 (15:03 +0200)
committerLukas Sedlak <lsedlak@cisco.com>
Thu, 28 Aug 2014 13:03:56 +0000 (15:03 +0200)
The stmtsep can occour 0..n times. Based on that the use of stmtsep? was replaced for stmtsep*
Added definitions for use of extensions outside of body statements in ext-use.yang.

Change-Id: I23092a7a6a5474bfed214ad08f64346a17b13df3
Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
yang/yang-parser-impl/src/main/antlr/YangParser.g4
yang/yang-parser-impl/src/test/resources/extensions/ext-use.yang

index c1b004dfd289baf1dbb6839b733cfe3a65ed23bd..3484b79fc342ad072c911e170fd1aed653c7a15e 100644 (file)
@@ -34,6 +34,13 @@ unknown_statement : (YIN_ELEMENT_KEYWORD | YANG_VERSION_KEYWORD | WHEN_KEYWORD |
                     ANYXML_KEYWORD | IDENTIFIER) string? (SEMICOLON | (LEFT_BRACE (unknown_statement | identifier_stmt)* RIGHT_BRACE)*);
 
 stmtend : (SEMICOLON) | (LEFT_BRACE identifier_stmt? RIGHT_BRACE);
+
+/* DO NOT replace stmtsep in rest of grammar with identifier_stmt!!! It might seems as code duplicity here, but this one is necessary.
+   Body of identifier_stmt generated from this grammar in YangParserListener is implemented in YangParserListenerImpl.
+   To ensure that all of the identifier_stmts will be resolved correctly the YangParserListenerImpl contains code that handles
+   specifcly identifier_stmts -> i.e. transforms identifier_stmt into QName. The stmtsep is used for parsing extension statements
+   placed outside of body_stmt.
+ */
 stmtsep : IDENTIFIER string? (stmtend | (LEFT_BRACE unknown_statement* RIGHT_BRACE));
 deviate_replace_stmt : DEVIATE_KEYWORD string /* REPLACE_KEYWORD */ (SEMICOLON | (LEFT_BRACE (identifier_stmt |type_stmt | units_stmt | default_stmt | config_stmt | mandatory_stmt | min_elements_stmt | max_elements_stmt )* RIGHT_BRACE));
 deviate_delete_stmt : DEVIATE_KEYWORD string /* DELETE_KEYWORD */ (SEMICOLON | (LEFT_BRACE (identifier_stmt |units_stmt | must_stmt | unique_stmt | default_stmt )* RIGHT_BRACE));
@@ -133,9 +140,9 @@ yang_version_stmt : YANG_VERSION_KEYWORD string stmtend;
 data_def_stmt : container_stmt | leaf_stmt | leaf_list_stmt | list_stmt | choice_stmt | anyxml_stmt | uses_stmt;
 body_stmts : (( identifier_stmt| extension_stmt | feature_stmt | identity_stmt | typedef_stmt | grouping_stmt | data_def_stmt | augment_stmt | rpc_stmt | notification_stmt | deviation_stmt) )*;
 revision_stmts :  (revision_stmt )* (stmtsep)*;
-linkage_stmts : (import_stmt stmtsep? | include_stmt stmtsep?)*;
-meta_stmts : (organization_stmt stmtsep? | contact_stmt stmtsep? | description_stmt stmtsep? | reference_stmt stmtsep?)*;
-submodule_header_stmts : (yang_version_stmt stmtsep? | belongs_to_stmt stmtsep?)+ ;
-module_header_stmts :  (yang_version_stmt stmtsep? | namespace_stmt stmtsep? | prefix_stmt stmtsep?)+ ;
+linkage_stmts : (import_stmt stmtsep* | include_stmt stmtsep*)*;
+meta_stmts : (organization_stmt stmtsep* | contact_stmt stmtsep* | description_stmt stmtsep* | reference_stmt stmtsep*)*;
+submodule_header_stmts : (yang_version_stmt stmtsep* | belongs_to_stmt stmtsep*)+ ;
+module_header_stmts :  (yang_version_stmt stmtsep* | namespace_stmt stmtsep* | prefix_stmt stmtsep*)+ ;
 submodule_stmt : SUBMODULE_KEYWORD string LEFT_BRACE  submodule_header_stmts linkage_stmts meta_stmts revision_stmts body_stmts RIGHT_BRACE;
-module_stmt : MODULE_KEYWORD string LEFT_BRACE stmtsep? module_header_stmts linkage_stmts meta_stmts revision_stmts body_stmts RIGHT_BRACE;
\ No newline at end of file
+module_stmt : MODULE_KEYWORD string LEFT_BRACE stmtsep* module_header_stmts linkage_stmts meta_stmts revision_stmts body_stmts RIGHT_BRACE;
\ No newline at end of file
index f36fc15b073439b90d48e3bf4bdb6922d0b5b83d..01c1dd97247b51f645c6bd9812d50a4c509c71ad 100644 (file)
@@ -1,7 +1,19 @@
 module ext-use {
+    ext:id "http://opendaylight.org";
     yang-version 1;
+    ext:id "http://opendaylight.org";
+
+    ext:id2 "73354";
+    ext:name "test-name";
+
     namespace "urn:simple.extension.use";
+    ext:id "http://opendaylight.org";
+
+    ext:name "test-name";
+
     prefix "ext-use";
+    ext:id "http://opendaylight.org";
+    ext:name "test-name";
 
     import ext-typedef { prefix "ext"; }