Bug 3859: Use of reference keyword in a YANG extension 25/26025/1
authorMartin Ciglan <mciglan@cisco.com>
Fri, 21 Aug 2015 12:48:34 +0000 (14:48 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 26 Aug 2015 14:35:14 +0000 (14:35 +0000)
    causes YangSyntaxErrorException

Once reference or any other yang statement is defined within use of
extension (unknown statement), this should be correctly parsed
as another unknown statement. This behavior has been
added to RFC6020 ANTLR grammar and tested.

Change-Id: I3eed81e67ba6192e2c98154e7e6800215b1cc4bf
Signed-off-by: Martin Ciglan <mciglan@cisco.com>
(cherry picked from commit e8a7058112bacbafada62cb71fef8207506d38d5)

yang/yang-parser-impl/src/main/antlr/YangParser.g4
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3859Test.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug3859/bug3859.yang [new file with mode: 0644]

index 3e5ca54da0e315379fbb50eb2efea1f603d3e620..6c4e76d38b9e3d53930591d7944d95b8b1717666 100644 (file)
@@ -33,7 +33,9 @@ unknown_statement : (YIN_ELEMENT_KEYWORD | YANG_VERSION_KEYWORD | WHEN_KEYWORD |
                     IDENTITY_KEYWORD | GROUPING_KEYWORD | FRACTION_DIGITS_KEYWORD | FEATURE_KEYWORD | DEVIATE_KEYWORD | DEVIATION_KEYWORD | EXTENSION_KEYWORD | 
                     ERROR_MESSAGE_KEYWORD | ERROR_APP_TAG_KEYWORD | ENUM_KEYWORD | DESCRIPTION_KEYWORD | STATUS_KEYWORD | DEFAULT_KEYWORD | CONTAINER_KEYWORD | CONTACT_KEYWORD | 
                     CONFIG_KEYWORD | CHOICE_KEYWORD |  CASE_KEYWORD | BIT_KEYWORD | BELONGS_TO_KEYWORD | BASE_KEYWORD | AUGMENT_KEYWORD |  
-                    ANYXML_KEYWORD | IDENTIFIER) string? (SEMICOLON | (LEFT_BRACE (unknown_statement | identifier_stmt)* RIGHT_BRACE)*);
+                    ANYXML_KEYWORD | REFERENCE_KEYWORD | IDENTIFIER) string? (SEMICOLON | (LEFT_BRACE
+                    (unknown_statement |
+                    identifier_stmt)* RIGHT_BRACE)*);
 
 stmtend : (SEMICOLON) | (LEFT_BRACE identifier_stmt? RIGHT_BRACE);
 
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3859Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug3859Test.java
new file mode 100644 (file)
index 0000000..a67ffb4
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Module;
+
+public class Bug3859Test {
+
+    @Test
+    public void test() throws Exception {
+        Set<Module> modules = TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI());
+        Module bug3859 = TestUtils.findModule(modules, "reference-in-unknown");
+        assertNotNull(bug3859);
+    }
+
+}
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug3859/bug3859.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug3859/bug3859.yang
new file mode 100644 (file)
index 0000000..b3d9bc4
--- /dev/null
@@ -0,0 +1,31 @@
+module reference-in-unknown {
+  namespace "urn:ref:unknown";
+  prefix "riu";
+
+  extension test-extension {
+    argument test;
+  }
+
+  riu:test-extension {
+    container cont {
+      description
+        "This is just a plain text";
+
+      list mylist {
+        description
+          "This is a just another plain text";
+
+        reference "refers somewhere...";
+
+        leaf myleaf1 {
+          type string;
+        }
+
+        leaf myleaf2 {
+          type string;
+        }
+      }
+    }
+  }
+}
+