[ONOS-3880, 3881] Yang Listener for Module and Sub-Module
Change-Id: Iee75c3e04af9b66ebc38acb3396aa4c54af5a268
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java b/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
index 0878191..dcab33a 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
@@ -69,16 +69,12 @@
// Add customized error listener to catch errors during parsing.
parser.addErrorListener(parseTreeErrorListener);
- // Begin parsing YANG file and generate parse tree.
- ParseTree tree = parser.yangfile();
+ ParseTree tree;
- /**
- * Throws an parser Exception if exception flag is set i.e. exception has
- * occurred during parsing.
- */
- if (parseTreeErrorListener.isExceptionFlag()) {
- // Get the exception occurred during parsing.
- ParserException parserException = parseTreeErrorListener.getParserException();
+ try {
+ // Begin parsing YANG file and generate parse tree.
+ tree = parser.yangfile();
+ } catch (ParserException parserException) {
parserException.setFileName(yangFile);
throw parserException;
}
@@ -93,18 +89,17 @@
* Walk parse tree, provide call backs to methods in listener and
* build data model tree.
*/
- walker.walk(treeWalker, tree);
-
- // Throws an parser exception which has occurred during listener walk.
- if (treeWalker.getErrorInformation().isErrorFlag()) {
- // Create object of listener exception
- ParserException listenerException = new ParserException();
- listenerException.setMsg(treeWalker.getErrorInformation().getErrorMsg());
+ try {
+ walker.walk(treeWalker, tree);
+ } catch (ParserException listenerException) {
+ // TODO free incomplete data model tree.
listenerException.setFileName(yangFile);
throw listenerException;
+ } finally {
+ // TODO free parsable stack
}
// Returns the Root Node of the constructed data model tree.
return treeWalker.getRootNode();
}
-}
+}
\ No newline at end of file