Bug 1559, Bug 2406 - Unknown statement is missing in submodule and revision statements 49/13249/2
authorPeter Kajsa <pkajsa@cisco.com>
Mon, 1 Dec 2014 09:57:50 +0000 (10:57 +0100)
committerPeter Kajsa <pkajsa@cisco.com>
Wed, 7 Jan 2015 14:03:29 +0000 (14:03 +0000)
Bug 1559 - stmtsep is missing in submodule_stmt.
Bug 2406 - in our grammar unknown-statement can occur only after all revision
statements, but in RFC grammar unknown-statement can occur also before or
between two revision statements etc.

Change-Id: Ide4a9044545af8a397cc8c4074ea6ae91022288d
Signed-off-by: Peter Kajsa <pkajsa@cisco.com>
yang/yang-parser-impl/src/main/antlr/YangParser.g4
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java
yang/yang-parser-impl/src/test/resources/yang-grammar-test/revisions-extension.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/yang-grammar-test/submodule-header-extension.yang [new file with mode: 0644]

index 3484b79fc342ad072c911e170fd1aed653c7a15e..9a26c172f3ec4bcbe42d22bb0bd37ceff3d1e122 100644 (file)
@@ -139,10 +139,10 @@ import_stmt : IMPORT_KEYWORD string LEFT_BRACE  prefix_stmt  (revision_date_stmt
 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)*;
+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*)+ ;
-submodule_stmt : SUBMODULE_KEYWORD string LEFT_BRACE  submodule_header_stmts linkage_stmts meta_stmts revision_stmts body_stmts RIGHT_BRACE;
+submodule_stmt : SUBMODULE_KEYWORD string LEFT_BRACE stmtsep* 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
index adab3c93a3c12a1364d5bf4fee313c3fee99b309..b3f408ef4e6771bb5e171405afdb0971c8f199a5 100644 (file)
@@ -12,13 +12,16 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigInteger;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -31,6 +34,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -60,6 +64,7 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.util.Decimal64;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.model.util.Int16;
@@ -68,6 +73,7 @@ import org.opendaylight.yangtools.yang.model.util.StringType;
 import org.opendaylight.yangtools.yang.model.util.Uint32;
 import org.opendaylight.yangtools.yang.model.util.UnionType;
 import org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
 public class YangParserTest {
     public static final String FS = File.separator;
@@ -923,4 +929,36 @@ public class YangParserTest {
         assertEquals(2, foo.getAugmentations().size());
     }
 
+    @Test
+    public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException {
+
+        File yang = new File(getClass().getResource("/yang-grammar-test/submodule-header-extension.yang").toURI());
+
+        try {
+            YangParserImpl.getInstance().parseFile(yang, yang.getParentFile());
+        } catch (YangSyntaxErrorException | YangParseException e) {
+            e.printStackTrace();
+            fail("YangSyntaxErrorException or YangParseException should not be thrown");
+        }
+
+    }
+
+    @Test
+    public void unknownStatementBetweenRevisionsTest() throws IOException, URISyntaxException {
+
+        File yangModul = new File(getClass().getResource("/yang-grammar-test/revisions-extension.yang").toURI());
+        File yangSubmodul = new File(getClass().getResource("/yang-grammar-test/submodule-header-extension.yang")
+                .toURI());
+
+        List<File> yangs = new ArrayList<File>();
+        yangs.add(yangModul);
+        yangs.add(yangSubmodul);
+
+        try {
+            YangParserImpl.getInstance().parseFiles(yangs);
+        } catch (YangParseException e) {
+            e.printStackTrace();
+            fail("YangParseException should not be thrown");
+        }
+    }
 }
diff --git a/yang/yang-parser-impl/src/test/resources/yang-grammar-test/revisions-extension.yang b/yang/yang-parser-impl/src/test/resources/yang-grammar-test/revisions-extension.yang
new file mode 100644 (file)
index 0000000..3527eff
--- /dev/null
@@ -0,0 +1,24 @@
+module revisions-extension {
+    namespace "my-namespace";
+    prefix pre;
+
+    include submodule-header-extension {
+        revision-date 2007-06-09;
+    }
+
+    revision "2007-06-09" {
+        description "Initial revision.";
+    }
+
+    pre:my-extension 1;
+
+    revision "2008-06-09" {
+        description "Revision 2.";
+    }
+
+    extension my-extension {
+        description "my description ...";
+        argument "number";
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/yang-grammar-test/submodule-header-extension.yang b/yang/yang-parser-impl/src/test/resources/yang-grammar-test/submodule-header-extension.yang
new file mode 100644 (file)
index 0000000..cfda3cb
--- /dev/null
@@ -0,0 +1,18 @@
+submodule submodule-header-extension {
+
+    pre:my-extension2 2;
+
+    belongs-to revisions-extension {
+        prefix pre;
+    }
+
+    revision "2007-06-09" {
+        description "Initial revision.";
+    }
+
+    extension my-extension2 {
+        description "my description ...";
+        argument "number";
+    }
+
+}