Gaurav Agrawal
Committed by Gerrit Code Review

YANG Derived Data Type Support + Change in YANG Parser Grammar to

Support String values which are not in double quotes with UT case + 
Addition of Revision Date Validation with UT case + Removal of 
String.valueOf

Change-Id: Ic152265a35c0d2b0f84473a94ca67681cf8efca8
Showing 21 changed files with 434 additions and 58 deletions
...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.parser.Parsable; ...@@ -24,6 +24,7 @@ import org.onosproject.yangutils.parser.Parsable;
24 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener; 24 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
25 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; 25 import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
26 26
27 +import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
27 import org.onosproject.yangutils.parser.impl.listeners.KeyListener; 28 import org.onosproject.yangutils.parser.impl.listeners.KeyListener;
28 import org.onosproject.yangutils.parser.impl.listeners.LeafListListener; 29 import org.onosproject.yangutils.parser.impl.listeners.LeafListListener;
29 import org.onosproject.yangutils.parser.impl.listeners.LeafListener; 30 import org.onosproject.yangutils.parser.impl.listeners.LeafListener;
...@@ -49,6 +50,7 @@ import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener; ...@@ -49,6 +50,7 @@ import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener;
49 import org.onosproject.yangutils.parser.impl.listeners.RevisionListener; 50 import org.onosproject.yangutils.parser.impl.listeners.RevisionListener;
50 import org.onosproject.yangutils.parser.impl.listeners.StatusListener; 51 import org.onosproject.yangutils.parser.impl.listeners.StatusListener;
51 import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener; 52 import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener;
53 +import org.onosproject.yangutils.parser.impl.listeners.TypeDefListener;
52 import org.onosproject.yangutils.parser.impl.listeners.TypeListener; 54 import org.onosproject.yangutils.parser.impl.listeners.TypeListener;
53 import org.onosproject.yangutils.parser.impl.listeners.UnitsListener; 55 import org.onosproject.yangutils.parser.impl.listeners.UnitsListener;
54 import org.onosproject.yangutils.parser.impl.listeners.VersionListener; 56 import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
...@@ -519,12 +521,12 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -519,12 +521,12 @@ public class TreeWalkListener implements GeneratedYangListener {
519 521
520 @Override 522 @Override
521 public void enterTypedefStatement(GeneratedYangParser.TypedefStatementContext ctx) { 523 public void enterTypedefStatement(GeneratedYangParser.TypedefStatementContext ctx) {
522 - //TODO: implement the method. 524 + TypeDefListener.processTypeDefEntry(this, ctx);
523 } 525 }
524 526
525 @Override 527 @Override
526 public void exitTypedefStatement(GeneratedYangParser.TypedefStatementContext ctx) { 528 public void exitTypedefStatement(GeneratedYangParser.TypedefStatementContext ctx) {
527 - //TODO: implement the method. 529 + TypeDefListener.processTypeDefExit(this, ctx);
528 } 530 }
529 531
530 @Override 532 @Override
...@@ -609,7 +611,7 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -609,7 +611,7 @@ public class TreeWalkListener implements GeneratedYangListener {
609 611
610 @Override 612 @Override
611 public void enterDefaultStatement(GeneratedYangParser.DefaultStatementContext ctx) { 613 public void enterDefaultStatement(GeneratedYangParser.DefaultStatementContext ctx) {
612 - //TODO: implement the method. 614 + DefaultListener.processDefaultEntry(this, ctx);
613 } 615 }
614 616
615 @Override 617 @Override
......
...@@ -78,8 +78,8 @@ public final class BaseFileListener { ...@@ -78,8 +78,8 @@ public final class BaseFileListener {
78 checkStackIsNotEmpty(listener, MISSING_HOLDER, YANGBASE_DATA, "", EXIT); 78 checkStackIsNotEmpty(listener, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
79 79
80 // Data Model tree root node is set. 80 // Data Model tree root node is set.
81 - if (listener.getParsedDataStack().peek() instanceof YangModule 81 + if ((listener.getParsedDataStack().peek() instanceof YangModule)
82 - || listener.getParsedDataStack().peek() instanceof YangSubModule) { 82 + || (listener.getParsedDataStack().peek() instanceof YangSubModule)) {
83 listener.setRootNode((YangNode) listener.getParsedDataStack().pop()); 83 listener.setRootNode((YangNode) listener.getParsedDataStack().pop());
84 } else { 84 } else {
85 throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, YANGBASE_DATA, "", EXIT)); 85 throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, YANGBASE_DATA, "", EXIT));
......
...@@ -77,11 +77,11 @@ public final class BelongsToListener { ...@@ -77,11 +77,11 @@ public final class BelongsToListener {
77 GeneratedYangParser.BelongstoStatementContext ctx) { 77 GeneratedYangParser.BelongstoStatementContext ctx) {
78 78
79 // Check for stack to be non empty. 79 // Check for stack to be non empty.
80 - checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, String.valueOf(ctx.IDENTIFIER().getText()), 80 + checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.IDENTIFIER().getText(),
81 ENTRY); 81 ENTRY);
82 82
83 YangBelongsTo belongstoNode = new YangBelongsTo(); 83 YangBelongsTo belongstoNode = new YangBelongsTo();
84 - belongstoNode.setBelongsToModuleName(String.valueOf(ctx.IDENTIFIER().getText())); 84 + belongstoNode.setBelongsToModuleName(ctx.IDENTIFIER().getText());
85 85
86 // Push belongsto into the stack. 86 // Push belongsto into the stack.
87 listener.getParsedDataStack().push(belongstoNode); 87 listener.getParsedDataStack().push(belongstoNode);
...@@ -98,7 +98,7 @@ public final class BelongsToListener { ...@@ -98,7 +98,7 @@ public final class BelongsToListener {
98 GeneratedYangParser.BelongstoStatementContext ctx) { 98 GeneratedYangParser.BelongstoStatementContext ctx) {
99 99
100 // Check for stack to be non empty. 100 // Check for stack to be non empty.
101 - checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, String.valueOf(ctx.IDENTIFIER().getText()), 101 + checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.IDENTIFIER().getText(),
102 EXIT); 102 EXIT);
103 103
104 Parsable tmpBelongstoNode = listener.getParsedDataStack().peek(); 104 Parsable tmpBelongstoNode = listener.getParsedDataStack().peek();
...@@ -107,7 +107,7 @@ public final class BelongsToListener { ...@@ -107,7 +107,7 @@ public final class BelongsToListener {
107 107
108 // Check for stack to be empty. 108 // Check for stack to be empty.
109 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, 109 checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA,
110 - String.valueOf(ctx.IDENTIFIER().getText()), EXIT); 110 + ctx.IDENTIFIER().getText(), EXIT);
111 111
112 Parsable tmpNode = listener.getParsedDataStack().peek(); 112 Parsable tmpNode = listener.getParsedDataStack().peek();
113 switch (tmpNode.getParsableDataType()) { 113 switch (tmpNode.getParsableDataType()) {
...@@ -118,12 +118,12 @@ public final class BelongsToListener { ...@@ -118,12 +118,12 @@ public final class BelongsToListener {
118 } 118 }
119 default: 119 default:
120 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BELONGS_TO_DATA, 120 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BELONGS_TO_DATA,
121 - String.valueOf(ctx.IDENTIFIER().getText()), 121 + ctx.IDENTIFIER().getText(),
122 EXIT)); 122 EXIT));
123 } 123 }
124 } else { 124 } else {
125 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA, 125 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA,
126 - String.valueOf(ctx.IDENTIFIER().getText()), EXIT)); 126 + ctx.IDENTIFIER().getText(), EXIT));
127 } 127 }
128 } 128 }
129 } 129 }
......
...@@ -92,24 +92,24 @@ public final class ContactListener { ...@@ -92,24 +92,24 @@ public final class ContactListener {
92 public static void processContactEntry(TreeWalkListener listener, GeneratedYangParser.ContactStatementContext ctx) { 92 public static void processContactEntry(TreeWalkListener listener, GeneratedYangParser.ContactStatementContext ctx) {
93 93
94 // Check for stack to be non empty. 94 // Check for stack to be non empty.
95 - checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTACT_DATA, String.valueOf(ctx.string().getText()), ENTRY); 95 + checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTACT_DATA, ctx.string().getText(), ENTRY);
96 96
97 // Obtain the node of the stack. 97 // Obtain the node of the stack.
98 Parsable tmpNode = listener.getParsedDataStack().peek(); 98 Parsable tmpNode = listener.getParsedDataStack().peek();
99 switch (tmpNode.getParsableDataType()) { 99 switch (tmpNode.getParsableDataType()) {
100 case MODULE_DATA: { 100 case MODULE_DATA: {
101 YangModule module = (YangModule) tmpNode; 101 YangModule module = (YangModule) tmpNode;
102 - module.setContact(String.valueOf(ctx.string().getText())); 102 + module.setContact(ctx.string().getText());
103 break; 103 break;
104 } 104 }
105 case SUB_MODULE_DATA: { 105 case SUB_MODULE_DATA: {
106 YangSubModule subModule = (YangSubModule) tmpNode; 106 YangSubModule subModule = (YangSubModule) tmpNode;
107 - subModule.setContact(String.valueOf(ctx.string().getText())); 107 + subModule.setContact(ctx.string().getText());
108 break; 108 break;
109 } 109 }
110 default: 110 default:
111 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, 111 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
112 - String.valueOf(ctx.string().getText()), ENTRY)); 112 + ctx.string().getText(), ENTRY));
113 } 113 }
114 } 114 }
115 } 115 }
......
1 +/*
2 + * Copyright 2014-2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +/*
20 + * Reference: RFC6020 and YANG ANTLR Grammar
21 + *
22 + * typedef-stmt = typedef-keyword sep identifier-arg-str optsep
23 + * "{" stmtsep
24 + * ;; these stmts can appear in any order
25 + * type-stmt stmtsep
26 + * [units-stmt stmtsep]
27 + * [default-stmt stmtsep]
28 + * [status-stmt stmtsep]
29 + * [description-stmt stmtsep]
30 + * [reference-stmt stmtsep]
31 + * "}"
32 + * default-stmt = default-keyword sep string stmtend
33 +
34 + *
35 + * ANTLR grammar rule
36 + * typedefStatement : TYPEDEF_KEYWORD IDENTIFIER LEFT_CURLY_BRACE
37 + * (typeStatement | unitsStatement | defaultStatement | statusStatement
38 + * | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
39 + * defaultStatement : DEFAULT_KEYWORD string STMTEND;
40 + */
41 +
42 +import org.onosproject.yangutils.datamodel.YangTypeDef;
43 +import org.onosproject.yangutils.parser.Parsable;
44 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
45 +import org.onosproject.yangutils.parser.exceptions.ParserException;
46 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
47 +
48 +import static org.onosproject.yangutils.parser.ParsableDataType.DEFAULT_DATA;
49 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
50 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
51 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
52 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
53 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
54 +
55 +public final class DefaultListener {
56 +
57 + /**
58 + * Creates a new default listener.
59 + */
60 + private DefaultListener() {
61 + }
62 +
63 + /**
64 + * It is called when parser enters grammar rule (default), it perform
65 + * validations and updates the data model tree.
66 + *
67 + * @param listener listener's object.
68 + * @param ctx context object of the grammar rule.
69 + */
70 + public static void processDefaultEntry(TreeWalkListener listener,
71 + GeneratedYangParser.DefaultStatementContext ctx) {
72 +
73 + // Check for stack to be non empty.
74 + checkStackIsNotEmpty(listener, MISSING_HOLDER, DEFAULT_DATA, ctx.string().getText(), ENTRY);
75 +
76 + Parsable tmpNode = listener.getParsedDataStack().peek();
77 + switch (tmpNode.getParsableDataType()) {
78 + case TYPEDEF_DATA: {
79 + YangTypeDef typeDef = (YangTypeDef) tmpNode;
80 + typeDef.setDefaultValueInString(ctx.string().getText());
81 + break;
82 + }
83 + default:
84 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
85 + DEFAULT_DATA, ctx.string().getText(), ENTRY));
86 + }
87 + }
88 +}
...@@ -75,10 +75,10 @@ public final class ImportListener { ...@@ -75,10 +75,10 @@ public final class ImportListener {
75 public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { 75 public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
76 76
77 // Check for stack to be non empty. 77 // Check for stack to be non empty.
78 - checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, String.valueOf(ctx.IDENTIFIER().getText()), ENTRY); 78 + checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.IDENTIFIER().getText(), ENTRY);
79 79
80 YangImport importNode = new YangImport(); 80 YangImport importNode = new YangImport();
81 - importNode.setModuleName(String.valueOf(ctx.IDENTIFIER().getText())); 81 + importNode.setModuleName(ctx.IDENTIFIER().getText());
82 82
83 // Push import node to the stack. 83 // Push import node to the stack.
84 listener.getParsedDataStack().push(importNode); 84 listener.getParsedDataStack().push(importNode);
...@@ -94,14 +94,14 @@ public final class ImportListener { ...@@ -94,14 +94,14 @@ public final class ImportListener {
94 public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { 94 public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
95 95
96 // Check for stack to be non empty. 96 // Check for stack to be non empty.
97 - checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, String.valueOf(ctx.IDENTIFIER().getText()), EXIT); 97 + checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.IDENTIFIER().getText(), EXIT);
98 98
99 Parsable tmpImportNode = listener.getParsedDataStack().peek(); 99 Parsable tmpImportNode = listener.getParsedDataStack().peek();
100 if (tmpImportNode instanceof YangImport) { 100 if (tmpImportNode instanceof YangImport) {
101 listener.getParsedDataStack().pop(); 101 listener.getParsedDataStack().pop();
102 102
103 // Check for stack to be non empty. 103 // Check for stack to be non empty.
104 - checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, String.valueOf(ctx.IDENTIFIER().getText()), 104 + checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.IDENTIFIER().getText(),
105 EXIT); 105 EXIT);
106 106
107 Parsable tmpNode = listener.getParsedDataStack().peek(); 107 Parsable tmpNode = listener.getParsedDataStack().peek();
...@@ -118,12 +118,12 @@ public final class ImportListener { ...@@ -118,12 +118,12 @@ public final class ImportListener {
118 } 118 }
119 default: 119 default:
120 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IMPORT_DATA, 120 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IMPORT_DATA,
121 - String.valueOf(ctx.IDENTIFIER().getText()), 121 + ctx.IDENTIFIER().getText(),
122 EXIT)); 122 EXIT));
123 } 123 }
124 } else { 124 } else {
125 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA, 125 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA,
126 - String.valueOf(ctx.IDENTIFIER().getText()), EXIT)); 126 + ctx.IDENTIFIER().getText(), EXIT));
127 } 127 }
128 } 128 }
129 } 129 }
......
...@@ -74,11 +74,11 @@ public final class IncludeListener { ...@@ -74,11 +74,11 @@ public final class IncludeListener {
74 public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { 74 public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
75 75
76 // Check for stack to be non empty. 76 // Check for stack to be non empty.
77 - checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), 77 + checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.IDENTIFIER().getText(),
78 ENTRY); 78 ENTRY);
79 79
80 YangInclude includeNode = new YangInclude(); 80 YangInclude includeNode = new YangInclude();
81 - includeNode.setSubModuleName(String.valueOf(ctx.IDENTIFIER().getText())); 81 + includeNode.setSubModuleName(ctx.IDENTIFIER().getText());
82 82
83 listener.getParsedDataStack().push(includeNode); 83 listener.getParsedDataStack().push(includeNode);
84 } 84 }
...@@ -93,14 +93,14 @@ public final class IncludeListener { ...@@ -93,14 +93,14 @@ public final class IncludeListener {
93 public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { 93 public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
94 94
95 // Check for stack to be non empty. 95 // Check for stack to be non empty.
96 - checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), EXIT); 96 + checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.IDENTIFIER().getText(), EXIT);
97 97
98 Parsable tmpIncludeNode = listener.getParsedDataStack().peek(); 98 Parsable tmpIncludeNode = listener.getParsedDataStack().peek();
99 if (tmpIncludeNode instanceof YangInclude) { 99 if (tmpIncludeNode instanceof YangInclude) {
100 listener.getParsedDataStack().pop(); 100 listener.getParsedDataStack().pop();
101 101
102 // Check for stack to be non empty. 102 // Check for stack to be non empty.
103 - checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), 103 + checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.IDENTIFIER().getText(),
104 EXIT); 104 EXIT);
105 105
106 Parsable tmpNode = listener.getParsedDataStack().peek(); 106 Parsable tmpNode = listener.getParsedDataStack().peek();
...@@ -117,12 +117,12 @@ public final class IncludeListener { ...@@ -117,12 +117,12 @@ public final class IncludeListener {
117 } 117 }
118 default: 118 default:
119 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INCLUDE_DATA, 119 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INCLUDE_DATA,
120 - String.valueOf(ctx.IDENTIFIER().getText()), 120 + ctx.IDENTIFIER().getText(),
121 EXIT)); 121 EXIT));
122 } 122 }
123 } else { 123 } else {
124 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA, 124 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA,
125 - String.valueOf(ctx.IDENTIFIER().getText()), EXIT)); 125 + ctx.IDENTIFIER().getText(), EXIT));
126 } 126 }
127 } 127 }
128 } 128 }
......
...@@ -69,7 +69,7 @@ public final class ModuleListener { ...@@ -69,7 +69,7 @@ public final class ModuleListener {
69 public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) { 69 public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
70 70
71 // Check if stack is empty. 71 // Check if stack is empty.
72 - checkStackIsEmpty(listener, INVALID_HOLDER, MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), ENTRY); 72 + checkStackIsEmpty(listener, INVALID_HOLDER, MODULE_DATA, ctx.IDENTIFIER().getText(), ENTRY);
73 73
74 YangModule yangModule = new YangModule(); 74 YangModule yangModule = new YangModule();
75 yangModule.setName(ctx.IDENTIFIER().getText()); 75 yangModule.setName(ctx.IDENTIFIER().getText());
...@@ -87,11 +87,11 @@ public final class ModuleListener { ...@@ -87,11 +87,11 @@ public final class ModuleListener {
87 public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) { 87 public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
88 88
89 // Check for stack to be non empty. 89 // Check for stack to be non empty.
90 - checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), EXIT); 90 + checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.IDENTIFIER().getText(), EXIT);
91 91
92 if (!(listener.getParsedDataStack().peek() instanceof YangModule)) { 92 if (!(listener.getParsedDataStack().peek() instanceof YangModule)) {
93 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA, 93 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
94 - String.valueOf(ctx.IDENTIFIER().getText()), EXIT)); 94 + ctx.IDENTIFIER().getText(), EXIT));
95 } 95 }
96 } 96 }
97 } 97 }
......
...@@ -77,9 +77,9 @@ public final class NamespaceListener { ...@@ -77,9 +77,9 @@ public final class NamespaceListener {
77 GeneratedYangParser.NamespaceStatementContext ctx) { 77 GeneratedYangParser.NamespaceStatementContext ctx) {
78 78
79 // Check for stack to be non empty. 79 // Check for stack to be non empty.
80 - checkStackIsNotEmpty(listener, MISSING_HOLDER, NAMESPACE_DATA, String.valueOf(ctx.string().getText()), ENTRY); 80 + checkStackIsNotEmpty(listener, MISSING_HOLDER, NAMESPACE_DATA, ctx.string().getText(), ENTRY);
81 81
82 - if (!validateUriValue(String.valueOf(ctx.string().getText()))) { 82 + if (!validateUriValue(ctx.string().getText())) {
83 ParserException parserException = new ParserException("Invalid namespace URI"); 83 ParserException parserException = new ParserException("Invalid namespace URI");
84 parserException.setLine(ctx.string().STRING(0).getSymbol().getLine()); 84 parserException.setLine(ctx.string().STRING(0).getSymbol().getLine());
85 parserException.setCharPosition(ctx.string().STRING(0).getSymbol().getCharPositionInLine()); 85 parserException.setCharPosition(ctx.string().STRING(0).getSymbol().getCharPositionInLine());
...@@ -92,13 +92,13 @@ public final class NamespaceListener { ...@@ -92,13 +92,13 @@ public final class NamespaceListener {
92 case MODULE_DATA: { 92 case MODULE_DATA: {
93 YangModule module = (YangModule) tmpNode; 93 YangModule module = (YangModule) tmpNode;
94 YangNameSpace uri = new YangNameSpace(); 94 YangNameSpace uri = new YangNameSpace();
95 - uri.setUri(String.valueOf(ctx.string().getText())); 95 + uri.setUri(ctx.string().getText());
96 module.setNameSpace(uri); 96 module.setNameSpace(uri);
97 break; 97 break;
98 } 98 }
99 default: 99 default:
100 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, NAMESPACE_DATA, 100 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, NAMESPACE_DATA,
101 - String.valueOf(ctx.string().getText()), ENTRY)); 101 + ctx.string().getText(), ENTRY));
102 } 102 }
103 } 103 }
104 104
......
...@@ -95,7 +95,7 @@ public final class OrganizationListener { ...@@ -95,7 +95,7 @@ public final class OrganizationListener {
95 GeneratedYangParser.OrganizationStatementContext ctx) { 95 GeneratedYangParser.OrganizationStatementContext ctx) {
96 96
97 // Check for stack to be non empty. 97 // Check for stack to be non empty.
98 - checkStackIsNotEmpty(listener, MISSING_HOLDER, ORGANIZATION_DATA, String.valueOf(ctx.string().getText()), 98 + checkStackIsNotEmpty(listener, MISSING_HOLDER, ORGANIZATION_DATA, ctx.string().getText(),
99 ENTRY); 99 ENTRY);
100 100
101 // Obtain the node of the stack. 101 // Obtain the node of the stack.
...@@ -103,17 +103,17 @@ public final class OrganizationListener { ...@@ -103,17 +103,17 @@ public final class OrganizationListener {
103 switch (tmpNode.getParsableDataType()) { 103 switch (tmpNode.getParsableDataType()) {
104 case MODULE_DATA: { 104 case MODULE_DATA: {
105 YangModule module = (YangModule) tmpNode; 105 YangModule module = (YangModule) tmpNode;
106 - module.setOrganization(String.valueOf(ctx.string().getText())); 106 + module.setOrganization(ctx.string().getText());
107 break; 107 break;
108 } 108 }
109 case SUB_MODULE_DATA: { 109 case SUB_MODULE_DATA: {
110 YangSubModule subModule = (YangSubModule) tmpNode; 110 YangSubModule subModule = (YangSubModule) tmpNode;
111 - subModule.setOrganization(String.valueOf(ctx.string().getText())); 111 + subModule.setOrganization(ctx.string().getText());
112 break; 112 break;
113 } 113 }
114 default: 114 default:
115 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ORGANIZATION_DATA, 115 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ORGANIZATION_DATA,
116 - String.valueOf(ctx.string().getText()), ENTRY)); 116 + ctx.string().getText(), ENTRY));
117 } 117 }
118 } 118 }
119 } 119 }
......
...@@ -76,7 +76,7 @@ public final class PrefixListener { ...@@ -76,7 +76,7 @@ public final class PrefixListener {
76 public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) { 76 public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) {
77 77
78 // Check for stack to be non empty. 78 // Check for stack to be non empty.
79 - checkStackIsNotEmpty(listener, MISSING_HOLDER, PREFIX_DATA, String.valueOf(ctx.IDENTIFIER().getText()), ENTRY); 79 + checkStackIsNotEmpty(listener, MISSING_HOLDER, PREFIX_DATA, ctx.IDENTIFIER().getText(), ENTRY);
80 80
81 // Obtain the node of the stack. 81 // Obtain the node of the stack.
82 Parsable tmpNode = listener.getParsedDataStack().peek(); 82 Parsable tmpNode = listener.getParsedDataStack().peek();
...@@ -98,7 +98,7 @@ public final class PrefixListener { ...@@ -98,7 +98,7 @@ public final class PrefixListener {
98 } 98 }
99 default: 99 default:
100 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PREFIX_DATA, 100 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PREFIX_DATA,
101 - String.valueOf(ctx.IDENTIFIER().getText()), ENTRY)); 101 + ctx.IDENTIFIER().getText(), ENTRY));
102 } 102 }
103 } 103 }
104 } 104 }
......
...@@ -23,6 +23,10 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; ...@@ -23,6 +23,10 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
23 import org.onosproject.yangutils.parser.exceptions.ParserException; 23 import org.onosproject.yangutils.parser.exceptions.ParserException;
24 import org.onosproject.yangutils.parser.impl.TreeWalkListener; 24 import org.onosproject.yangutils.parser.impl.TreeWalkListener;
25 25
26 +import java.text.ParseException;
27 +import java.text.SimpleDateFormat;
28 +import java.util.Date;
29 +
26 import static org.onosproject.yangutils.parser.ParsableDataType.REVISION_DATE_DATA; 30 import static org.onosproject.yangutils.parser.ParsableDataType.REVISION_DATE_DATA;
27 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; 31 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
28 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; 32 import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
...@@ -82,26 +86,57 @@ public final class RevisionDateListener { ...@@ -82,26 +86,57 @@ public final class RevisionDateListener {
82 GeneratedYangParser.RevisionDateStatementContext ctx) { 86 GeneratedYangParser.RevisionDateStatementContext ctx) {
83 87
84 // Check for stack to be non empty. 88 // Check for stack to be non empty.
85 - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, String.valueOf(ctx.DATE_ARG().getText()), 89 + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.DATE_ARG().getText(),
86 ENTRY); 90 ENTRY);
87 91
92 + if (!isDateValid(ctx.DATE_ARG().getText())) {
93 + ParserException parserException = new ParserException("Input date is not correct");
94 + parserException.setLine(ctx.DATE_ARG().getSymbol().getLine());
95 + parserException.setCharPosition(ctx.DATE_ARG().getSymbol().getCharPositionInLine());
96 + throw parserException;
97 + }
98 +
88 // Obtain the node of the stack. 99 // Obtain the node of the stack.
89 Parsable tmpNode = listener.getParsedDataStack().peek(); 100 Parsable tmpNode = listener.getParsedDataStack().peek();
90 switch (tmpNode.getParsableDataType()) { 101 switch (tmpNode.getParsableDataType()) {
91 case IMPORT_DATA: { 102 case IMPORT_DATA: {
92 YangImport importNode = (YangImport) tmpNode; 103 YangImport importNode = (YangImport) tmpNode;
93 - importNode.setRevision(String.valueOf(ctx.DATE_ARG().getText())); 104 + importNode.setRevision(ctx.DATE_ARG().getText());
94 break; 105 break;
95 } 106 }
96 case INCLUDE_DATA: { 107 case INCLUDE_DATA: {
97 YangInclude includeNode = (YangInclude) tmpNode; 108 YangInclude includeNode = (YangInclude) tmpNode;
98 - includeNode.setRevision(String.valueOf(ctx.DATE_ARG().getText())); 109 + includeNode.setRevision(ctx.DATE_ARG().getText());
99 break; 110 break;
100 } 111 }
101 default: 112 default:
102 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATE_DATA, 113 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATE_DATA,
103 - String.valueOf(ctx.DATE_ARG().getText()), ENTRY)); 114 + ctx.DATE_ARG().getText(), ENTRY));
115 + }
116 + }
117 +
118 + /**
119 + * Validates the revision date.
120 + *
121 + * @param dateToValidate input revision date.
122 + * @return validation result, true for success, false for failure.
123 + */
124 + private static boolean isDateValid(String dateToValidate) {
125 +
126 + if (dateToValidate == null) {
127 + return false;
128 + }
129 +
130 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
131 + sdf.setLenient(false);
132 +
133 + try {
134 + //if not valid, it will throw ParseException
135 + Date date = sdf.parse(dateToValidate);
136 + System.out.println(date);
137 + } catch (ParseException e) {
138 + return false;
104 } 139 }
140 + return true;
105 } 141 }
106 - // TODO Implement the DATE_ARG validation as per RFC 6020.
107 } 142 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -82,7 +82,7 @@ public final class RevisionListener { ...@@ -82,7 +82,7 @@ public final class RevisionListener {
82 GeneratedYangParser.RevisionStatementContext ctx) { 82 GeneratedYangParser.RevisionStatementContext ctx) {
83 83
84 // Check for stack to be non empty. 84 // Check for stack to be non empty.
85 - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, String.valueOf(ctx.DATE_ARG().getText()), ENTRY); 85 + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.DATE_ARG().getText(), ENTRY);
86 86
87 // Validate for reverse chronological order of revision & for revision 87 // Validate for reverse chronological order of revision & for revision
88 // value. 88 // value.
...@@ -92,7 +92,7 @@ public final class RevisionListener { ...@@ -92,7 +92,7 @@ public final class RevisionListener {
92 } 92 }
93 93
94 YangRevision revisionNode = new YangRevision(); 94 YangRevision revisionNode = new YangRevision();
95 - revisionNode.setRevDate(String.valueOf(ctx.DATE_ARG().getText())); 95 + revisionNode.setRevDate(ctx.DATE_ARG().getText());
96 96
97 listener.getParsedDataStack().push(revisionNode); 97 listener.getParsedDataStack().push(revisionNode);
98 } 98 }
...@@ -108,14 +108,14 @@ public final class RevisionListener { ...@@ -108,14 +108,14 @@ public final class RevisionListener {
108 ctx) { 108 ctx) {
109 109
110 // Check for stack to be non empty. 110 // Check for stack to be non empty.
111 - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, String.valueOf(ctx.DATE_ARG().getText()), EXIT); 111 + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.DATE_ARG().getText(), EXIT);
112 112
113 Parsable tmpRevisionNode = listener.getParsedDataStack().peek(); 113 Parsable tmpRevisionNode = listener.getParsedDataStack().peek();
114 if (tmpRevisionNode instanceof YangRevision) { 114 if (tmpRevisionNode instanceof YangRevision) {
115 listener.getParsedDataStack().pop(); 115 listener.getParsedDataStack().pop();
116 116
117 // Check for stack to be non empty. 117 // Check for stack to be non empty.
118 - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, String.valueOf(ctx.DATE_ARG().getText()), 118 + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.DATE_ARG().getText(),
119 EXIT); 119 EXIT);
120 120
121 Parsable tmpNode = listener.getParsedDataStack().peek(); 121 Parsable tmpNode = listener.getParsedDataStack().peek();
...@@ -132,12 +132,12 @@ public final class RevisionListener { ...@@ -132,12 +132,12 @@ public final class RevisionListener {
132 } 132 }
133 default: 133 default:
134 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATA, 134 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATA,
135 - String.valueOf(ctx.DATE_ARG().getText()), 135 + ctx.DATE_ARG().getText(),
136 EXIT)); 136 EXIT));
137 } 137 }
138 } else { 138 } else {
139 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, REVISION_DATA, 139 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, REVISION_DATA,
140 - String.valueOf(ctx.DATE_ARG().getText()), EXIT)); 140 + ctx.DATE_ARG().getText(), EXIT));
141 } 141 }
142 } 142 }
143 143
......
...@@ -71,7 +71,7 @@ public final class SubModuleListener { ...@@ -71,7 +71,7 @@ public final class SubModuleListener {
71 GeneratedYangParser.SubModuleStatementContext ctx) { 71 GeneratedYangParser.SubModuleStatementContext ctx) {
72 72
73 // Check if stack is empty. 73 // Check if stack is empty.
74 - checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), 74 + checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, ctx.IDENTIFIER().getText(),
75 ENTRY); 75 ENTRY);
76 76
77 YangSubModule yangSubModule = new YangSubModule(); 77 YangSubModule yangSubModule = new YangSubModule();
...@@ -91,12 +91,12 @@ public final class SubModuleListener { ...@@ -91,12 +91,12 @@ public final class SubModuleListener {
91 GeneratedYangParser.SubModuleStatementContext ctx) { 91 GeneratedYangParser.SubModuleStatementContext ctx) {
92 92
93 // Check for stack to be non empty. 93 // Check for stack to be non empty.
94 - checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), 94 + checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.IDENTIFIER().getText(),
95 EXIT); 95 EXIT);
96 96
97 if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) { 97 if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) {
98 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA, 98 throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
99 - String.valueOf(ctx.IDENTIFIER().getText()), EXIT)); 99 + ctx.IDENTIFIER().getText(), EXIT));
100 } 100 }
101 } 101 }
102 } 102 }
......
1 +/*
2 + * Copyright 2014-2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +/*
20 + * Reference: RFC6020 and YANG ANTLR Grammar
21 + *
22 + * body-stmts = *((extension-stmt /
23 + * feature-stmt /
24 + * identity-stmt /
25 + * typedef-stmt /
26 + * grouping-stmt /
27 + * data-def-stmt /
28 + * augment-stmt /
29 + * rpc-stmt /
30 + * notification-stmt /
31 + * deviation-stmt) stmtsep)
32 + *
33 + * typedef-stmt = typedef-keyword sep identifier-arg-str optsep
34 + * "{" stmtsep
35 + * ;; these stmts can appear in any order
36 + * type-stmt stmtsep
37 + * [units-stmt stmtsep]
38 + * [default-stmt stmtsep]
39 + * [status-stmt stmtsep]
40 + * [description-stmt stmtsep]
41 + * [reference-stmt stmtsep]
42 + * "}"
43 + *
44 + * ANTLR grammar rule
45 + * typedefStatement : TYPEDEF_KEYWORD IDENTIFIER LEFT_CURLY_BRACE
46 + * (typeStatement | unitsStatement | defaultStatement | statusStatement
47 + * | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
48 + */
49 +
50 +import org.onosproject.yangutils.datamodel.YangContainer;
51 +import org.onosproject.yangutils.datamodel.YangList;
52 +import org.onosproject.yangutils.datamodel.YangModule;
53 +import org.onosproject.yangutils.datamodel.YangNode;
54 +import org.onosproject.yangutils.datamodel.YangSubModule;
55 +import org.onosproject.yangutils.datamodel.YangTypeDef;
56 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
57 +import org.onosproject.yangutils.parser.Parsable;
58 +import org.onosproject.yangutils.parser.ParsableDataType;
59 +import static org.onosproject.yangutils.parser.ParsableDataType.TYPEDEF_DATA;
60 +import static org.onosproject.yangutils.parser.ParsableDataType.UNITS_DATA;
61 +import static org.onosproject.yangutils.parser.ParsableDataType.DEFAULT_DATA;
62 +import static org.onosproject.yangutils.parser.ParsableDataType.TYPE_DATA;
63 +import static org.onosproject.yangutils.parser.ParsableDataType.DESCRIPTION_DATA;
64 +import static org.onosproject.yangutils.parser.ParsableDataType.REFERENCE_DATA;
65 +import static org.onosproject.yangutils.parser.ParsableDataType.STATUS_DATA;
66 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
67 +import org.onosproject.yangutils.parser.exceptions.ParserException;
68 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
69 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
70 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
71 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
72 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
73 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
74 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
75 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CARDINALITY;
76 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
77 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
78 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
79 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
80 +
81 +/**
82 + * Implements listener based call back function corresponding to the "typedef"
83 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
84 + */
85 +public final class TypeDefListener {
86 +
87 + private static ParsableDataType yangConstruct;
88 +
89 + /**
90 + * Creates a new typedef listener.
91 + */
92 + private TypeDefListener() {
93 + }
94 +
95 + /**
96 + * It is called when parser enters grammar rule (typedef), it perform
97 + * validations and updates the data model tree.
98 + *
99 + * @param listener listener's object.
100 + * @param ctx context object of the grammar rule.
101 + */
102 + public static void processTypeDefEntry(TreeWalkListener listener,
103 + GeneratedYangParser.TypedefStatementContext ctx) {
104 +
105 + // Check for stack to be non empty.
106 + checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.IDENTIFIER().getText(), ENTRY);
107 +
108 + boolean result = validateSubStatementsCardinality(ctx);
109 + if (!result) {
110 + throw new ParserException(constructListenerErrorMessage(INVALID_CARDINALITY, yangConstruct, "", ENTRY));
111 + }
112 +
113 + YangTypeDef typeDefNode = new YangTypeDef();
114 + typeDefNode.setDerivedName(ctx.IDENTIFIER().getText());
115 +
116 + Parsable curData = listener.getParsedDataStack().peek();
117 +
118 + if (curData instanceof YangModule | curData instanceof YangSubModule | curData instanceof YangContainer
119 + | curData instanceof YangList) {
120 + /*
121 + * TODO YangGrouping, YangRpc, YangInput, YangOutput, Notification.
122 + */
123 + YangNode curNode = (YangNode) curData;
124 + try {
125 + curNode.addChild(typeDefNode);
126 + } catch (DataModelException e) {
127 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
128 + TYPEDEF_DATA, ctx.IDENTIFIER().getText(), ENTRY, e.getMessage()));
129 + }
130 + listener.getParsedDataStack().push(typeDefNode);
131 + } else {
132 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
133 + TYPEDEF_DATA, ctx.IDENTIFIER().getText(), ENTRY));
134 + }
135 + }
136 +
137 + /**
138 + * It is called when parser exits from grammar rule (typedef), it perform
139 + * validations and updates the data model tree.
140 + *
141 + * @param listener listener's object.
142 + * @param ctx context object of the grammar rule.
143 + */
144 + public static void processTypeDefExit(TreeWalkListener listener,
145 + GeneratedYangParser.TypedefStatementContext ctx) {
146 +
147 + // Check for stack to be non empty.
148 + checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.IDENTIFIER().getText(), EXIT);
149 +
150 + if (listener.getParsedDataStack().peek() instanceof YangTypeDef) {
151 + listener.getParsedDataStack().pop();
152 + } else {
153 + listener.getErrorInformation().setErrorFlag(true);
154 + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, TYPEDEF_DATA,
155 + ctx.IDENTIFIER().getText(), EXIT));
156 + }
157 + }
158 +
159 + /**
160 + * Validates the cardinality of typedef sub-statements as per grammar.
161 + *
162 + * @param ctx context object of the grammar rule.
163 + * @return true/false validation success or failure.
164 + */
165 + private static boolean validateSubStatementsCardinality(GeneratedYangParser.TypedefStatementContext ctx) {
166 +
167 + if ((!ctx.unitsStatement().isEmpty())
168 + && (ctx.unitsStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
169 + yangConstruct = UNITS_DATA;
170 + return false;
171 + }
172 +
173 + if ((!ctx.defaultStatement().isEmpty())
174 + && (ctx.defaultStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
175 + yangConstruct = DEFAULT_DATA;
176 + return false;
177 + }
178 +
179 + if (ctx.typeStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY) {
180 + yangConstruct = TYPE_DATA;
181 + return false;
182 + }
183 +
184 + if ((!ctx.descriptionStatement().isEmpty())
185 + && (ctx.descriptionStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
186 + yangConstruct = DESCRIPTION_DATA;
187 + return false;
188 + }
189 +
190 + if ((!ctx.referenceStatement().isEmpty())
191 + && (ctx.referenceStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
192 + yangConstruct = REFERENCE_DATA;
193 + return false;
194 + }
195 +
196 + if ((!ctx.statusStatement().isEmpty())
197 + && (ctx.statusStatement().size() != YangUtilsParserManager.SUB_STATEMENT_CARDINALITY)) {
198 + yangConstruct = STATUS_DATA;
199 + return false;
200 + }
201 + return true;
202 + }
203 +}
...@@ -85,7 +85,7 @@ public final class VersionListener { ...@@ -85,7 +85,7 @@ public final class VersionListener {
85 GeneratedYangParser.YangVersionStatementContext ctx) { 85 GeneratedYangParser.YangVersionStatementContext ctx) {
86 86
87 // Check for stack to be non empty. 87 // Check for stack to be non empty.
88 - checkStackIsNotEmpty(listener, MISSING_HOLDER, VERSION_DATA, String.valueOf(ctx.INTEGER().getText()), ENTRY); 88 + checkStackIsNotEmpty(listener, MISSING_HOLDER, VERSION_DATA, ctx.INTEGER().getText(), ENTRY);
89 89
90 Integer version = Integer.valueOf(ctx.INTEGER().getText()); 90 Integer version = Integer.valueOf(ctx.INTEGER().getText());
91 if (!isVersionValid(version)) { 91 if (!isVersionValid(version)) {
...@@ -110,7 +110,7 @@ public final class VersionListener { ...@@ -110,7 +110,7 @@ public final class VersionListener {
110 } 110 }
111 default: 111 default:
112 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, VERSION_DATA, 112 throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, VERSION_DATA,
113 - String.valueOf(ctx.INTEGER().getText()), ENTRY)); 113 + ctx.INTEGER().getText(), ENTRY));
114 } 114 }
115 } 115 }
116 116
......
...@@ -1220,4 +1220,6 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -1220,4 +1220,6 @@ package org.onosproject.yangutils.parser.antlrgencode;
1220 defaultStatement? configStatement? mandatoryStatement? minElementsStatement? 1220 defaultStatement? configStatement? mandatoryStatement? minElementsStatement?
1221 maxElementsStatement? RIGHT_CURLY_BRACE)); 1221 maxElementsStatement? RIGHT_CURLY_BRACE));
1222 1222
1223 - string : STRING (PLUS STRING)*; 1223 + string : STRING (PLUS STRING)*
1224 + | IDENTIFIER
1225 + | INTEGER;
......
...@@ -47,7 +47,7 @@ public class ContactListenerTest { ...@@ -47,7 +47,7 @@ public class ContactListenerTest {
47 47
48 YangNode node = manager.getDataModel("src/test/resources/ContactValidEntry.yang"); 48 YangNode node = manager.getDataModel("src/test/resources/ContactValidEntry.yang");
49 49
50 - // Checks for the version value in data model tree. 50 + // Checks for the contact value in data model tree.
51 assertThat(((YangModule) node).getContact(), is("\"WG List: <mailto:spring@ietf.org>\nEditor: " 51 assertThat(((YangModule) node).getContact(), is("\"WG List: <mailto:spring@ietf.org>\nEditor: "
52 + "Stephane Litkowski\n " + "<mailto:stephane.litkowski@orange.com>\"")); 52 + "Stephane Litkowski\n " + "<mailto:stephane.litkowski@orange.com>\""));
53 } 53 }
...@@ -63,6 +63,18 @@ public class ContactListenerTest { ...@@ -63,6 +63,18 @@ public class ContactListenerTest {
63 } 63 }
64 64
65 /** 65 /**
66 + * Checks that contact can have a string value without double quotes.
67 + */
68 + @Test
69 + public void processContactWithoutQuotes() throws IOException, ParserException {
70 +
71 + YangNode node = manager.getDataModel("src/test/resources/ContactWithoutQuotes.yang");
72 +
73 + // Checks for the contact value in data model tree.
74 + assertThat(((YangModule) node).getContact(), is("WG"));
75 + }
76 +
77 + /**
66 * Checks if contact is not empty. 78 * Checks if contact is not empty.
67 */ 79 */
68 @Test(expected = ParserException.class) 80 @Test(expected = ParserException.class)
......
...@@ -80,6 +80,15 @@ public class RevisionDateListenerTest { ...@@ -80,6 +80,15 @@ public class RevisionDateListenerTest {
80 } 80 }
81 81
82 /** 82 /**
83 + * Checks if revision date is correct.
84 + */
85 + @Test(expected = ParserException.class)
86 + public void processRevisionDateInvalid() throws IOException, ParserException {
87 +
88 + YangNode node = manager.getDataModel("src/test/resources/RevisionDateInvalid.yang");
89 + }
90 +
91 + /**
83 * Checks if revision date listener updates the data model tree. 92 * Checks if revision date listener updates the data model tree.
84 */ 93 */
85 @Test 94 @Test
......
1 +module Test {
2 +yang-version 1;
3 +namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
4 +prefix On;
5 +organization "IETF SPRING Working Group";
6 +contact WG;
7 +}
8 +
1 +module Test {
2 +yang-version 1;
3 +namespace urn:ietf:params:xml:ns:yang:ietf-ospf;
4 +prefix test;
5 +import ietf {
6 +prefix On2;
7 +revision-date 2015-02-30;
8 +}
9 +include itut {
10 +revision-date 2016-02-03;
11 +}
12 +include sdn {
13 +revision-date 2014-02-03;
14 +}
15 +contact "Test";
16 +organization "ONOS";
17 +}