Added support for parsing submodules & added dependency utility parser
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / YangParserListenerImpl.java
index f59f6881ae99b455cc7da825b317a2f8f5d6dad9..12c230d5bc3894d649990fb7d458fd978a8e17a0 100644 (file)
@@ -110,6 +110,41 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         actualPath.pop();
     }
 
+    @Override public void enterSubmodule_stmt(YangParser.Submodule_stmtContext ctx) {
+        moduleName = stringFromNode(ctx);
+        LOGGER.debug("entering submodule " + moduleName);
+        enterLog("submodule", moduleName, 0);
+        actualPath.push(new Stack<QName>());
+
+        moduleBuilder = new ModuleBuilder(moduleName, true);
+
+        String description = null;
+        String reference = null;
+        for (int i = 0; i < ctx.getChildCount(); i++) {
+            ParseTree child = ctx.getChild(i);
+            if (child instanceof Description_stmtContext) {
+                description = stringFromNode(child);
+            } else if (child instanceof Reference_stmtContext) {
+                reference = stringFromNode(child);
+            } else {
+                if (description != null && reference != null) {
+                    break;
+                }
+            }
+        }
+        moduleBuilder.setDescription(description);
+        moduleBuilder.setReference(reference);
+    }
+
+    @Override public void exitSubmodule_stmt(YangParser.Submodule_stmtContext ctx) {
+        exitLog("submodule", "");
+        actualPath.pop();
+    }
+
+    @Override public void enterBelongs_to_stmt(YangParser.Belongs_to_stmtContext ctx) {
+        moduleBuilder.setBelongsTo(stringFromNode(ctx));
+    }
+
     @Override
     public void enterModule_header_stmts(Module_header_stmtsContext ctx) {
         enterLog("module_header", "", ctx.getStart().getLine());