[ONOS-4941][ONOS-4883][ONOS-4979]Grouping and uses interfile linking issue + defect fix
Change-Id: I5e8145f05d3ef570d4ecbbe885c93de172de0ea3
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
index 508ec54..754801b 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
@@ -172,7 +172,7 @@
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
+ .resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) yangNode)
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
index 5c680cd..d7f0428 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
@@ -1594,11 +1594,7 @@
if (linkedNode != null) {
// Add the link to external entity.
addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
- /*
- * Update the current reference resolver to external
- * module/sub-module containing the referred typedef/grouping.
- */
- setCurReferenceResolver((YangReferenceResolver) yangInclude.getIncludedNode());
+
// Add the type/uses of referred typedef/grouping to the stack.
addUnresolvedRecursiveReferenceToStack(linkedNode);
return true;
@@ -1641,12 +1637,7 @@
if (linkedNode != null) {
// Add the link to external entity.
addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
- /*
- * Update the current reference resolver to external
- * module/sub-module containing the referred
- * typedef/grouping.
- */
- setCurReferenceResolver((YangReferenceResolver) yangImport.getImportedNode());
+
// Add the type/uses of referred typedef/grouping to the
// stack.
addUnresolvedRecursiveReferenceToStack(linkedNode);
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
index 5e55e15..72e7995 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
@@ -1835,136 +1835,94 @@
void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext currentContext);
/**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation statement.
+ * Enters a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
*
* @param currentContext current context in the parsed tree
*/
- void enterAnnotationStatement(GeneratedYangParser.AnnotationStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAnnotationStatement(GeneratedYangParser.AnnotationStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation type.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAnnotationType(GeneratedYangParser.AnnotationTypeContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation type.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAnnotationType(GeneratedYangParser.AnnotationTypeContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter specification.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
- currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter specification.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
+ void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
currentContext);
/**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter specification argument.
+ * Exits a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
*
* @param currentContext current context in the parsed tree
*/
- void enterAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
- currentContext);
+ void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
+ currentContext);
/**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter specification argument.
+ * Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
*
* @param currentContext current context in the parsed tree
*/
- void exitAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
- currentContext);
+ void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext
+ currentContext);
/**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation parameter instance.
+ * Exits a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
*
* @param currentContext current context in the parsed tree
*/
- void enterAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext
- currentContext);
+ void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext currentContext);
/**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation parameter instance.
+ * Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure.
*
* @param currentContext current context in the parsed tree
*/
- void exitAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext
- currentContext);
+ void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
+
+ /**
+ * Exits a parse tree produced by GeneratedYangParser for grammar rule app data strcuture.
+ *
+ * @param currentContext current context in the parsed tree
+ */
+ void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
+
+ /**
+ * Enters a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
+ *
+ * @param currentContext current context in the parsed tree
+ */
+ void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
+
+ /**
+ * Exits a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
+ *
+ * @param currentContext current context in the parsed tree
+ */
+ void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
+
+ /**
+ * Enters a parse tree produced by GeneratedYangParser for grammar rule extended name.
+ *
+ * @param currentContext current context in the parsed tree
+ */
+ void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
+
+ /**
+ * Exits a parse tree produced by GeneratedYangParser for grammar rule extended name.
+ *
+ * @param currentContext current context in the parsed tree
+ */
+ void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
+
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter type identifier.
+ * data structure key statement.
*
* @param currentContext current context in the parsed tree
*/
- void enterAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext
- currentContext);
+ void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
/**
* Exits a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter type identifier.
+ * data structure key statement.
*
* @param currentContext current context in the parsed tree
*/
- void exitAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext
- currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter type value.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext
- currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule
- * annotation parameter type value.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext
- currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule annotation identifier.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
- currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule annotation identifier.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext
- currentContext);
+ void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
/**
* Enters a parse tree produced by GeneratedYangParser for grammar rule require instance.
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
index 2b9021b..116f06d 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
@@ -24,6 +24,8 @@
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.impl.listeners.AppDataStructureListener;
+import org.onosproject.yangutils.parser.impl.listeners.AppExtendedNameListener;
import org.onosproject.yangutils.parser.impl.listeners.ArgumentListener;
import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
@@ -33,9 +35,11 @@
import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
import org.onosproject.yangutils.parser.impl.listeners.CaseListener;
import org.onosproject.yangutils.parser.impl.listeners.ChoiceListener;
+import org.onosproject.yangutils.parser.impl.listeners.CompilerAnnotationListener;
import org.onosproject.yangutils.parser.impl.listeners.ConfigListener;
import org.onosproject.yangutils.parser.impl.listeners.ContactListener;
import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
+import org.onosproject.yangutils.parser.impl.listeners.DataStructureKeyListener;
import org.onosproject.yangutils.parser.impl.listeners.Decimal64Listener;
import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
@@ -1428,95 +1432,72 @@
@Override
public void enterCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
- // TODO: implement the method.
+ CompilerAnnotationListener.processCompilerAnnotationEntry(this, ctx);
}
@Override
public void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
- // TODO: implement the method.
+ CompilerAnnotationListener.processCompilerAnnotationExit(this, ctx);
}
@Override
- public void enterAnnotationStatement(GeneratedYangParser.AnnotationStatementContext ctx) {
- // TODO: implement the method.
+ public void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
+ // do nothing
}
@Override
- public void exitAnnotationStatement(GeneratedYangParser.AnnotationStatementContext ctx) {
- // TODO: implement the method.
+ public void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
+ // do nothing
}
@Override
- public void enterAnnotationType(GeneratedYangParser.AnnotationTypeContext ctx) {
- // TODO: implement the method.
+ public void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
+ AppDataStructureListener.processAppDataStructureEntry(this, ctx);
}
@Override
- public void exitAnnotationType(GeneratedYangParser.AnnotationTypeContext ctx) {
- // TODO: implement the method.
+ public void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
+ AppDataStructureListener.processAppDataStructureExit(this, ctx);
}
@Override
- public void enterAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext
- ctx) {
- // TODO: implement the method.
+ public void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
+ // do nothing
}
@Override
- public void exitAnnotationParameterSpecification(GeneratedYangParser.AnnotationParameterSpecificationContext ctx) {
- // TODO: implement the method.
+ public void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
+ // do nothing
}
@Override
- public void enterAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
- ctx) {
- // TODO: implement the method.
+ public void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
+ AppExtendedNameListener.processAppExtendedNameEntry(this, currentContext);
}
@Override
- public void exitAnnotationParameterSpecificationArg(GeneratedYangParser.AnnotationParameterSpecificationArgContext
- ctx) {
- // TODO: implement the method.
+ public void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
+ // TODO : to be implemented
}
@Override
- public void enterAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext ctx) {
- // TODO: implement the method.
+ public void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
+ // do nothing
}
@Override
- public void exitAnnotationParaInstance(GeneratedYangParser.AnnotationParaInstanceContext ctx) {
- // TODO: implement the method.
+ public void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
+ // do nothing
}
@Override
- public void enterAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext ctx) {
- // TODO: implement the method.
+ public void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
+ DataStructureKeyListener.processDataStructureKeyEntry(this, ctx);
}
@Override
- public void exitAnnotationParaTypeIdentifier(GeneratedYangParser.AnnotationParaTypeIdentifierContext ctx) {
- // TODO: implement the method.
- }
-
- @Override
- public void enterAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext ctx) {
- // TODO: implement the method.
- }
-
- @Override
- public void exitAnnotationParaTypeValue(GeneratedYangParser.AnnotationParaTypeValueContext ctx) {
- // TODO: implement the method.
- }
-
- @Override
- public void enterAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext ctx) {
- // TODO: implement the method.
- }
-
- @Override
- public void exitAnnotationIdentifier(GeneratedYangParser.AnnotationIdentifierContext ctx) {
- // TODO: implement the method.
+ public void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
+ // do nothing
}
@Override
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
new file mode 100644
index 0000000..e6628b3
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppDataStructure;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangDataStructure;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.YangDataStructure.getType;
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.APP_DATA_STRUCTURE;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * app-data-structure-stmt = prefix:app-data-structure-keyword string
+ * (";" /
+ * "{"
+ * [data-structure-key-stmt stmtsep]
+ * "}")
+ *
+ * ANTLR grammar rule
+ * appDataStructureStatement : APP_DATA_STRUCTURE appDataStructure (STMTEND | (LEFT_CURLY_BRACE
+ * dataStructureKeyStatement? RIGHT_CURLY_BRACE));
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "app-data-structure"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class AppDataStructureListener {
+
+ /**
+ * Creates a new app-data-structure listener.
+ */
+ private AppDataStructureListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when parser receives an
+ * input matching the grammar rule(app-data-structure).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processAppDataStructureEntry(TreeWalkListener listener,
+ GeneratedYangParser.AppDataStructureStatementContext ctx) {
+
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", ENTRY);
+
+ String prefix = getValidPrefix(ctx.APP_DATA_STRUCTURE().getText(), APP_DATA_STRUCTURE, ctx);
+ YangDataStructure dataStructure = getType(ctx.appDataStructure().getText());
+
+ YangAppDataStructure appDataStructure = new YangAppDataStructure();
+ appDataStructure.setPrefix(prefix);
+ appDataStructure.setDataStructure(dataStructure);
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ if (curData instanceof YangCompilerAnnotation) {
+ YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
+ compilerAnnotation.setYangAppDataStructure(appDataStructure);
+ listener.getParsedDataStack().push(appDataStructure);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_DATA_STRUCTURE,
+ "", ENTRY));
+ }
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when parser
+ * exits from grammar rule (app-data-structure).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processAppDataStructureExit(TreeWalkListener listener,
+ GeneratedYangParser.AppDataStructureStatementContext ctx) {
+
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", EXIT);
+ if (!(listener.getParsedDataStack().peek() instanceof YangAppDataStructure)) {
+ throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, APP_DATA_STRUCTURE,
+ "", EXIT));
+ }
+ listener.getParsedDataStack().pop();
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
new file mode 100644
index 0000000..3ec31c7
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppExtendedName;
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.APP_EXTENDED_NAME_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * app-extended-stmt = prefix:app-extended-name-keyword string ";"
+ *
+ * ANTLR grammar rule
+ * appExtendedStatement : APP_EXTENDED extendedName STMTEND;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "app-extended-name"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class AppExtendedNameListener {
+
+ /**
+ * Creates a new app-extended-name listener.
+ */
+ private AppExtendedNameListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when parser receives an
+ * input matching the grammar rule(app-extended-name).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processAppExtendedNameEntry(TreeWalkListener listener,
+ GeneratedYangParser.AppExtendedStatementContext ctx) {
+
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_EXTENDED_NAME_DATA, ctx.extendedName().getText(), ENTRY);
+
+ String prefix = getValidPrefix(ctx.APP_EXTENDED().getText(), APP_EXTENDED_NAME_DATA, ctx);
+ YangAppExtendedName extendedName = new YangAppExtendedName();
+ extendedName.setPrefix(prefix);
+ extendedName.setYangAppExtendedName(removeQuotesAndHandleConcat(ctx.extendedName().getText()));
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ if (curData instanceof YangCompilerAnnotation) {
+ YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
+ compilerAnnotation.setYangAppExtendedName(extendedName);
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_EXTENDED_NAME_DATA,
+ ctx.extendedName().getText(), ENTRY));
+ }
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
new file mode 100644
index 0000000..c89e99a
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangSubModule;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.COMPILER_ANNOTATION_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * compiler-annotation-stmt = prefix:compiler-annotation-keyword string
+ * "{"
+ * [app-data-structure-stmt stmtsep]
+ * [app-extended-stmt stmtsep]
+ * "}"
+ *
+ * ANTLR grammar rule
+ * compilerAnnotationStatement : COMPILER_ANNOTATION string LEFT_CURLY_BRACE
+ * compilerAnnotationBodyStatement RIGHT_CURLY_BRACE;
+ *
+ * compilerAnnotationBodyStatement : appDataStructureStatement? appExtendedStatement? ;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "compiler-annotation"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class CompilerAnnotationListener {
+
+ /**
+ * Creates a new compiler-annotation listener.
+ */
+ private CompilerAnnotationListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when parser receives an
+ * input matching the grammar rule(compiler-annotation).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processCompilerAnnotationEntry(TreeWalkListener listener,
+ GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), ENTRY);
+ String prefix = getValidPrefix(ctx.COMPILER_ANNOTATION().getText(), COMPILER_ANNOTATION_DATA, ctx);
+
+ YangCompilerAnnotation compilerAnnotation = new YangCompilerAnnotation();
+ compilerAnnotation.setPrefix(prefix);
+ compilerAnnotation.setPath(removeQuotesAndHandleConcat(ctx.string().getText()));
+
+ Parsable curData = listener.getParsedDataStack().peek();
+ switch (curData.getYangConstructType()) {
+ case MODULE_DATA:
+ YangModule module = ((YangModule) curData);
+ module.addCompilerAnnotation(compilerAnnotation);
+ break;
+ case SUB_MODULE_DATA:
+ YangSubModule subModule = ((YangSubModule) curData);
+ subModule.addCompilerAnnotation(compilerAnnotation);
+ break;
+ default:
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, COMPILER_ANNOTATION_DATA,
+ ctx.string().getText(), ENTRY));
+ }
+ listener.getParsedDataStack().push(compilerAnnotation);
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when parser
+ * exits from grammar rule (compiler-annotation).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processCompilerAnnotationExit(TreeWalkListener listener,
+ GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
+
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), EXIT);
+ if (!(listener.getParsedDataStack().peek() instanceof YangCompilerAnnotation)) {
+ throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, COMPILER_ANNOTATION_DATA,
+ ctx.string().getText(), EXIT));
+ }
+ listener.getParsedDataStack().pop();
+ }
+}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java
new file mode 100644
index 0000000..65fc50b
--- /dev/null
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.listeners;
+
+import org.onosproject.yangutils.datamodel.YangAppDataStructure;
+import org.onosproject.yangutils.datamodel.utils.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.datamodel.utils.YangConstructType.KEY_DATA;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
+import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+
+/*
+ * Reference: RFC6020 and YANG ANTLR Grammar
+ *
+ * ABNF grammar as per RFC6020
+ * data-structure-key-stmt = prefix:key-keyword string ";"
+ *
+ * ANTLR grammar rule
+ * dataStructureKeyStatement : DATA_STRUCTURE_KEY string STMTEND;
+ */
+
+/**
+ * Represents listener based call back function corresponding to the "key"
+ * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
+ */
+public final class DataStructureKeyListener {
+
+ /**
+ * Creates a new data-structure-key listener.
+ */
+ private DataStructureKeyListener() {
+ }
+
+ /**
+ * Performs validation and updates the data model tree. It is called when parser receives an
+ * input matching the grammar rule(key).
+ *
+ * @param listener listener's object
+ * @param ctx context object of the grammar rule
+ */
+ public static void processDataStructureKeyEntry(TreeWalkListener listener,
+ GeneratedYangParser.DataStructureKeyStatementContext ctx) {
+
+ // Check for stack to be non empty.
+ checkStackIsNotEmpty(listener, MISSING_HOLDER, KEY_DATA, ctx.string().getText(), ENTRY);
+
+ Parsable tmpData = listener.getParsedDataStack().peek();
+ if (listener.getParsedDataStack().peek() instanceof YangAppDataStructure) {
+ YangAppDataStructure dataStructure = (YangAppDataStructure) tmpData;
+ String tmpKeyValue = removeQuotesAndHandleConcat(ctx.string().getText());
+ if (tmpKeyValue.contains(SPACE)) {
+ String[] keyValues = tmpKeyValue.split(SPACE);
+ for (String keyValue : keyValues) {
+ dataStructure.addKey(keyValue);
+ }
+ } else {
+ dataStructure.addKey(tmpKeyValue);
+ }
+ } else {
+ throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, KEY_DATA, ctx.string().getText(),
+ ENTRY));
+ }
+ }
+}
+
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index aa38b87..5fe0970 100644
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -1026,4 +1026,28 @@
throw parserException;
}
}
+
+ /**
+ * Checks and return valid prefix.
+ *
+ * @param inputString string from yang file
+ * @param yangConstruct yang construct for creating error message
+ * @param ctx yang construct's context to get the line number and character position
+ * @return valid prefix
+ */
+ public static String getValidPrefix(String inputString,
+ YangConstructType yangConstruct, ParserRuleContext ctx) {
+ String tmpPrefixString = removeQuotesAndHandleConcat(inputString);
+ String[] tmpData = tmpPrefixString.split(Pattern.quote(COLON));
+ if (tmpData.length == 2) {
+ return tmpData[0];
+ } else {
+ ParserException parserException = new ParserException("YANG file error : " +
+ YangConstructType.getYangConstructType(yangConstruct) + " name " + inputString +
+ " is not valid.");
+ parserException.setLine(ctx.getStart().getLine());
+ parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
+ throw parserException;
+ }
+ }
}
diff --git a/plugin/src/main/resources/GeneratedYang.g4 b/plugin/src/main/resources/GeneratedYang.g4
index eb23364..0362cb0 100644
--- a/plugin/src/main/resources/GeneratedYang.g4
+++ b/plugin/src/main/resources/GeneratedYang.g4
@@ -124,7 +124,8 @@
| augmentStatement
| rpcStatement
| notificationStatement
- | deviationStatement)*
+ | deviationStatement
+ | compilerAnnotationStatement)*
;
/**
@@ -237,13 +238,34 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* "}")
- * TODO : 0..1 occurance to be checked in listener
*/
extensionStatement : EXTENSION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE extensionBody RIGHT_CURLY_BRACE);
- extensionBody : (argumentStatement | statusStatement | descriptionStatement
- | referenceStatement | compilerAnnotationStatement)* ;
+ extensionBody : argumentStatement? statusStatement? descriptionStatement? referenceStatement?
+ | argumentStatement? statusStatement? referenceStatement? descriptionStatement?
+ | argumentStatement? descriptionStatement? statusStatement? referenceStatement?
+ | argumentStatement? descriptionStatement? referenceStatement? statusStatement?
+ | argumentStatement? referenceStatement? descriptionStatement? statusStatement?
+ | argumentStatement? referenceStatement? statusStatement? descriptionStatement?
+ | statusStatement? referenceStatement? argumentStatement? descriptionStatement?
+ | statusStatement? referenceStatement? descriptionStatement? argumentStatement?
+ | statusStatement? descriptionStatement? referenceStatement? argumentStatement?
+ | statusStatement? descriptionStatement? argumentStatement? referenceStatement?
+ | statusStatement? argumentStatement? referenceStatement? descriptionStatement?
+ | statusStatement? argumentStatement? descriptionStatement? referenceStatement?
+ | descriptionStatement? argumentStatement? statusStatement? referenceStatement?
+ | descriptionStatement? argumentStatement? referenceStatement? statusStatement?
+ | descriptionStatement? statusStatement? argumentStatement? referenceStatement?
+ | descriptionStatement? statusStatement? referenceStatement? argumentStatement?
+ | descriptionStatement? referenceStatement? statusStatement? argumentStatement?
+ | descriptionStatement? referenceStatement? argumentStatement? statusStatement?
+ | referenceStatement? descriptionStatement? argumentStatement? statusStatement?
+ | referenceStatement? descriptionStatement? statusStatement? argumentStatement?
+ | referenceStatement? statusStatement? argumentStatement? descriptionStatement?
+ | referenceStatement? statusStatement? descriptionStatement? argumentStatement?
+ | referenceStatement? argumentStatement? descriptionStatement? statusStatement?
+ | referenceStatement? argumentStatement? statusStatement? descriptionStatement?
+ ;
/**
* argument-stmt = argument-keyword sep identifier-arg-str optsep
@@ -270,13 +292,35 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* "}")
- * TODO : 0..1 occurance to be checked in listener
*/
identityStatement : IDENTITY_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE identityBody RIGHT_CURLY_BRACE);
- identityBody : (baseStatement | statusStatement | descriptionStatement | referenceStatement
- | compilerAnnotationStatement)*;
+ identityBody : baseStatement? statusStatement? descriptionStatement? referenceStatement?
+ | baseStatement? statusStatement? referenceStatement? descriptionStatement?
+ | baseStatement? descriptionStatement? statusStatement? referenceStatement?
+ | baseStatement? descriptionStatement? referenceStatement? statusStatement?
+ | baseStatement? referenceStatement? descriptionStatement? statusStatement?
+ | baseStatement? referenceStatement? statusStatement? descriptionStatement?
+ | referenceStatement? baseStatement? statusStatement? descriptionStatement?
+ | referenceStatement? baseStatement? descriptionStatement? statusStatement?
+ | referenceStatement? statusStatement? baseStatement? descriptionStatement?
+ | referenceStatement? statusStatement? descriptionStatement? baseStatement?
+ | referenceStatement? descriptionStatement? statusStatement? baseStatement?
+ | referenceStatement? descriptionStatement? baseStatement? statusStatement?
+ | descriptionStatement? referenceStatement? statusStatement? baseStatement?
+ | descriptionStatement? referenceStatement? statusStatement? baseStatement?
+ | descriptionStatement? referenceStatement? baseStatement? statusStatement?
+ | descriptionStatement? statusStatement? baseStatement? referenceStatement?
+ | descriptionStatement? statusStatement? referenceStatement? baseStatement?
+ | descriptionStatement? baseStatement? referenceStatement? statusStatement?
+ | descriptionStatement? baseStatement? statusStatement? referenceStatement?
+ | statusStatement? baseStatement? descriptionStatement? referenceStatement?
+ | statusStatement? baseStatement? referenceStatement? descriptionStatement?
+ | statusStatement? descriptionStatement? baseStatement? referenceStatement?
+ | statusStatement? descriptionStatement? referenceStatement? baseStatement?
+ | statusStatement? referenceStatement? descriptionStatement? baseStatement?
+ | statusStatement? referenceStatement? baseStatement? descriptionStatement?
+ ;
/**
* base-stmt = base-keyword sep identifier-ref-arg-str
@@ -294,13 +338,34 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* "}")
- * TODO : 0..1 occurance to be checked in listener
*/
featureStatement : FEATURE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE featureBody RIGHT_CURLY_BRACE);
- featureBody : (ifFeatureStatement | statusStatement | descriptionStatement
- | referenceStatement | compilerAnnotationStatement)* ;
+ featureBody : ifFeatureStatement* statusStatement? descriptionStatement? referenceStatement?
+ | ifFeatureStatement* statusStatement? referenceStatement? descriptionStatement?
+ | ifFeatureStatement* descriptionStatement? statusStatement? referenceStatement?
+ | ifFeatureStatement* descriptionStatement? referenceStatement? statusStatement?
+ | ifFeatureStatement* referenceStatement? statusStatement? descriptionStatement?
+ | ifFeatureStatement* referenceStatement? descriptionStatement? statusStatement?
+ | statusStatement? ifFeatureStatement* descriptionStatement? referenceStatement?
+ | statusStatement? ifFeatureStatement* referenceStatement? descriptionStatement?
+ | statusStatement? descriptionStatement? ifFeatureStatement* referenceStatement?
+ | statusStatement? descriptionStatement? referenceStatement? ifFeatureStatement*
+ | statusStatement? referenceStatement? ifFeatureStatement* descriptionStatement?
+ | statusStatement? referenceStatement? descriptionStatement? ifFeatureStatement*
+ | descriptionStatement? ifFeatureStatement* statusStatement? referenceStatement?
+ | descriptionStatement? ifFeatureStatement* referenceStatement? statusStatement?
+ | descriptionStatement? statusStatement? ifFeatureStatement* referenceStatement?
+ | descriptionStatement? statusStatement? referenceStatement? ifFeatureStatement*
+ | descriptionStatement? referenceStatement* statusStatement? ifFeatureStatement*
+ | descriptionStatement? referenceStatement* ifFeatureStatement? statusStatement?
+ | referenceStatement? ifFeatureStatement* statusStatement? descriptionStatement?
+ | referenceStatement? ifFeatureStatement* descriptionStatement? statusStatement?
+ | referenceStatement? descriptionStatement? statusStatement? ifFeatureStatement*
+ | referenceStatement? descriptionStatement? ifFeatureStatement* statusStatement?
+ | referenceStatement? statusStatement? descriptionStatement? ifFeatureStatement*
+ | referenceStatement? statusStatement? ifFeatureStatement* descriptionStatement?
+ ;
/**
* data-def-stmt = container-stmt /
@@ -340,13 +405,11 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* "}"
* TODO : 0..1 occurance to be validated in listener
*/
typedefStatement : TYPEDEF_KEYWORD identifier LEFT_CURLY_BRACE
- (typeStatement | unitsStatement | defaultStatement | statusStatement | descriptionStatement
- | compilerAnnotationStatement | referenceStatement)*
+ (typeStatement | unitsStatement | defaultStatement | statusStatement | descriptionStatement | referenceStatement)*
RIGHT_CURLY_BRACE;
/**
@@ -715,7 +778,6 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* *((typedef-stmt /
* grouping-stmt) stmtsep)
* *(data-def-stmt stmtsep)
@@ -724,7 +786,7 @@
*/
groupingStatement : GROUPING_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE
(statusStatement | descriptionStatement | referenceStatement | typedefStatement | groupingStatement
- | dataDefStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
+ | dataDefStatement)* RIGHT_CURLY_BRACE);
/**
* container-stmt = container-keyword sep identifier-arg-str optsep
@@ -739,7 +801,6 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* *((typedef-stmt /
* grouping-stmt) stmtsep)
* *(data-def-stmt stmtsep)
@@ -749,7 +810,7 @@
containerStatement : CONTAINER_KEYWORD identifier
(STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | presenceStatement | configStatement
| statusStatement | descriptionStatement | referenceStatement | typedefStatement | groupingStatement
- | dataDefStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
+ | dataDefStatement)* RIGHT_CURLY_BRACE);
/**
* leaf-stmt = leaf-keyword sep identifier-arg-str optsep
@@ -771,7 +832,7 @@
*/
leafStatement : LEAF_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement | unitsStatement
| mustStatement | defaultStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement
- | referenceStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
+ | referenceStatement)* RIGHT_CURLY_BRACE;
/**
* leaf-list-stmt = leaf-list-keyword sep identifier-arg-str optsep
@@ -794,7 +855,7 @@
*/
leafListStatement : LEAF_LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement
| unitsStatement | mustStatement | configStatement | minElementsStatement | maxElementsStatement | orderedByStatement
- | statusStatement | descriptionStatement | referenceStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
+ | statusStatement | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
/**
* list-stmt = list-keyword sep identifier-arg-str optsep
@@ -820,8 +881,7 @@
*/
listStatement : LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | keyStatement
| uniqueStatement | configStatement | minElementsStatement | maxElementsStatement | orderedByStatement | statusStatement
- | descriptionStatement | referenceStatement | typedefStatement | groupingStatement| dataDefStatement
- | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
+ | descriptionStatement | referenceStatement | typedefStatement | groupingStatement| dataDefStatement)* RIGHT_CURLY_BRACE;
/**
* key-stmt = key-keyword sep key-arg-str stmtend
@@ -852,7 +912,7 @@
*/
choiceStatement : CHOICE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | defaultStatement
| configStatement | mandatoryStatement | statusStatement | descriptionStatement | referenceStatement | shortCaseStatement
- | caseStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
+ | caseStatement)* RIGHT_CURLY_BRACE);
/**
* short-case-stmt = container-stmt /
@@ -897,7 +957,7 @@
*/
anyxmlStatement : ANYXML_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement
| mustStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement
- | referenceStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
+ | referenceStatement)* RIGHT_CURLY_BRACE);
/**
* uses-stmt = uses-keyword sep identifier-ref-arg-str optsep
@@ -909,15 +969,13 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* *(refine-stmt stmtsep)
* *(uses-augment-stmt stmtsep)
* "}")
* TODO : 0..1 occurance to be checked in listener
*/
usesStatement : USES_KEYWORD string (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
- | descriptionStatement | referenceStatement | refineStatement | augmentStatement
- | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
+ | descriptionStatement | referenceStatement | refineStatement | augmentStatement)* RIGHT_CURLY_BRACE);
/**
* refine-stmt = refine-keyword sep refine-arg-str optsep
@@ -1032,8 +1090,7 @@
* TODO : 0..1 occurance to be checked in listener
*/
augmentStatement : AUGMENT_KEYWORD augment LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
- | descriptionStatement | referenceStatement | dataDefStatement | caseStatement
- | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
+ | descriptionStatement | referenceStatement | dataDefStatement | caseStatement)* RIGHT_CURLY_BRACE;
/**
* when-stmt = when-keyword sep string optsep
@@ -1061,13 +1118,10 @@
* grouping-stmt) stmtsep)
* [input-stmt stmtsep]
* [output-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* "}")
- * TODO : 0..1 occurance to be checked in listener
*/
- rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
- | descriptionStatement | referenceStatement | typedefStatement | groupingStatement | inputStatement
- | outputStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
+ rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement | descriptionStatement
+ | referenceStatement | typedefStatement | groupingStatement | inputStatement | outputStatement)* RIGHT_CURLY_BRACE);
/**
* input-stmt = input-keyword optsep
@@ -1101,7 +1155,6 @@
* [status-stmt stmtsep]
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* *((typedef-stmt /
* grouping-stmt) stmtsep)
* *(data-def-stmt stmtsep)
@@ -1110,7 +1163,7 @@
*/
notificationStatement : NOTIFICATION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement
| statusStatement | descriptionStatement | referenceStatement | typedefStatement
- | groupingStatement | dataDefStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE);
+ | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
/**
* deviation-stmt = deviation-keyword sep
@@ -1119,7 +1172,6 @@
* ;; these stmts can appear in any order
* [description-stmt stmtsep]
* [reference-stmt stmtsep]
- * [compiler-annotation-stmt stmtsep]
* (deviate-not-supported-stmt /
* 1*(deviate-add-stmt /
* deviate-replace-stmt /
@@ -1129,7 +1181,7 @@
*/
deviationStatement: DEVIATION_KEYWORD deviation LEFT_CURLY_BRACE (descriptionStatement | referenceStatement
| deviateNotSupportedStatement | deviateAddStatement | deviateReplaceStatement
- | deviateDeleteStatement | compilerAnnotationStatement)* RIGHT_CURLY_BRACE;
+ | deviateDeleteStatement)* RIGHT_CURLY_BRACE;
/**
* deviate-not-supported-stmt =
@@ -1190,67 +1242,42 @@
maxElementsStatement? RIGHT_CURLY_BRACE));
/**
- * compiler-annotation-stmt = compiler-annotation-keyword optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [units-stmt stmtsep]
- * [reference-stmt stmtsep]
- * 1*(compiler-annotation-stmt stmtsep)
- * "}"
+ * compiler-annotation-stmt = prefix:compiler-annotation-keyword string
+ * "{"
+ * [app-data-structure-stmt stmtsep]
+ * [app-extended-stmt stmtsep]
+ * "}"
*/
- compilerAnnotationStatement : COMPILER_ANNOTATION_KEYWORD LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
- | unitsStatement | referenceStatement | annotationStatement)*
- RIGHT_CURLY_BRACE;
+ compilerAnnotationStatement : COMPILER_ANNOTATION string LEFT_CURLY_BRACE
+ compilerAnnotationBodyStatement RIGHT_CURLY_BRACE;
+
+ compilerAnnotationBodyStatement : appDataStructureStatement? appExtendedStatement? ;
/**
- * annotation-stmt = "@" annotation-type [annotation-parameter-specification] ";"
+ * app-data-structure-stmt = prefix:app-data-structure-keyword string
+ * (";" /
+ * "{"
+ * [data-structure-key-stmt stmtsep]
+ * "}")
*/
- annotationStatement : annotationType annotationParameterSpecification? STMTEND;
+ appDataStructureStatement : APP_DATA_STRUCTURE appDataStructure (STMTEND | (LEFT_CURLY_BRACE
+ dataStructureKeyStatement? RIGHT_CURLY_BRACE));
/**
- * annotation-type = identifier
+ * data-structure-key-stmt = prefix:key-keyword string ";"
*/
- annotationType : annotationIdentifier;
+ dataStructureKeyStatement : DATA_STRUCTURE_KEY string STMTEND;
/**
- * annotation-parameter-specification = "(" optsep annotation-parameter-specification-arg optsep ")"
+ * app-extended-stmt = prefix:app-extended-name-keyword string ";"
*/
- annotationParameterSpecification : LEFT_ROUND_BRACE annotationParameterSpecificationArg RIGHT_ROUND_BRACE;
-
- /**
- * annotation-parameter-specification-arg = annotation-para-type-value
- * / annotation-para-instance *("," annotation-para-instance)
- */
- annotationParameterSpecificationArg : annotationParaTypeValue
- | annotationParaInstance (COMMA annotationParaInstance)*;
-
- /**
- * annotation-para-instance = annotation-para-type-identifier optsep "=" optsep annotation-para-type-value
- */
- annotationParaInstance : annotationParaTypeIdentifier EQUAL annotationParaTypeValue;
-
- /**
- * annotation-para-type-identifier = identifier
- */
- annotationParaTypeIdentifier : identifier;
-
- /**
- * annotation-para-type-value = identifier
- */
- annotationParaTypeValue : identifier;
+ appExtendedStatement : APP_EXTENDED extendedName STMTEND;
string : STRING (PLUS STRING)*
| IDENTIFIER
| INTEGER
| yangConstruct;
- annotationIdentifier : STRING (PLUS STRING)*
- | ANNOTATION_IDENTIFIER
- | IDENTIFIER
- | yangConstruct;
-
identifier : STRING (PLUS STRING)*
| IDENTIFIER
| yangConstruct;
@@ -1296,15 +1323,19 @@
fraction : string;
+ appDataStructure : string;
+
+ extendedName : string;
+
yangConstruct : ANYXML_KEYWORD | ARGUMENT_KEYWORD | AUGMENT_KEYWORD | BASE_KEYWORD | BELONGS_TO_KEYWORD
| BIT_KEYWORD | CASE_KEYWORD | CHOICE_KEYWORD | CONFIG_KEYWORD | CONTACT_KEYWORD | CONTAINER_KEYWORD
- | DEFAULT_KEYWORD | DESCRIPTION_KEYWORD | ENUM_KEYWORD ERROR_APP_TAG_KEYWORD | ERROR_MESSAGE_KEYWORD
+ | DEFAULT_KEYWORD | DESCRIPTION_KEYWORD | ENUM_KEYWORD | ERROR_APP_TAG_KEYWORD | ERROR_MESSAGE_KEYWORD
| EXTENSION_KEYWORD | DEVIATION_KEYWORD | DEVIATE_KEYWORD | FEATURE_KEYWORD
| FRACTION_DIGITS_KEYWORD | GROUPING_KEYWORD | IDENTITY_KEYWORD | IF_FEATURE_KEYWORD
| IMPORT_KEYWORD | INCLUDE_KEYWORD | INPUT_KEYWORD | KEY_KEYWORD | LEAF_KEYWORD | LEAF_LIST_KEYWORD
| LENGTH_KEYWORD | LIST_KEYWORD | MANDATORY_KEYWORD | MAX_ELEMENTS_KEYWORD | MIN_ELEMENTS_KEYWORD
| MODULE_KEYWORD | MUST_KEYWORD | NAMESPACE_KEYWORD | NOTIFICATION_KEYWORD | ORDERED_BY_KEYWORD
- | ORGANIZATION_KEYWORD | OUTPUT_KEYWORD | PATH_KEYWORD | PATTERN_KEYWORD |POSITION_KEYWORD
+ | ORGANIZATION_KEYWORD | OUTPUT_KEYWORD | PATH_KEYWORD | PATTERN_KEYWORD | POSITION_KEYWORD
| PREFIX_KEYWORD | PRESENCE_KEYWORD | RANGE_KEYWORD | REFERENCE_KEYWORD | REFINE_KEYWORD
| REQUIRE_INSTANCE_KEYWORD | REVISION_KEYWORD | REVISION_DATE_KEYWORD | RPC_KEYWORD
| STATUS_KEYWORD | SUBMODULE_KEYWORD | TYPE_KEYWORD | TYPEDEF_KEYWORD | UNIQUE_KEYWORD
@@ -1312,4 +1343,5 @@
| YIN_ELEMENT_KEYWORD | ADD_KEYWORD | CURRENT_KEYWORD | DELETE_KEYWORD | DEPRECATED_KEYWORD
| FALSE_KEYWORD | MAX_KEYWORD | MIN_KEYWORD | NOT_SUPPORTED_KEYWORD | OBSOLETE_KEYWORD
| REPLACE_KEYWORD | SYSTEM_KEYWORD | TRUE_KEYWORD | UNBOUNDED_KEYWORD | USER_KEYWORD
- | COMPILER_ANNOTATION_KEYWORD;
+ | COMPILER_ANNOTATION_KEYWORD | APP_DATA_STRUCTURE_KEYWORD | DATA_STRUCTURE_KEYWORD
+ | APP_EXTENDED_KEYWORD;
diff --git a/plugin/src/main/resources/YangLexer.g4 b/plugin/src/main/resources/YangLexer.g4
index d1f7fea..8abe32f 100644
--- a/plugin/src/main/resources/YangLexer.g4
+++ b/plugin/src/main/resources/YangLexer.g4
@@ -101,6 +101,14 @@
UNBOUNDED_KEYWORD : 'unbounded';
USER_KEYWORD : 'user';
COMPILER_ANNOTATION_KEYWORD : 'compiler-annotation';
+ COMPILER_ANNOTATION : IDENTIFIER COLON COMPILER_ANNOTATION_KEYWORD;
+ APP_DATA_STRUCTURE_KEYWORD : 'app-data-structure';
+ APP_DATA_STRUCTURE : IDENTIFIER COLON APP_DATA_STRUCTURE_KEYWORD;
+ DATA_STRUCTURE_KEYWORD : 'data-structure';
+ DATA_STRUCTURE : IDENTIFIER COLON DATA_STRUCTURE_KEYWORD;
+ DATA_STRUCTURE_KEY : IDENTIFIER COLON KEY_KEYWORD;
+ APP_EXTENDED_KEYWORD : 'app-extended-name';
+ APP_EXTENDED : IDENTIFIER COLON APP_EXTENDED_KEYWORD;
// Lexer tokens to be skipped
COMMENT
@@ -117,18 +125,11 @@
DATE_ARG : DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT;
LEFT_CURLY_BRACE : '{';
RIGHT_CURLY_BRACE : '}';
- LEFT_ROUND_BRACE : '(';
- RIGHT_ROUND_BRACE : ')';
- ANNOTATION_START : '@';
- ANNOTATION_IDENTIFIER : ('@')(ALPHA | '_')
- (ALPHA | DIGIT | '_' | '-' | '.')*;
IDENTIFIER : (ALPHA | '_')
(ALPHA | DIGIT | '_' | '-' | '.')*;
STMTEND : ';';
DQUOTE : '"';
COLON : ':';
- COMMA : ',';
- EQUAL : '=';
PLUS : '+';
MINUS: '-';