Committed by
Gerrit Code Review
Identifier issue fix for module, list, container, leaf, leaf-list, prefix + date…
… agr string for revision fix Change-Id: Id9d596512f35b54f6359d361402bcd0180b71678
Showing
33 changed files
with
495 additions
and
240 deletions
This diff is collapsed. Click to expand it.
... | @@ -1163,6 +1163,26 @@ public class TreeWalkListener implements GeneratedYangListener { | ... | @@ -1163,6 +1163,26 @@ public class TreeWalkListener implements GeneratedYangListener { |
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | @Override | 1165 | @Override |
1166 | + public void enterIdentifier(GeneratedYangParser.IdentifierContext ctx) { | ||
1167 | + // TODO: implement the method. | ||
1168 | + } | ||
1169 | + | ||
1170 | + @Override | ||
1171 | + public void exitIdentifier(GeneratedYangParser.IdentifierContext ctx) { | ||
1172 | + // TODO: implement the method. | ||
1173 | + } | ||
1174 | + | ||
1175 | + @Override | ||
1176 | + public void enterDateArgumentString(GeneratedYangParser.DateArgumentStringContext ctx) { | ||
1177 | + // TODO: implement the method. | ||
1178 | + } | ||
1179 | + | ||
1180 | + @Override | ||
1181 | + public void exitDateArgumentString(GeneratedYangParser.DateArgumentStringContext ctx) { | ||
1182 | + // TODO: implement the method. | ||
1183 | + } | ||
1184 | + | ||
1185 | + @Override | ||
1166 | public void visitTerminal(TerminalNode terminalNode) { | 1186 | public void visitTerminal(TerminalNode terminalNode) { |
1167 | // TODO: implement the method. | 1187 | // TODO: implement the method. |
1168 | } | 1188 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
... | @@ -22,6 +22,8 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -22,6 +22,8 @@ import org.onosproject.yangutils.parser.Parsable; |
22 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 22 | 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 | + | ||
26 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
25 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
26 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
... | @@ -50,7 +52,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.BELONGS_TO_DATA; | ... | @@ -50,7 +52,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.BELONGS_TO_DATA; |
50 | * submodule_header_statement : yang_version_stmt? belongs_to_stmt | 52 | * submodule_header_statement : yang_version_stmt? belongs_to_stmt |
51 | * | belongs_to_stmt yang_version_stmt? | 53 | * | belongs_to_stmt yang_version_stmt? |
52 | * ; | 54 | * ; |
53 | - * belongs_to_stmt : BELONGS_TO_KEYWORD IDENTIFIER LEFT_CURLY_BRACE belongs_to_stmt_body RIGHT_CURLY_BRACE; | 55 | + * belongs_to_stmt : BELONGS_TO_KEYWORD identifier LEFT_CURLY_BRACE belongs_to_stmt_body RIGHT_CURLY_BRACE; |
54 | * belongs_to_stmt_body : prefix_stmt; | 56 | * belongs_to_stmt_body : prefix_stmt; |
55 | */ | 57 | */ |
56 | 58 | ||
... | @@ -78,11 +80,13 @@ public final class BelongsToListener { | ... | @@ -78,11 +80,13 @@ public final class BelongsToListener { |
78 | GeneratedYangParser.BelongstoStatementContext ctx) { | 80 | GeneratedYangParser.BelongstoStatementContext ctx) { |
79 | 81 | ||
80 | // Check for stack to be non empty. | 82 | // Check for stack to be non empty. |
81 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.IDENTIFIER().getText(), | 83 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(), |
82 | ENTRY); | 84 | ENTRY); |
83 | 85 | ||
86 | + String identifier = getValidIdentifier(ctx.identifier().getText(), BELONGS_TO_DATA, ctx); | ||
87 | + | ||
84 | YangBelongsTo belongstoNode = new YangBelongsTo(); | 88 | YangBelongsTo belongstoNode = new YangBelongsTo(); |
85 | - belongstoNode.setBelongsToModuleName(ctx.IDENTIFIER().getText()); | 89 | + belongstoNode.setBelongsToModuleName(identifier); |
86 | 90 | ||
87 | // Push belongsto into the stack. | 91 | // Push belongsto into the stack. |
88 | listener.getParsedDataStack().push(belongstoNode); | 92 | listener.getParsedDataStack().push(belongstoNode); |
... | @@ -99,7 +103,7 @@ public final class BelongsToListener { | ... | @@ -99,7 +103,7 @@ public final class BelongsToListener { |
99 | GeneratedYangParser.BelongstoStatementContext ctx) { | 103 | GeneratedYangParser.BelongstoStatementContext ctx) { |
100 | 104 | ||
101 | // Check for stack to be non empty. | 105 | // Check for stack to be non empty. |
102 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.IDENTIFIER().getText(), | 106 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(), |
103 | EXIT); | 107 | EXIT); |
104 | 108 | ||
105 | Parsable tmpBelongstoNode = listener.getParsedDataStack().peek(); | 109 | Parsable tmpBelongstoNode = listener.getParsedDataStack().peek(); |
... | @@ -108,7 +112,7 @@ public final class BelongsToListener { | ... | @@ -108,7 +112,7 @@ public final class BelongsToListener { |
108 | 112 | ||
109 | // Check for stack to be empty. | 113 | // Check for stack to be empty. |
110 | checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, | 114 | checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, |
111 | - ctx.IDENTIFIER().getText(), EXIT); | 115 | + ctx.identifier().getText(), EXIT); |
112 | 116 | ||
113 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 117 | Parsable tmpNode = listener.getParsedDataStack().peek(); |
114 | switch (tmpNode.getYangConstructType()) { | 118 | switch (tmpNode.getYangConstructType()) { |
... | @@ -119,12 +123,12 @@ public final class BelongsToListener { | ... | @@ -119,12 +123,12 @@ public final class BelongsToListener { |
119 | } | 123 | } |
120 | default: | 124 | default: |
121 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BELONGS_TO_DATA, | 125 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BELONGS_TO_DATA, |
122 | - ctx.IDENTIFIER().getText(), | 126 | + ctx.identifier().getText(), |
123 | EXIT)); | 127 | EXIT)); |
124 | } | 128 | } |
125 | } else { | 129 | } else { |
126 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA, | 130 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA, |
127 | - ctx.IDENTIFIER().getText(), EXIT)); | 131 | + ctx.identifier().getText(), EXIT)); |
128 | } | 132 | } |
129 | } | 133 | } |
130 | } | 134 | } | ... | ... |
... | @@ -32,7 +32,7 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -32,7 +32,7 @@ package org.onosproject.yangutils.parser.impl.listeners; |
32 | * "}") | 32 | * "}") |
33 | * | 33 | * |
34 | * ANTLR grammar rule | 34 | * ANTLR grammar rule |
35 | - * bitStatement : BIT_KEYWORD IDENTIFIER (STMTEND | LEFT_CURLY_BRACE bitBodyStatement RIGHT_CURLY_BRACE); | 35 | + * bitStatement : BIT_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE bitBodyStatement RIGHT_CURLY_BRACE); |
36 | * | 36 | * |
37 | * bitBodyStatement : positionStatement? statusStatement? descriptionStatement? referenceStatement? | 37 | * bitBodyStatement : positionStatement? statusStatement? descriptionStatement? referenceStatement? |
38 | * | positionStatement? statusStatement? referenceStatement? descriptionStatement? | 38 | * | positionStatement? statusStatement? referenceStatement? descriptionStatement? |
... | @@ -65,10 +65,12 @@ import org.onosproject.yangutils.datamodel.YangBit; | ... | @@ -65,10 +65,12 @@ import org.onosproject.yangutils.datamodel.YangBit; |
65 | import org.onosproject.yangutils.datamodel.YangBits; | 65 | import org.onosproject.yangutils.datamodel.YangBits; |
66 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 66 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
67 | import org.onosproject.yangutils.parser.Parsable; | 67 | import org.onosproject.yangutils.parser.Parsable; |
68 | -import static org.onosproject.yangutils.utils.YangConstructType.BIT_DATA; | ||
69 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 68 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
70 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 69 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
71 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 70 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
71 | + | ||
72 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
73 | +import static org.onosproject.yangutils.utils.YangConstructType.BIT_DATA; | ||
72 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 74 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
73 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 75 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
74 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 76 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
... | @@ -102,10 +104,12 @@ public final class BitListener { | ... | @@ -102,10 +104,12 @@ public final class BitListener { |
102 | GeneratedYangParser.BitStatementContext ctx) { | 104 | GeneratedYangParser.BitStatementContext ctx) { |
103 | 105 | ||
104 | // Check for stack to be non empty. | 106 | // Check for stack to be non empty. |
105 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 107 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.identifier().getText(), ENTRY); |
108 | + | ||
109 | + String identifier = getValidIdentifier(ctx.identifier().getText(), BIT_DATA, ctx); | ||
106 | 110 | ||
107 | YangBit bitNode = new YangBit(); | 111 | YangBit bitNode = new YangBit(); |
108 | - bitNode.setBitName(ctx.IDENTIFIER().getText()); | 112 | + bitNode.setBitName(identifier); |
109 | listener.getParsedDataStack().push(bitNode); | 113 | listener.getParsedDataStack().push(bitNode); |
110 | } | 114 | } |
111 | 115 | ||
... | @@ -120,14 +124,14 @@ public final class BitListener { | ... | @@ -120,14 +124,14 @@ public final class BitListener { |
120 | GeneratedYangParser.BitStatementContext ctx) { | 124 | GeneratedYangParser.BitStatementContext ctx) { |
121 | 125 | ||
122 | // Check for stack to be non empty. | 126 | // Check for stack to be non empty. |
123 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.IDENTIFIER().getText(), EXIT); | 127 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT); |
124 | 128 | ||
125 | Parsable tmpBitNode = listener.getParsedDataStack().peek(); | 129 | Parsable tmpBitNode = listener.getParsedDataStack().peek(); |
126 | if (tmpBitNode instanceof YangBit) { | 130 | if (tmpBitNode instanceof YangBit) { |
127 | listener.getParsedDataStack().pop(); | 131 | listener.getParsedDataStack().pop(); |
128 | 132 | ||
129 | // Check for stack to be non empty. | 133 | // Check for stack to be non empty. |
130 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.IDENTIFIER().getText(), EXIT); | 134 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT); |
131 | 135 | ||
132 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 136 | Parsable tmpNode = listener.getParsedDataStack().peek(); |
133 | switch (tmpNode.getYangConstructType()) { | 137 | switch (tmpNode.getYangConstructType()) { |
... | @@ -152,20 +156,20 @@ public final class BitListener { | ... | @@ -152,20 +156,20 @@ public final class BitListener { |
152 | yangBits.addBitInfo((YangBit) tmpBitNode); | 156 | yangBits.addBitInfo((YangBit) tmpBitNode); |
153 | } catch (DataModelException e) { | 157 | } catch (DataModelException e) { |
154 | ParserException parserException = new ParserException(constructExtendedListenerErrorMessage( | 158 | ParserException parserException = new ParserException(constructExtendedListenerErrorMessage( |
155 | - INVALID_CONTENT, BIT_DATA, ctx.IDENTIFIER().getText(), EXIT, e.getMessage())); | 159 | + INVALID_CONTENT, BIT_DATA, ctx.identifier().getText(), EXIT, e.getMessage())); |
156 | - parserException.setLine(ctx.IDENTIFIER().getSymbol().getLine()); | 160 | + parserException.setLine(ctx.getStart().getLine()); |
157 | - parserException.setCharPosition(ctx.IDENTIFIER().getSymbol().getCharPositionInLine()); | 161 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); |
158 | throw parserException; | 162 | throw parserException; |
159 | } | 163 | } |
160 | break; | 164 | break; |
161 | } | 165 | } |
162 | default: | 166 | default: |
163 | throw new ParserException( | 167 | throw new ParserException( |
164 | - constructListenerErrorMessage(INVALID_HOLDER, BIT_DATA, ctx.IDENTIFIER().getText(), EXIT)); | 168 | + constructListenerErrorMessage(INVALID_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT)); |
165 | } | 169 | } |
166 | } else { | 170 | } else { |
167 | throw new ParserException( | 171 | throw new ParserException( |
168 | - constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BIT_DATA, ctx.IDENTIFIER().getText(), EXIT)); | 172 | + constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT)); |
169 | } | 173 | } |
170 | } | 174 | } |
171 | } | 175 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java
... | @@ -25,6 +25,9 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -25,6 +25,9 @@ import org.onosproject.yangutils.parser.Parsable; |
25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 25 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
26 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 26 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
27 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 27 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
28 | +import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
29 | + | ||
30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 32 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
... | @@ -34,7 +37,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp | ... | @@ -34,7 +37,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp |
34 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 37 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
35 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; | 39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA; |
37 | -import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | ||
38 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 40 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
39 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality; | 41 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality; |
40 | import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA; | 42 | import static org.onosproject.yangutils.utils.YangConstructType.CONFIG_DATA; |
... | @@ -66,7 +68,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | ... | @@ -66,7 +68,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
66 | * "}") | 68 | * "}") |
67 | * | 69 | * |
68 | * ANTLR grammar rule | 70 | * ANTLR grammar rule |
69 | - * containerStatement : CONTAINER_KEYWORD IDENTIFIER | 71 | + * containerStatement : CONTAINER_KEYWORD identifier |
70 | * (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | | 72 | * (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | |
71 | * presenceStatement | configStatement | statusStatement | descriptionStatement | | 73 | * presenceStatement | configStatement | statusStatement | descriptionStatement | |
72 | * referenceStatement | typedefStatement | groupingStatement | 74 | * referenceStatement | typedefStatement | groupingStatement |
... | @@ -96,19 +98,20 @@ public final class ContainerListener { | ... | @@ -96,19 +98,20 @@ public final class ContainerListener { |
96 | GeneratedYangParser.ContainerStatementContext ctx) { | 98 | GeneratedYangParser.ContainerStatementContext ctx) { |
97 | 99 | ||
98 | // Check for stack to be non empty. | 100 | // Check for stack to be non empty. |
99 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 101 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.identifier().getText(), ENTRY); |
102 | + | ||
103 | + String identifier = getValidIdentifier(ctx.identifier().getText(), CONTAINER_DATA, ctx); | ||
100 | 104 | ||
101 | // Validate sub statement cardinality. | 105 | // Validate sub statement cardinality. |
102 | validateSubStatementsCardinality(ctx); | 106 | validateSubStatementsCardinality(ctx); |
103 | 107 | ||
104 | // Check for identifier collision | 108 | // Check for identifier collision |
105 | - int line = ctx.IDENTIFIER().getSymbol().getLine(); | 109 | + int line = ctx.getStart().getLine(); |
106 | - int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine(); | 110 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); |
107 | - String identifierName = ctx.IDENTIFIER().getText(); | 111 | + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CONTAINER_DATA); |
108 | - detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, CONTAINER_DATA); | ||
109 | 112 | ||
110 | YangContainer container = new YangContainer(); | 113 | YangContainer container = new YangContainer(); |
111 | - container.setName(ctx.IDENTIFIER().getText()); | 114 | + container.setName(identifier); |
112 | 115 | ||
113 | /* | 116 | /* |
114 | * If "config" is not specified, the default is the same as the parent | 117 | * If "config" is not specified, the default is the same as the parent |
... | @@ -127,12 +130,12 @@ public final class ContainerListener { | ... | @@ -127,12 +130,12 @@ public final class ContainerListener { |
127 | curNode.addChild(container); | 130 | curNode.addChild(container); |
128 | } catch (DataModelException e) { | 131 | } catch (DataModelException e) { |
129 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 132 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, |
130 | - CONTAINER_DATA, ctx.IDENTIFIER().getText(), ENTRY, e.getMessage())); | 133 | + CONTAINER_DATA, ctx.identifier().getText(), ENTRY, e.getMessage())); |
131 | } | 134 | } |
132 | listener.getParsedDataStack().push(container); | 135 | listener.getParsedDataStack().push(container); |
133 | } else { | 136 | } else { |
134 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONTAINER_DATA, | 137 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONTAINER_DATA, |
135 | - ctx.IDENTIFIER().getText(), ENTRY)); | 138 | + ctx.identifier().getText(), ENTRY)); |
136 | } | 139 | } |
137 | } | 140 | } |
138 | 141 | ||
... | @@ -147,7 +150,7 @@ public final class ContainerListener { | ... | @@ -147,7 +150,7 @@ public final class ContainerListener { |
147 | GeneratedYangParser.ContainerStatementContext ctx) { | 150 | GeneratedYangParser.ContainerStatementContext ctx) { |
148 | 151 | ||
149 | // Check for stack to be non empty. | 152 | // Check for stack to be non empty. |
150 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.IDENTIFIER().getText(), EXIT); | 153 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.identifier().getText(), EXIT); |
151 | 154 | ||
152 | if (listener.getParsedDataStack().peek() instanceof YangContainer) { | 155 | if (listener.getParsedDataStack().peek() instanceof YangContainer) { |
153 | YangContainer yangContainer = (YangContainer) listener.getParsedDataStack().peek(); | 156 | YangContainer yangContainer = (YangContainer) listener.getParsedDataStack().peek(); |
... | @@ -155,12 +158,12 @@ public final class ContainerListener { | ... | @@ -155,12 +158,12 @@ public final class ContainerListener { |
155 | yangContainer.validateDataOnExit(); | 158 | yangContainer.validateDataOnExit(); |
156 | } catch (DataModelException e) { | 159 | } catch (DataModelException e) { |
157 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 160 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, |
158 | - CONTAINER_DATA, ctx.IDENTIFIER().getText(), EXIT, e.getMessage())); | 161 | + CONTAINER_DATA, ctx.identifier().getText(), EXIT, e.getMessage())); |
159 | } | 162 | } |
160 | listener.getParsedDataStack().pop(); | 163 | listener.getParsedDataStack().pop(); |
161 | } else { | 164 | } else { |
162 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CONTAINER_DATA, | 165 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CONTAINER_DATA, |
163 | - ctx.IDENTIFIER().getText(), EXIT)); | 166 | + ctx.identifier().getText(), EXIT)); |
164 | } | 167 | } |
165 | } | 168 | } |
166 | 169 | ||
... | @@ -171,11 +174,11 @@ public final class ContainerListener { | ... | @@ -171,11 +174,11 @@ public final class ContainerListener { |
171 | */ | 174 | */ |
172 | private static void validateSubStatementsCardinality(GeneratedYangParser.ContainerStatementContext ctx) { | 175 | private static void validateSubStatementsCardinality(GeneratedYangParser.ContainerStatementContext ctx) { |
173 | 176 | ||
174 | - validateCardinality(ctx.presenceStatement(), PRESENCE_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText()); | 177 | + validateCardinality(ctx.presenceStatement(), PRESENCE_DATA, CONTAINER_DATA, ctx.identifier().getText()); |
175 | - validateCardinality(ctx.configStatement(), CONFIG_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText()); | 178 | + validateCardinality(ctx.configStatement(), CONFIG_DATA, CONTAINER_DATA, ctx.identifier().getText()); |
176 | - validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText()); | 179 | + validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, CONTAINER_DATA, ctx.identifier().getText()); |
177 | - validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText()); | 180 | + validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, CONTAINER_DATA, ctx.identifier().getText()); |
178 | - validateCardinality(ctx.statusStatement(), STATUS_DATA, CONTAINER_DATA, ctx.IDENTIFIER().getText()); | 181 | + validateCardinality(ctx.statusStatement(), STATUS_DATA, CONTAINER_DATA, ctx.identifier().getText()); |
179 | // TODO when, grouping, typedef. | 182 | // TODO when, grouping, typedef. |
180 | } | 183 | } |
181 | } | 184 | } | ... | ... |
... | @@ -23,6 +23,8 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -23,6 +23,8 @@ import org.onosproject.yangutils.parser.Parsable; |
23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | + | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
26 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
... | @@ -49,7 +51,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.IMPORT_DATA; | ... | @@ -49,7 +51,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.IMPORT_DATA; |
49 | * ANTLR grammar rule | 51 | * ANTLR grammar rule |
50 | * linkage_stmts : (import_stmt | 52 | * linkage_stmts : (import_stmt |
51 | * | include_stmt)*; | 53 | * | include_stmt)*; |
52 | - * import_stmt : IMPORT_KEYWORD IDENTIFIER LEFT_CURLY_BRACE import_stmt_body | 54 | + * import_stmt : IMPORT_KEYWORD identifier LEFT_CURLY_BRACE import_stmt_body |
53 | * RIGHT_CURLY_BRACE; | 55 | * RIGHT_CURLY_BRACE; |
54 | * import_stmt_body : prefix_stmt revision_date_stmt?; | 56 | * import_stmt_body : prefix_stmt revision_date_stmt?; |
55 | */ | 57 | */ |
... | @@ -76,10 +78,12 @@ public final class ImportListener { | ... | @@ -76,10 +78,12 @@ public final class ImportListener { |
76 | public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { | 78 | public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { |
77 | 79 | ||
78 | // Check for stack to be non empty. | 80 | // Check for stack to be non empty. |
79 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 81 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(), ENTRY); |
82 | + | ||
83 | + String identifier = getValidIdentifier(ctx.identifier().getText(), IMPORT_DATA, ctx); | ||
80 | 84 | ||
81 | YangImport importNode = new YangImport(); | 85 | YangImport importNode = new YangImport(); |
82 | - importNode.setModuleName(ctx.IDENTIFIER().getText()); | 86 | + importNode.setModuleName(identifier); |
83 | 87 | ||
84 | // Push import node to the stack. | 88 | // Push import node to the stack. |
85 | listener.getParsedDataStack().push(importNode); | 89 | listener.getParsedDataStack().push(importNode); |
... | @@ -95,14 +99,14 @@ public final class ImportListener { | ... | @@ -95,14 +99,14 @@ public final class ImportListener { |
95 | public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { | 99 | public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) { |
96 | 100 | ||
97 | // Check for stack to be non empty. | 101 | // Check for stack to be non empty. |
98 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.IDENTIFIER().getText(), EXIT); | 102 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(), EXIT); |
99 | 103 | ||
100 | Parsable tmpImportNode = listener.getParsedDataStack().peek(); | 104 | Parsable tmpImportNode = listener.getParsedDataStack().peek(); |
101 | if (tmpImportNode instanceof YangImport) { | 105 | if (tmpImportNode instanceof YangImport) { |
102 | listener.getParsedDataStack().pop(); | 106 | listener.getParsedDataStack().pop(); |
103 | 107 | ||
104 | // Check for stack to be non empty. | 108 | // Check for stack to be non empty. |
105 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.IDENTIFIER().getText(), | 109 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(), |
106 | EXIT); | 110 | EXIT); |
107 | 111 | ||
108 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 112 | Parsable tmpNode = listener.getParsedDataStack().peek(); |
... | @@ -119,12 +123,12 @@ public final class ImportListener { | ... | @@ -119,12 +123,12 @@ public final class ImportListener { |
119 | } | 123 | } |
120 | default: | 124 | default: |
121 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IMPORT_DATA, | 125 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IMPORT_DATA, |
122 | - ctx.IDENTIFIER().getText(), | 126 | + ctx.identifier().getText(), |
123 | EXIT)); | 127 | EXIT)); |
124 | } | 128 | } |
125 | } else { | 129 | } else { |
126 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA, | 130 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA, |
127 | - ctx.IDENTIFIER().getText(), EXIT)); | 131 | + ctx.identifier().getText(), EXIT)); |
128 | } | 132 | } |
129 | } | 133 | } |
130 | } | 134 | } | ... | ... |
... | @@ -23,6 +23,8 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -23,6 +23,8 @@ import org.onosproject.yangutils.parser.Parsable; |
23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 23 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | + | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
26 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
... | @@ -49,7 +51,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.INCLUDE_DATA; | ... | @@ -49,7 +51,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.INCLUDE_DATA; |
49 | * ANTLR grammar rule | 51 | * ANTLR grammar rule |
50 | * linkage_stmts : (import_stmt | 52 | * linkage_stmts : (import_stmt |
51 | * | include_stmt)*; | 53 | * | include_stmt)*; |
52 | - * include_stmt : INCLUDE_KEYWORD IDENTIFIER (STMTEND | LEFT_CURLY_BRACE | 54 | + * include_stmt : INCLUDE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE |
53 | * revision_date_stmt? RIGHT_CURLY_BRACE); | 55 | * revision_date_stmt? RIGHT_CURLY_BRACE); |
54 | */ | 56 | */ |
55 | 57 | ||
... | @@ -75,11 +77,13 @@ public final class IncludeListener { | ... | @@ -75,11 +77,13 @@ public final class IncludeListener { |
75 | public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { | 77 | public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { |
76 | 78 | ||
77 | // Check for stack to be non empty. | 79 | // Check for stack to be non empty. |
78 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.IDENTIFIER().getText(), | 80 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(), |
79 | ENTRY); | 81 | ENTRY); |
80 | 82 | ||
83 | + String identifier = getValidIdentifier(ctx.identifier().getText(), INCLUDE_DATA, ctx); | ||
84 | + | ||
81 | YangInclude includeNode = new YangInclude(); | 85 | YangInclude includeNode = new YangInclude(); |
82 | - includeNode.setSubModuleName(ctx.IDENTIFIER().getText()); | 86 | + includeNode.setSubModuleName(identifier); |
83 | 87 | ||
84 | listener.getParsedDataStack().push(includeNode); | 88 | listener.getParsedDataStack().push(includeNode); |
85 | } | 89 | } |
... | @@ -94,14 +98,14 @@ public final class IncludeListener { | ... | @@ -94,14 +98,14 @@ public final class IncludeListener { |
94 | public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { | 98 | public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) { |
95 | 99 | ||
96 | // Check for stack to be non empty. | 100 | // Check for stack to be non empty. |
97 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.IDENTIFIER().getText(), EXIT); | 101 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(), EXIT); |
98 | 102 | ||
99 | Parsable tmpIncludeNode = listener.getParsedDataStack().peek(); | 103 | Parsable tmpIncludeNode = listener.getParsedDataStack().peek(); |
100 | if (tmpIncludeNode instanceof YangInclude) { | 104 | if (tmpIncludeNode instanceof YangInclude) { |
101 | listener.getParsedDataStack().pop(); | 105 | listener.getParsedDataStack().pop(); |
102 | 106 | ||
103 | // Check for stack to be non empty. | 107 | // Check for stack to be non empty. |
104 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.IDENTIFIER().getText(), | 108 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(), |
105 | EXIT); | 109 | EXIT); |
106 | 110 | ||
107 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 111 | Parsable tmpNode = listener.getParsedDataStack().peek(); |
... | @@ -118,12 +122,12 @@ public final class IncludeListener { | ... | @@ -118,12 +122,12 @@ public final class IncludeListener { |
118 | } | 122 | } |
119 | default: | 123 | default: |
120 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INCLUDE_DATA, | 124 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INCLUDE_DATA, |
121 | - ctx.IDENTIFIER().getText(), | 125 | + ctx.identifier().getText(), |
122 | EXIT)); | 126 | EXIT)); |
123 | } | 127 | } |
124 | } else { | 128 | } else { |
125 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA, | 129 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA, |
126 | - ctx.IDENTIFIER().getText(), EXIT)); | 130 | + ctx.identifier().getText(), EXIT)); |
127 | } | 131 | } |
128 | } | 132 | } |
129 | } | 133 | } | ... | ... |
... | @@ -22,6 +22,8 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -22,6 +22,8 @@ import org.onosproject.yangutils.parser.Parsable; |
22 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 22 | 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 | + | ||
26 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
25 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
26 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
... | @@ -64,7 +66,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA; | ... | @@ -64,7 +66,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA; |
64 | * "}" | 66 | * "}" |
65 | * | 67 | * |
66 | * ANTLR grammar rule | 68 | * ANTLR grammar rule |
67 | - * leafListStatement : LEAF_LIST_KEYWORD IDENTIFIER LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | | 69 | + * leafListStatement : LEAF_LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | |
68 | * typeStatement | unitsStatement | mustStatement | configStatement | minElementsStatement | maxElementsStatement | | 70 | * typeStatement | unitsStatement | mustStatement | configStatement | minElementsStatement | maxElementsStatement | |
69 | * orderedByStatement | statusStatement | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE; | 71 | * orderedByStatement | statusStatement | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE; |
70 | */ | 72 | */ |
... | @@ -92,19 +94,20 @@ public final class LeafListListener { | ... | @@ -92,19 +94,20 @@ public final class LeafListListener { |
92 | GeneratedYangParser.LeafListStatementContext ctx) { | 94 | GeneratedYangParser.LeafListStatementContext ctx) { |
93 | 95 | ||
94 | // Check for stack to be non empty. | 96 | // Check for stack to be non empty. |
95 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 97 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.identifier().getText(), ENTRY); |
98 | + | ||
99 | + String identifier = getValidIdentifier(ctx.identifier().getText(), LEAF_LIST_DATA, ctx); | ||
96 | 100 | ||
97 | // Validate sub statement cardinality. | 101 | // Validate sub statement cardinality. |
98 | validateSubStatementsCardinality(ctx); | 102 | validateSubStatementsCardinality(ctx); |
99 | 103 | ||
100 | // Check for identifier collision | 104 | // Check for identifier collision |
101 | - int line = ctx.IDENTIFIER().getSymbol().getLine(); | 105 | + int line = ctx.getStart().getLine(); |
102 | - int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine(); | 106 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); |
103 | - String identifierName = ctx.IDENTIFIER().getText(); | 107 | + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LEAF_LIST_DATA); |
104 | - detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, LEAF_LIST_DATA); | ||
105 | 108 | ||
106 | YangLeafList leafList = new YangLeafList(); | 109 | YangLeafList leafList = new YangLeafList(); |
107 | - leafList.setLeafName(ctx.IDENTIFIER().getText()); | 110 | + leafList.setLeafName(identifier); |
108 | 111 | ||
109 | Parsable tmpData = listener.getParsedDataStack().peek(); | 112 | Parsable tmpData = listener.getParsedDataStack().peek(); |
110 | YangLeavesHolder leaves; | 113 | YangLeavesHolder leaves; |
... | @@ -114,7 +117,7 @@ public final class LeafListListener { | ... | @@ -114,7 +117,7 @@ public final class LeafListListener { |
114 | leaves.addLeafList(leafList); | 117 | leaves.addLeafList(leafList); |
115 | } else { | 118 | } else { |
116 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_LIST_DATA, | 119 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_LIST_DATA, |
117 | - ctx.IDENTIFIER().getText(), ENTRY)); | 120 | + ctx.identifier().getText(), ENTRY)); |
118 | } | 121 | } |
119 | listener.getParsedDataStack().push(leafList); | 122 | listener.getParsedDataStack().push(leafList); |
120 | } | 123 | } |
... | @@ -130,31 +133,31 @@ public final class LeafListListener { | ... | @@ -130,31 +133,31 @@ public final class LeafListListener { |
130 | GeneratedYangParser.LeafListStatementContext ctx) { | 133 | GeneratedYangParser.LeafListStatementContext ctx) { |
131 | 134 | ||
132 | // Check for stack to be non empty. | 135 | // Check for stack to be non empty. |
133 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.IDENTIFIER().getText(), EXIT); | 136 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.identifier().getText(), EXIT); |
134 | 137 | ||
135 | if (listener.getParsedDataStack().peek() instanceof YangLeafList) { | 138 | if (listener.getParsedDataStack().peek() instanceof YangLeafList) { |
136 | listener.getParsedDataStack().pop(); | 139 | listener.getParsedDataStack().pop(); |
137 | } else { | 140 | } else { |
138 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_LIST_DATA, | 141 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_LIST_DATA, |
139 | - ctx.IDENTIFIER().getText(), EXIT)); | 142 | + ctx.identifier().getText(), EXIT)); |
140 | } | 143 | } |
141 | } | 144 | } |
142 | 145 | ||
143 | /** | 146 | /** |
144 | * Validates the cardinality of leaf-list sub-statements as per grammar. | 147 | * Validates the cardinality of leaf-list sub-statements as per grammar. |
145 | * | 148 | * |
146 | - * @param ctx context object of the grammar rule. | 149 | + * @param ctx context object of the grammar rule |
147 | */ | 150 | */ |
148 | private static void validateSubStatementsCardinality(GeneratedYangParser.LeafListStatementContext ctx) { | 151 | private static void validateSubStatementsCardinality(GeneratedYangParser.LeafListStatementContext ctx) { |
149 | 152 | ||
150 | - validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 153 | + validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
151 | - validateCardinality(ctx.unitsStatement(), UNITS_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 154 | + validateCardinality(ctx.unitsStatement(), UNITS_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
152 | - validateCardinality(ctx.configStatement(), CONFIG_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 155 | + validateCardinality(ctx.configStatement(), CONFIG_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
153 | - validateCardinality(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 156 | + validateCardinality(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
154 | - validateCardinality(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 157 | + validateCardinality(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
155 | - validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 158 | + validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
156 | - validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 159 | + validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
157 | - validateCardinality(ctx.statusStatement(), STATUS_DATA, LEAF_LIST_DATA, ctx.IDENTIFIER().getText()); | 160 | + validateCardinality(ctx.statusStatement(), STATUS_DATA, LEAF_LIST_DATA, ctx.identifier().getText()); |
158 | //TODO ordered by | 161 | //TODO ordered by |
159 | } | 162 | } |
160 | } | 163 | } | ... | ... |
... | @@ -26,6 +26,8 @@ import org.onosproject.yangutils.parser.Parsable; | ... | @@ -26,6 +26,8 @@ import org.onosproject.yangutils.parser.Parsable; |
26 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 26 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
27 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 27 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
28 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 28 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
29 | + | ||
30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 32 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
... | @@ -66,7 +68,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA; | ... | @@ -66,7 +68,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA; |
66 | * "}" | 68 | * "}" |
67 | * | 69 | * |
68 | * ANTLR grammar rule | 70 | * ANTLR grammar rule |
69 | - * leafStatement : LEAF_KEYWORD IDENTIFIER LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement | | 71 | + * leafStatement : LEAF_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement | |
70 | * unitsStatement | mustStatement | defaultStatement | configStatement | mandatoryStatement | statusStatement | | 72 | * unitsStatement | mustStatement | defaultStatement | configStatement | mandatoryStatement | statusStatement | |
71 | * descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE; | 73 | * descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE; |
72 | */ | 74 | */ |
... | @@ -94,19 +96,20 @@ public final class LeafListener { | ... | @@ -94,19 +96,20 @@ public final class LeafListener { |
94 | GeneratedYangParser.LeafStatementContext ctx) { | 96 | GeneratedYangParser.LeafStatementContext ctx) { |
95 | 97 | ||
96 | // Check for stack to be non empty. | 98 | // Check for stack to be non empty. |
97 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 99 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.identifier().getText(), ENTRY); |
100 | + | ||
101 | + String identifier = getValidIdentifier(ctx.identifier().getText(), LEAF_DATA, ctx); | ||
98 | 102 | ||
99 | // Validate sub statement cardinality. | 103 | // Validate sub statement cardinality. |
100 | validateSubStatementsCardinality(ctx); | 104 | validateSubStatementsCardinality(ctx); |
101 | 105 | ||
102 | // Check for identifier collision | 106 | // Check for identifier collision |
103 | - int line = ctx.IDENTIFIER().getSymbol().getLine(); | 107 | + int line = ctx.getStart().getLine(); |
104 | - int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine(); | 108 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); |
105 | - String identifierName = ctx.IDENTIFIER().getText(); | 109 | + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LEAF_DATA); |
106 | - detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, LEAF_DATA); | ||
107 | 110 | ||
108 | YangLeaf leaf = new YangLeaf(); | 111 | YangLeaf leaf = new YangLeaf(); |
109 | - leaf.setLeafName(ctx.IDENTIFIER().getText()); | 112 | + leaf.setLeafName(identifier); |
110 | 113 | ||
111 | Parsable tmpData = listener.getParsedDataStack().peek(); | 114 | Parsable tmpData = listener.getParsedDataStack().peek(); |
112 | YangLeavesHolder leaves; | 115 | YangLeavesHolder leaves; |
... | @@ -116,7 +119,7 @@ public final class LeafListener { | ... | @@ -116,7 +119,7 @@ public final class LeafListener { |
116 | leaves.addLeaf(leaf); | 119 | leaves.addLeaf(leaf); |
117 | } else { | 120 | } else { |
118 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_DATA, | 121 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_DATA, |
119 | - ctx.IDENTIFIER().getText(), ENTRY)); | 122 | + ctx.identifier().getText(), ENTRY)); |
120 | } | 123 | } |
121 | 124 | ||
122 | listener.getParsedDataStack().push(leaf); | 125 | listener.getParsedDataStack().push(leaf); |
... | @@ -126,37 +129,37 @@ public final class LeafListener { | ... | @@ -126,37 +129,37 @@ public final class LeafListener { |
126 | * It is called when parser exits from grammar rule (leaf), performs | 129 | * It is called when parser exits from grammar rule (leaf), performs |
127 | * validation and updates the data model tree. | 130 | * validation and updates the data model tree. |
128 | * | 131 | * |
129 | - * @param listener listener's object. | 132 | + * @param listener listener's object |
130 | - * @param ctx context object of the grammar rule. | 133 | + * @param ctx context object of the grammar rule |
131 | */ | 134 | */ |
132 | public static void processLeafExit(TreeWalkListener listener, | 135 | public static void processLeafExit(TreeWalkListener listener, |
133 | GeneratedYangParser.LeafStatementContext ctx) { | 136 | GeneratedYangParser.LeafStatementContext ctx) { |
134 | 137 | ||
135 | // Check for stack to be non empty. | 138 | // Check for stack to be non empty. |
136 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.IDENTIFIER().getText(), EXIT); | 139 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.identifier().getText(), EXIT); |
137 | 140 | ||
138 | if (listener.getParsedDataStack().peek() instanceof YangLeaf) { | 141 | if (listener.getParsedDataStack().peek() instanceof YangLeaf) { |
139 | listener.getParsedDataStack().pop(); | 142 | listener.getParsedDataStack().pop(); |
140 | } else { | 143 | } else { |
141 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_DATA, | 144 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_DATA, |
142 | - ctx.IDENTIFIER().getText(), EXIT)); | 145 | + ctx.identifier().getText(), EXIT)); |
143 | } | 146 | } |
144 | } | 147 | } |
145 | 148 | ||
146 | /** | 149 | /** |
147 | * Validates the cardinality of leaf sub-statements as per grammar. | 150 | * Validates the cardinality of leaf sub-statements as per grammar. |
148 | * | 151 | * |
149 | - * @param ctx context object of the grammar rule. | 152 | + * @param ctx context object of the grammar rule |
150 | */ | 153 | */ |
151 | private static void validateSubStatementsCardinality(GeneratedYangParser.LeafStatementContext ctx) { | 154 | private static void validateSubStatementsCardinality(GeneratedYangParser.LeafStatementContext ctx) { |
152 | 155 | ||
153 | - validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_DATA, ctx.IDENTIFIER().getText()); | 156 | + validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_DATA, ctx.identifier().getText()); |
154 | - validateCardinality(ctx.unitsStatement(), UNITS_DATA, LEAF_DATA, ctx.IDENTIFIER().getText()); | 157 | + validateCardinality(ctx.unitsStatement(), UNITS_DATA, LEAF_DATA, ctx.identifier().getText()); |
155 | - validateCardinality(ctx.configStatement(), CONFIG_DATA, LEAF_DATA, ctx.IDENTIFIER().getText()); | 158 | + validateCardinality(ctx.configStatement(), CONFIG_DATA, LEAF_DATA, ctx.identifier().getText()); |
156 | - validateCardinality(ctx.mandatoryStatement(), MANDATORY_DATA, LEAF_DATA, ctx.IDENTIFIER().getText()); | 159 | + validateCardinality(ctx.mandatoryStatement(), MANDATORY_DATA, LEAF_DATA, ctx.identifier().getText()); |
157 | - validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_DATA, ctx.IDENTIFIER().getText()); | 160 | + validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_DATA, ctx.identifier().getText()); |
158 | - validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LEAF_DATA, ctx.IDENTIFIER().getText()); | 161 | + validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LEAF_DATA, ctx.identifier().getText()); |
159 | - validateCardinality(ctx.statusStatement(), STATUS_DATA, LEAF_DATA, ctx.IDENTIFIER().getText()); | 162 | + validateCardinality(ctx.statusStatement(), STATUS_DATA, LEAF_DATA, ctx.identifier().getText()); |
160 | //TODO when. | 163 | //TODO when. |
161 | } | 164 | } |
162 | } | 165 | } | ... | ... |
... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; | ... | @@ -27,6 +27,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException; |
27 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 27 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
28 | import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; | 28 | import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation; |
29 | 29 | ||
30 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; | 31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil; |
31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 32 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
32 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
... | @@ -74,7 +75,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; | ... | @@ -74,7 +75,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA; |
74 | * "}" | 75 | * "}" |
75 | * | 76 | * |
76 | * ANTLR grammar rule | 77 | * ANTLR grammar rule |
77 | - * listStatement : LIST_KEYWORD IDENTIFIER LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | | 78 | + * listStatement : LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | |
78 | * keyStatement | uniqueStatement | configStatement | minElementsStatement | maxElementsStatement | | 79 | * keyStatement | uniqueStatement | configStatement | minElementsStatement | maxElementsStatement | |
79 | * orderedByStatement | statusStatement | descriptionStatement | referenceStatement | typedefStatement | | 80 | * orderedByStatement | statusStatement | descriptionStatement | referenceStatement | typedefStatement | |
80 | * groupingStatement| dataDefStatement)* RIGHT_CURLY_BRACE; | 81 | * groupingStatement| dataDefStatement)* RIGHT_CURLY_BRACE; |
... | @@ -104,19 +105,20 @@ public final class ListListener { | ... | @@ -104,19 +105,20 @@ public final class ListListener { |
104 | 105 | ||
105 | YangNode curNode; | 106 | YangNode curNode; |
106 | 107 | ||
107 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 108 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.identifier().getText(), ENTRY); |
109 | + | ||
110 | + String identifier = getValidIdentifier(ctx.identifier().getText(), LIST_DATA, ctx); | ||
108 | 111 | ||
109 | // Validate sub statement cardinality. | 112 | // Validate sub statement cardinality. |
110 | validateSubStatementsCardinality(ctx); | 113 | validateSubStatementsCardinality(ctx); |
111 | 114 | ||
112 | // Check for identifier collision | 115 | // Check for identifier collision |
113 | - int line = ctx.IDENTIFIER().getSymbol().getLine(); | 116 | + int line = ctx.getStart().getLine(); |
114 | - int charPositionInLine = ctx.IDENTIFIER().getSymbol().getCharPositionInLine(); | 117 | + int charPositionInLine = ctx.getStart().getCharPositionInLine(); |
115 | - String identifierName = ctx.IDENTIFIER().getText(); | 118 | + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LIST_DATA); |
116 | - detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, LIST_DATA); | ||
117 | 119 | ||
118 | YangList yangList = new YangList(); | 120 | YangList yangList = new YangList(); |
119 | - yangList.setName(ctx.IDENTIFIER().getText()); | 121 | + yangList.setName(identifier); |
120 | 122 | ||
121 | /* | 123 | /* |
122 | * If "config" is not specified, the default is the same as the parent | 124 | * If "config" is not specified, the default is the same as the parent |
... | @@ -135,12 +137,12 @@ public final class ListListener { | ... | @@ -135,12 +137,12 @@ public final class ListListener { |
135 | curNode.addChild(yangList); | 137 | curNode.addChild(yangList); |
136 | } catch (DataModelException e) { | 138 | } catch (DataModelException e) { |
137 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 139 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, |
138 | - LIST_DATA, ctx.IDENTIFIER().getText(), ENTRY, e.getMessage())); | 140 | + LIST_DATA, ctx.identifier().getText(), ENTRY, e.getMessage())); |
139 | } | 141 | } |
140 | listener.getParsedDataStack().push(yangList); | 142 | listener.getParsedDataStack().push(yangList); |
141 | } else { | 143 | } else { |
142 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LIST_DATA, | 144 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LIST_DATA, |
143 | - ctx.IDENTIFIER().getText(), ENTRY)); | 145 | + ctx.identifier().getText(), ENTRY)); |
144 | } | 146 | } |
145 | } | 147 | } |
146 | 148 | ||
... | @@ -154,7 +156,7 @@ public final class ListListener { | ... | @@ -154,7 +156,7 @@ public final class ListListener { |
154 | public static void processListExit(TreeWalkListener listener, | 156 | public static void processListExit(TreeWalkListener listener, |
155 | GeneratedYangParser.ListStatementContext ctx) { | 157 | GeneratedYangParser.ListStatementContext ctx) { |
156 | 158 | ||
157 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.IDENTIFIER().getText(), EXIT); | 159 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.identifier().getText(), EXIT); |
158 | 160 | ||
159 | if (listener.getParsedDataStack().peek() instanceof YangList) { | 161 | if (listener.getParsedDataStack().peek() instanceof YangList) { |
160 | YangList yangList = (YangList) listener.getParsedDataStack().peek(); | 162 | YangList yangList = (YangList) listener.getParsedDataStack().peek(); |
... | @@ -162,12 +164,12 @@ public final class ListListener { | ... | @@ -162,12 +164,12 @@ public final class ListListener { |
162 | yangList.validateDataOnExit(); | 164 | yangList.validateDataOnExit(); |
163 | } catch (DataModelException e) { | 165 | } catch (DataModelException e) { |
164 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 166 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, |
165 | - LIST_DATA, ctx.IDENTIFIER().getText(), EXIT, e.getMessage())); | 167 | + LIST_DATA, ctx.identifier().getText(), EXIT, e.getMessage())); |
166 | } | 168 | } |
167 | listener.getParsedDataStack().pop(); | 169 | listener.getParsedDataStack().pop(); |
168 | } else { | 170 | } else { |
169 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LIST_DATA, | 171 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LIST_DATA, |
170 | - ctx.IDENTIFIER().getText(), EXIT)); | 172 | + ctx.identifier().getText(), EXIT)); |
171 | } | 173 | } |
172 | } | 174 | } |
173 | 175 | ||
... | @@ -178,14 +180,14 @@ public final class ListListener { | ... | @@ -178,14 +180,14 @@ public final class ListListener { |
178 | */ | 180 | */ |
179 | private static void validateSubStatementsCardinality(GeneratedYangParser.ListStatementContext ctx) { | 181 | private static void validateSubStatementsCardinality(GeneratedYangParser.ListStatementContext ctx) { |
180 | 182 | ||
181 | - validateCardinality(ctx.keyStatement(), KEY_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 183 | + validateCardinality(ctx.keyStatement(), KEY_DATA, LIST_DATA, ctx.identifier().getText()); |
182 | - validateCardinality(ctx.configStatement(), CONFIG_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 184 | + validateCardinality(ctx.configStatement(), CONFIG_DATA, LIST_DATA, ctx.identifier().getText()); |
183 | - validateCardinality(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 185 | + validateCardinality(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LIST_DATA, ctx.identifier().getText()); |
184 | - validateCardinality(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 186 | + validateCardinality(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LIST_DATA, ctx.identifier().getText()); |
185 | - validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 187 | + validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, LIST_DATA, ctx.identifier().getText()); |
186 | - validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 188 | + validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, LIST_DATA, ctx.identifier().getText()); |
187 | - validateCardinality(ctx.statusStatement(), STATUS_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 189 | + validateCardinality(ctx.statusStatement(), STATUS_DATA, LIST_DATA, ctx.identifier().getText()); |
188 | - validateCardinalityNonNull(ctx.dataDefStatement(), DATA_DEF_DATA, LIST_DATA, ctx.IDENTIFIER().getText()); | 190 | + validateCardinalityNonNull(ctx.dataDefStatement(), DATA_DEF_DATA, LIST_DATA, ctx.identifier().getText()); |
189 | //TODO when, typedef, grouping, unique | 191 | //TODO when, typedef, grouping, unique |
190 | } | 192 | } |
191 | } | 193 | } | ... | ... |
... | @@ -20,6 +20,8 @@ import org.onosproject.yangutils.datamodel.YangModule; | ... | @@ -20,6 +20,8 @@ import org.onosproject.yangutils.datamodel.YangModule; |
20 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 20 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
21 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 21 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
22 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 22 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
23 | + | ||
24 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
23 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 25 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
24 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 26 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
25 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
... | @@ -45,7 +47,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.MODULE_DATA; | ... | @@ -45,7 +47,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.MODULE_DATA; |
45 | * "}" optsep | 47 | * "}" optsep |
46 | * | 48 | * |
47 | * ANTLR grammar rule | 49 | * ANTLR grammar rule |
48 | - * module_stmt : MODULE_KEYWORD IDENTIFIER LEFT_CURLY_BRACE module_body* RIGHT_CURLY_BRACE; | 50 | + * module_stmt : MODULE_KEYWORD identifier LEFT_CURLY_BRACE module_body* RIGHT_CURLY_BRACE; |
49 | */ | 51 | */ |
50 | 52 | ||
51 | /** | 53 | /** |
... | @@ -70,10 +72,12 @@ public final class ModuleListener { | ... | @@ -70,10 +72,12 @@ public final class ModuleListener { |
70 | public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) { | 72 | public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) { |
71 | 73 | ||
72 | // Check if stack is empty. | 74 | // Check if stack is empty. |
73 | - checkStackIsEmpty(listener, INVALID_HOLDER, MODULE_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 75 | + checkStackIsEmpty(listener, INVALID_HOLDER, MODULE_DATA, ctx.identifier().getText(), ENTRY); |
76 | + | ||
77 | + String identifier = getValidIdentifier(ctx.identifier().getText(), MODULE_DATA, ctx); | ||
74 | 78 | ||
75 | YangModule yangModule = new YangModule(); | 79 | YangModule yangModule = new YangModule(); |
76 | - yangModule.setName(ctx.IDENTIFIER().getText()); | 80 | + yangModule.setName(identifier); |
77 | 81 | ||
78 | if (ctx.moduleBody(0).moduleHeaderStatement().yangVersionStatement() == null) { | 82 | if (ctx.moduleBody(0).moduleHeaderStatement().yangVersionStatement() == null) { |
79 | yangModule.setVersion((byte) 1); | 83 | yangModule.setVersion((byte) 1); |
... | @@ -92,11 +96,11 @@ public final class ModuleListener { | ... | @@ -92,11 +96,11 @@ public final class ModuleListener { |
92 | public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) { | 96 | public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) { |
93 | 97 | ||
94 | // Check for stack to be non empty. | 98 | // Check for stack to be non empty. |
95 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.IDENTIFIER().getText(), EXIT); | 99 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.identifier().getText(), EXIT); |
96 | 100 | ||
97 | if (!(listener.getParsedDataStack().peek() instanceof YangModule)) { | 101 | if (!(listener.getParsedDataStack().peek() instanceof YangModule)) { |
98 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA, | 102 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA, |
99 | - ctx.IDENTIFIER().getText(), EXIT)); | 103 | + ctx.identifier().getText(), EXIT)); |
100 | } | 104 | } |
101 | } | 105 | } |
102 | } | 106 | } | ... | ... |
... | @@ -30,7 +30,7 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -30,7 +30,7 @@ package org.onosproject.yangutils.parser.impl.listeners; |
30 | * zero-integer-value = 1*DIGIT | 30 | * zero-integer-value = 1*DIGIT |
31 | * | 31 | * |
32 | * ANTLR grammar rule | 32 | * ANTLR grammar rule |
33 | - * positionStatement : POSITION_KEYWORD INTEGER STMTEND; | 33 | + * positionStatement : POSITION_KEYWORD string STMTEND; |
34 | */ | 34 | */ |
35 | 35 | ||
36 | import org.onosproject.yangutils.datamodel.YangBit; | 36 | import org.onosproject.yangutils.datamodel.YangBit; |
... | @@ -44,6 +44,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc | ... | @@ -44,6 +44,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc |
44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 44 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 45 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 46 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
47 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
47 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 48 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
48 | import static org.onosproject.yangutils.utils.YangConstructType.POSITION_DATA; | 49 | import static org.onosproject.yangutils.utils.YangConstructType.POSITION_DATA; |
49 | 50 | ||
... | @@ -73,25 +74,27 @@ public final class PositionListener { | ... | @@ -73,25 +74,27 @@ public final class PositionListener { |
73 | GeneratedYangParser.PositionStatementContext ctx) { | 74 | GeneratedYangParser.PositionStatementContext ctx) { |
74 | 75 | ||
75 | // Check for stack to be non empty. | 76 | // Check for stack to be non empty. |
76 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, POSITION_DATA, ctx.INTEGER().getText(), ENTRY); | 77 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, POSITION_DATA, ctx.string().getText(), ENTRY); |
78 | + | ||
79 | + String position = removeQuotesAndHandleConcat(ctx.string().getText()); | ||
77 | 80 | ||
78 | // Obtain the node of the stack. | 81 | // Obtain the node of the stack. |
79 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 82 | Parsable tmpNode = listener.getParsedDataStack().peek(); |
80 | switch (tmpNode.getYangConstructType()) { | 83 | switch (tmpNode.getYangConstructType()) { |
81 | case BIT_DATA: { | 84 | case BIT_DATA: { |
82 | YangBit bitNode = (YangBit) tmpNode; | 85 | YangBit bitNode = (YangBit) tmpNode; |
83 | - if (!isBitPositionValid(listener, ctx)) { | 86 | + if (!isBitPositionValid(listener, ctx, position)) { |
84 | ParserException parserException = new ParserException(errMsg); | 87 | ParserException parserException = new ParserException(errMsg); |
85 | - parserException.setLine(ctx.INTEGER().getSymbol().getLine()); | 88 | + parserException.setLine(ctx.getStart().getLine()); |
86 | - parserException.setCharPosition(ctx.INTEGER().getSymbol().getCharPositionInLine()); | 89 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); |
87 | throw parserException; | 90 | throw parserException; |
88 | } | 91 | } |
89 | - bitNode.setPosition(Integer.valueOf(ctx.INTEGER().getText())); | 92 | + bitNode.setPosition(Integer.valueOf(position)); |
90 | break; | 93 | break; |
91 | } | 94 | } |
92 | default: | 95 | default: |
93 | throw new ParserException( | 96 | throw new ParserException( |
94 | - constructListenerErrorMessage(INVALID_HOLDER, POSITION_DATA, ctx.INTEGER().getText(), ENTRY)); | 97 | + constructListenerErrorMessage(INVALID_HOLDER, POSITION_DATA, ctx.string().getText(), ENTRY)); |
95 | } | 98 | } |
96 | } | 99 | } |
97 | 100 | ||
... | @@ -103,13 +106,13 @@ public final class PositionListener { | ... | @@ -103,13 +106,13 @@ public final class PositionListener { |
103 | * @return validation result | 106 | * @return validation result |
104 | */ | 107 | */ |
105 | private static boolean isBitPositionValid(TreeWalkListener listener, | 108 | private static boolean isBitPositionValid(TreeWalkListener listener, |
106 | - GeneratedYangParser.PositionStatementContext ctx) { | 109 | + GeneratedYangParser.PositionStatementContext ctx, String position) { |
107 | Parsable bitNode = listener.getParsedDataStack().pop(); | 110 | Parsable bitNode = listener.getParsedDataStack().pop(); |
108 | 111 | ||
109 | // Check for stack to be non empty. | 112 | // Check for stack to be non empty. |
110 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, POSITION_DATA, ctx.INTEGER().getText(), ENTRY); | 113 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, POSITION_DATA, ctx.string().getText(), ENTRY); |
111 | 114 | ||
112 | - if (Integer.valueOf(ctx.INTEGER().getText()) < 0) { | 115 | + if (Integer.valueOf(position) < 0) { |
113 | errMsg = "YANG file error: Negative value of position is invalid."; | 116 | errMsg = "YANG file error: Negative value of position is invalid."; |
114 | listener.getParsedDataStack().push(bitNode); | 117 | listener.getParsedDataStack().push(bitNode); |
115 | return false; | 118 | return false; |
... | @@ -120,7 +123,7 @@ public final class PositionListener { | ... | @@ -120,7 +123,7 @@ public final class PositionListener { |
120 | case BITS_DATA: { | 123 | case BITS_DATA: { |
121 | YangBits yangBits = (YangBits) tmpNode; | 124 | YangBits yangBits = (YangBits) tmpNode; |
122 | for (YangBit curBit : yangBits.getBitSet()) { | 125 | for (YangBit curBit : yangBits.getBitSet()) { |
123 | - if (Integer.valueOf(ctx.INTEGER().getText()) == curBit.getPosition()) { | 126 | + if (Integer.valueOf(position) == curBit.getPosition()) { |
124 | errMsg = "YANG file error: Duplicate value of position is invalid."; | 127 | errMsg = "YANG file error: Duplicate value of position is invalid."; |
125 | listener.getParsedDataStack().push(bitNode); | 128 | listener.getParsedDataStack().push(bitNode); |
126 | return false; | 129 | return false; |
... | @@ -132,7 +135,7 @@ public final class PositionListener { | ... | @@ -132,7 +135,7 @@ public final class PositionListener { |
132 | default: | 135 | default: |
133 | listener.getParsedDataStack().push(bitNode); | 136 | listener.getParsedDataStack().push(bitNode); |
134 | throw new ParserException( | 137 | throw new ParserException( |
135 | - constructListenerErrorMessage(INVALID_HOLDER, POSITION_DATA, ctx.INTEGER().getText(), ENTRY)); | 138 | + constructListenerErrorMessage(INVALID_HOLDER, POSITION_DATA, ctx.string().getText(), ENTRY)); |
136 | } | 139 | } |
137 | } | 140 | } |
138 | } | 141 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -24,6 +24,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -24,6 +24,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | 26 | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
27 | import static org.onosproject.yangutils.utils.YangConstructType.PREFIX_DATA; | 28 | import static org.onosproject.yangutils.utils.YangConstructType.PREFIX_DATA; |
28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
... | @@ -51,7 +52,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati | ... | @@ -51,7 +52,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati |
51 | * | prefix_stmt namespace_stmt yang_version_stmt? | 52 | * | prefix_stmt namespace_stmt yang_version_stmt? |
52 | * | prefix_stmt yang_version_stmt? namespace_stmt | 53 | * | prefix_stmt yang_version_stmt? namespace_stmt |
53 | * ; | 54 | * ; |
54 | - * prefix_stmt : PREFIX_KEYWORD IDENTIFIER STMTEND; | 55 | + * prefix_stmt : PREFIX_KEYWORD identifier STMTEND; |
55 | */ | 56 | */ |
56 | 57 | ||
57 | /** | 58 | /** |
... | @@ -76,29 +77,31 @@ public final class PrefixListener { | ... | @@ -76,29 +77,31 @@ public final class PrefixListener { |
76 | public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) { | 77 | public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) { |
77 | 78 | ||
78 | // Check for stack to be non empty. | 79 | // Check for stack to be non empty. |
79 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, PREFIX_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 80 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, PREFIX_DATA, ctx.identifier().getText(), ENTRY); |
81 | + | ||
82 | + String identifier = getValidIdentifier(ctx.identifier().getText(), PREFIX_DATA, ctx); | ||
80 | 83 | ||
81 | // Obtain the node of the stack. | 84 | // Obtain the node of the stack. |
82 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 85 | Parsable tmpNode = listener.getParsedDataStack().peek(); |
83 | switch (tmpNode.getYangConstructType()) { | 86 | switch (tmpNode.getYangConstructType()) { |
84 | case MODULE_DATA: { | 87 | case MODULE_DATA: { |
85 | YangModule module = (YangModule) tmpNode; | 88 | YangModule module = (YangModule) tmpNode; |
86 | - module.setPrefix(ctx.IDENTIFIER().getText()); | 89 | + module.setPrefix(identifier); |
87 | break; | 90 | break; |
88 | } | 91 | } |
89 | case IMPORT_DATA: { | 92 | case IMPORT_DATA: { |
90 | YangImport importNode = (YangImport) tmpNode; | 93 | YangImport importNode = (YangImport) tmpNode; |
91 | - importNode.setPrefixId(ctx.IDENTIFIER().getText()); | 94 | + importNode.setPrefixId(identifier); |
92 | break; | 95 | break; |
93 | } | 96 | } |
94 | case BELONGS_TO_DATA: { | 97 | case BELONGS_TO_DATA: { |
95 | YangBelongsTo belongstoNode = (YangBelongsTo) tmpNode; | 98 | YangBelongsTo belongstoNode = (YangBelongsTo) tmpNode; |
96 | - belongstoNode.setPrefix(ctx.IDENTIFIER().getText()); | 99 | + belongstoNode.setPrefix(identifier); |
97 | break; | 100 | break; |
98 | } | 101 | } |
99 | default: | 102 | default: |
100 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PREFIX_DATA, | 103 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PREFIX_DATA, |
101 | - ctx.IDENTIFIER().getText(), ENTRY)); | 104 | + ctx.identifier().getText(), ENTRY)); |
102 | } | 105 | } |
103 | } | 106 | } |
104 | } | 107 | } | ... | ... |
... | @@ -16,10 +16,6 @@ | ... | @@ -16,10 +16,6 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | -import java.text.ParseException; | ||
20 | -import java.text.SimpleDateFormat; | ||
21 | -import java.util.Date; | ||
22 | - | ||
23 | import org.onosproject.yangutils.datamodel.YangImport; | 19 | import org.onosproject.yangutils.datamodel.YangImport; |
24 | import org.onosproject.yangutils.datamodel.YangInclude; | 20 | import org.onosproject.yangutils.datamodel.YangInclude; |
25 | import org.onosproject.yangutils.parser.Parsable; | 21 | import org.onosproject.yangutils.parser.Parsable; |
... | @@ -27,6 +23,8 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -27,6 +23,8 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
27 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 23 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
28 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 24 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
29 | 25 | ||
26 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid; | ||
30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
32 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
... | @@ -86,13 +84,14 @@ public final class RevisionDateListener { | ... | @@ -86,13 +84,14 @@ public final class RevisionDateListener { |
86 | GeneratedYangParser.RevisionDateStatementContext ctx) { | 84 | GeneratedYangParser.RevisionDateStatementContext ctx) { |
87 | 85 | ||
88 | // Check for stack to be non empty. | 86 | // Check for stack to be non empty. |
89 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.DATE_ARG().getText(), | 87 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.dateArgumentString().getText(), |
90 | ENTRY); | 88 | ENTRY); |
91 | 89 | ||
92 | - if (!isDateValid(ctx.DATE_ARG().getText())) { | 90 | + String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText()); |
91 | + if (!isDateValid(date)) { | ||
93 | ParserException parserException = new ParserException("YANG file error: Input date is not correct"); | 92 | ParserException parserException = new ParserException("YANG file error: Input date is not correct"); |
94 | - parserException.setLine(ctx.DATE_ARG().getSymbol().getLine()); | 93 | + parserException.setLine(ctx.getStart().getLine()); |
95 | - parserException.setCharPosition(ctx.DATE_ARG().getSymbol().getCharPositionInLine()); | 94 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); |
96 | throw parserException; | 95 | throw parserException; |
97 | } | 96 | } |
98 | 97 | ||
... | @@ -101,42 +100,17 @@ public final class RevisionDateListener { | ... | @@ -101,42 +100,17 @@ public final class RevisionDateListener { |
101 | switch (tmpNode.getYangConstructType()) { | 100 | switch (tmpNode.getYangConstructType()) { |
102 | case IMPORT_DATA: { | 101 | case IMPORT_DATA: { |
103 | YangImport importNode = (YangImport) tmpNode; | 102 | YangImport importNode = (YangImport) tmpNode; |
104 | - importNode.setRevision(ctx.DATE_ARG().getText()); | 103 | + importNode.setRevision(date); |
105 | break; | 104 | break; |
106 | } | 105 | } |
107 | case INCLUDE_DATA: { | 106 | case INCLUDE_DATA: { |
108 | YangInclude includeNode = (YangInclude) tmpNode; | 107 | YangInclude includeNode = (YangInclude) tmpNode; |
109 | - includeNode.setRevision(ctx.DATE_ARG().getText()); | 108 | + includeNode.setRevision(date); |
110 | break; | 109 | break; |
111 | } | 110 | } |
112 | default: | 111 | default: |
113 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATE_DATA, | 112 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATE_DATA, |
114 | - ctx.DATE_ARG().getText(), ENTRY)); | 113 | + ctx.dateArgumentString().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; | ||
139 | } | 114 | } |
140 | - return true; | ||
141 | } | 115 | } |
142 | } | 116 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -24,6 +24,8 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -24,6 +24,8 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
24 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 24 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 25 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
26 | 26 | ||
27 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
28 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.isDateValid; | ||
27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER; |
28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; | 30 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER; |
29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; | 31 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER; |
... | @@ -33,10 +35,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc | ... | @@ -33,10 +35,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLoc |
33 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 35 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
34 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; | 36 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty; |
35 | 37 | ||
36 | -import java.text.ParseException; | ||
37 | -import java.text.SimpleDateFormat; | ||
38 | -import java.util.Date; | ||
39 | - | ||
40 | /* | 38 | /* |
41 | * Reference: RFC6020 and YANG ANTLR Grammar | 39 | * Reference: RFC6020 and YANG ANTLR Grammar |
42 | * | 40 | * |
... | @@ -88,7 +86,7 @@ public final class RevisionListener { | ... | @@ -88,7 +86,7 @@ public final class RevisionListener { |
88 | GeneratedYangParser.RevisionStatementContext ctx) { | 86 | GeneratedYangParser.RevisionStatementContext ctx) { |
89 | 87 | ||
90 | // Check for stack to be non empty. | 88 | // Check for stack to be non empty. |
91 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.DATE_ARG().getText(), ENTRY); | 89 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), ENTRY); |
92 | 90 | ||
93 | // Validate for reverse chronological order of revision & for revision | 91 | // Validate for reverse chronological order of revision & for revision |
94 | // value. | 92 | // value. |
... | @@ -97,15 +95,16 @@ public final class RevisionListener { | ... | @@ -97,15 +95,16 @@ public final class RevisionListener { |
97 | // TODO to be implemented. | 95 | // TODO to be implemented. |
98 | } | 96 | } |
99 | 97 | ||
100 | - if (!isDateValid(ctx.DATE_ARG().getText())) { | 98 | + String date = removeQuotesAndHandleConcat(ctx.dateArgumentString().getText()); |
99 | + if (!isDateValid(date)) { | ||
101 | ParserException parserException = new ParserException("YANG file error: Input date is not correct"); | 100 | ParserException parserException = new ParserException("YANG file error: Input date is not correct"); |
102 | - parserException.setLine(ctx.DATE_ARG().getSymbol().getLine()); | 101 | + parserException.setLine(ctx.getStart().getLine()); |
103 | - parserException.setCharPosition(ctx.DATE_ARG().getSymbol().getCharPositionInLine()); | 102 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); |
104 | throw parserException; | 103 | throw parserException; |
105 | } | 104 | } |
106 | 105 | ||
107 | YangRevision revisionNode = new YangRevision(); | 106 | YangRevision revisionNode = new YangRevision(); |
108 | - revisionNode.setRevDate(ctx.DATE_ARG().getText()); | 107 | + revisionNode.setRevDate(date); |
109 | 108 | ||
110 | listener.getParsedDataStack().push(revisionNode); | 109 | listener.getParsedDataStack().push(revisionNode); |
111 | } | 110 | } |
... | @@ -121,14 +120,14 @@ public final class RevisionListener { | ... | @@ -121,14 +120,14 @@ public final class RevisionListener { |
121 | ctx) { | 120 | ctx) { |
122 | 121 | ||
123 | // Check for stack to be non empty. | 122 | // Check for stack to be non empty. |
124 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.DATE_ARG().getText(), EXIT); | 123 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), EXIT); |
125 | 124 | ||
126 | Parsable tmpRevisionNode = listener.getParsedDataStack().peek(); | 125 | Parsable tmpRevisionNode = listener.getParsedDataStack().peek(); |
127 | if (tmpRevisionNode instanceof YangRevision) { | 126 | if (tmpRevisionNode instanceof YangRevision) { |
128 | listener.getParsedDataStack().pop(); | 127 | listener.getParsedDataStack().pop(); |
129 | 128 | ||
130 | // Check for stack to be non empty. | 129 | // Check for stack to be non empty. |
131 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.DATE_ARG().getText(), | 130 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), |
132 | EXIT); | 131 | EXIT); |
133 | 132 | ||
134 | Parsable tmpNode = listener.getParsedDataStack().peek(); | 133 | Parsable tmpNode = listener.getParsedDataStack().peek(); |
... | @@ -145,12 +144,12 @@ public final class RevisionListener { | ... | @@ -145,12 +144,12 @@ public final class RevisionListener { |
145 | } | 144 | } |
146 | default: | 145 | default: |
147 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATA, | 146 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATA, |
148 | - ctx.DATE_ARG().getText(), | 147 | + ctx.dateArgumentString().getText(), |
149 | EXIT)); | 148 | EXIT)); |
150 | } | 149 | } |
151 | } else { | 150 | } else { |
152 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, REVISION_DATA, | 151 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, REVISION_DATA, |
153 | - ctx.DATE_ARG().getText(), EXIT)); | 152 | + ctx.dateArgumentString().getText(), EXIT)); |
154 | } | 153 | } |
155 | } | 154 | } |
156 | 155 | ||
... | @@ -166,29 +165,4 @@ public final class RevisionListener { | ... | @@ -166,29 +165,4 @@ public final class RevisionListener { |
166 | // TODO to be implemented | 165 | // TODO to be implemented |
167 | return true; | 166 | return true; |
168 | } | 167 | } |
169 | - | ||
170 | - /** | ||
171 | - * Validates the revision date. | ||
172 | - * | ||
173 | - * @param dateToValidate input revision date | ||
174 | - * @return validation result, true for success, false for failure | ||
175 | - */ | ||
176 | - private static boolean isDateValid(String dateToValidate) { | ||
177 | - | ||
178 | - if (dateToValidate == null) { | ||
179 | - return false; | ||
180 | - } | ||
181 | - | ||
182 | - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
183 | - sdf.setLenient(false); | ||
184 | - | ||
185 | - try { | ||
186 | - //if not valid, it will throw ParseException | ||
187 | - Date date = sdf.parse(dateToValidate); | ||
188 | - System.out.println(date); | ||
189 | - } catch (ParseException e) { | ||
190 | - return false; | ||
191 | - } | ||
192 | - return true; | ||
193 | - } | ||
194 | } | 168 | } | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
... | @@ -20,6 +20,8 @@ import org.onosproject.yangutils.datamodel.YangSubModule; | ... | @@ -20,6 +20,8 @@ import org.onosproject.yangutils.datamodel.YangSubModule; |
20 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | 20 | import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
21 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 21 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
22 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 22 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
23 | + | ||
24 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
23 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 25 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
24 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 26 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
25 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
... | @@ -45,7 +47,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.SUB_MODULE_DATA; | ... | @@ -45,7 +47,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.SUB_MODULE_DATA; |
45 | * "}" optsep | 47 | * "}" optsep |
46 | * | 48 | * |
47 | * ANTLR grammar rule | 49 | * ANTLR grammar rule |
48 | - * submodule_stmt : SUBMODULE_KEYWORD IDENTIFIER LEFT_CURLY_BRACE submodule_body* RIGHT_CURLY_BRACE; | 50 | + * submodule_stmt : SUBMODULE_KEYWORD identifier LEFT_CURLY_BRACE submodule_body* RIGHT_CURLY_BRACE; |
49 | * submodule_body : submodule_header_statement linkage_stmts meta_stmts revision_stmts body_stmts; | 51 | * submodule_body : submodule_header_statement linkage_stmts meta_stmts revision_stmts body_stmts; |
50 | */ | 52 | */ |
51 | 53 | ||
... | @@ -72,11 +74,13 @@ public final class SubModuleListener { | ... | @@ -72,11 +74,13 @@ public final class SubModuleListener { |
72 | GeneratedYangParser.SubModuleStatementContext ctx) { | 74 | GeneratedYangParser.SubModuleStatementContext ctx) { |
73 | 75 | ||
74 | // Check if stack is empty. | 76 | // Check if stack is empty. |
75 | - checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, ctx.IDENTIFIER().getText(), | 77 | + checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(), |
76 | ENTRY); | 78 | ENTRY); |
77 | 79 | ||
80 | + String identifier = getValidIdentifier(ctx.identifier().getText(), SUB_MODULE_DATA, ctx); | ||
81 | + | ||
78 | YangSubModule yangSubModule = new YangSubModule(); | 82 | YangSubModule yangSubModule = new YangSubModule(); |
79 | - yangSubModule.setName(ctx.IDENTIFIER().getText()); | 83 | + yangSubModule.setName(identifier); |
80 | 84 | ||
81 | if (ctx.submoduleBody(0).submoduleHeaderStatement().yangVersionStatement() == null) { | 85 | if (ctx.submoduleBody(0).submoduleHeaderStatement().yangVersionStatement() == null) { |
82 | yangSubModule.setVersion((byte) 1); | 86 | yangSubModule.setVersion((byte) 1); |
... | @@ -96,12 +100,12 @@ public final class SubModuleListener { | ... | @@ -96,12 +100,12 @@ public final class SubModuleListener { |
96 | GeneratedYangParser.SubModuleStatementContext ctx) { | 100 | GeneratedYangParser.SubModuleStatementContext ctx) { |
97 | 101 | ||
98 | // Check for stack to be non empty. | 102 | // Check for stack to be non empty. |
99 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.IDENTIFIER().getText(), | 103 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(), |
100 | EXIT); | 104 | EXIT); |
101 | 105 | ||
102 | if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) { | 106 | if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) { |
103 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA, | 107 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA, |
104 | - ctx.IDENTIFIER().getText(), EXIT)); | 108 | + ctx.identifier().getText(), EXIT)); |
105 | } | 109 | } |
106 | } | 110 | } |
107 | } | 111 | } | ... | ... |
... | @@ -42,7 +42,7 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -42,7 +42,7 @@ package org.onosproject.yangutils.parser.impl.listeners; |
42 | * "}" | 42 | * "}" |
43 | * | 43 | * |
44 | * ANTLR grammar rule | 44 | * ANTLR grammar rule |
45 | - * typedefStatement : TYPEDEF_KEYWORD IDENTIFIER LEFT_CURLY_BRACE | 45 | + * typedefStatement : TYPEDEF_KEYWORD identifier LEFT_CURLY_BRACE |
46 | * (typeStatement | unitsStatement | defaultStatement | statusStatement | 46 | * (typeStatement | unitsStatement | defaultStatement | statusStatement |
47 | * | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE; | 47 | * | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE; |
48 | */ | 48 | */ |
... | @@ -62,6 +62,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -62,6 +62,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; |
62 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 62 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
63 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; | 63 | import org.onosproject.yangutils.parser.impl.TreeWalkListener; |
64 | 64 | ||
65 | +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier; | ||
65 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 66 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
66 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; | 67 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT; |
67 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; | 68 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage; |
... | @@ -105,7 +106,9 @@ public final class TypeDefListener { | ... | @@ -105,7 +106,9 @@ public final class TypeDefListener { |
105 | GeneratedYangParser.TypedefStatementContext ctx) { | 106 | GeneratedYangParser.TypedefStatementContext ctx) { |
106 | 107 | ||
107 | // Check for stack to be non empty. | 108 | // Check for stack to be non empty. |
108 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.IDENTIFIER().getText(), ENTRY); | 109 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.identifier().getText(), ENTRY); |
110 | + | ||
111 | + String identifier = getValidIdentifier(ctx.identifier().getText(), TYPEDEF_DATA, ctx); | ||
109 | 112 | ||
110 | // Validate sub statement cardinality. | 113 | // Validate sub statement cardinality. |
111 | validateSubStatementsCardinality(ctx); | 114 | validateSubStatementsCardinality(ctx); |
... | @@ -116,7 +119,7 @@ public final class TypeDefListener { | ... | @@ -116,7 +119,7 @@ public final class TypeDefListener { |
116 | */ | 119 | */ |
117 | YangType<YangDerivedType> derivedType = new YangType<YangDerivedType>(); | 120 | YangType<YangDerivedType> derivedType = new YangType<YangDerivedType>(); |
118 | derivedType.setDataType(YangDataTypes.DERIVED); | 121 | derivedType.setDataType(YangDataTypes.DERIVED); |
119 | - derivedType.setDataTypeName(ctx.IDENTIFIER().getText()); | 122 | + derivedType.setDataTypeName(identifier); |
120 | 123 | ||
121 | YangTypeDef typeDefNode = new YangTypeDef(); | 124 | YangTypeDef typeDefNode = new YangTypeDef(); |
122 | typeDefNode.setDerivedType(derivedType); | 125 | typeDefNode.setDerivedType(derivedType); |
... | @@ -133,12 +136,12 @@ public final class TypeDefListener { | ... | @@ -133,12 +136,12 @@ public final class TypeDefListener { |
133 | curNode.addChild(typeDefNode); | 136 | curNode.addChild(typeDefNode); |
134 | } catch (DataModelException e) { | 137 | } catch (DataModelException e) { |
135 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, | 138 | throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, |
136 | - TYPEDEF_DATA, ctx.IDENTIFIER().getText(), ENTRY, e.getMessage())); | 139 | + TYPEDEF_DATA, ctx.identifier().getText(), ENTRY, e.getMessage())); |
137 | } | 140 | } |
138 | listener.getParsedDataStack().push(typeDefNode); | 141 | listener.getParsedDataStack().push(typeDefNode); |
139 | } else { | 142 | } else { |
140 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, | 143 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, |
141 | - TYPEDEF_DATA, ctx.IDENTIFIER().getText(), ENTRY)); | 144 | + TYPEDEF_DATA, ctx.identifier().getText(), ENTRY)); |
142 | } | 145 | } |
143 | } | 146 | } |
144 | 147 | ||
... | @@ -153,7 +156,7 @@ public final class TypeDefListener { | ... | @@ -153,7 +156,7 @@ public final class TypeDefListener { |
153 | GeneratedYangParser.TypedefStatementContext ctx) { | 156 | GeneratedYangParser.TypedefStatementContext ctx) { |
154 | 157 | ||
155 | // Check for stack to be non empty. | 158 | // Check for stack to be non empty. |
156 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.IDENTIFIER().getText(), EXIT); | 159 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.identifier().getText(), EXIT); |
157 | 160 | ||
158 | if (listener.getParsedDataStack().peek() instanceof YangTypeDef) { | 161 | if (listener.getParsedDataStack().peek() instanceof YangTypeDef) { |
159 | YangTypeDef typeDefNode = (YangTypeDef) listener.getParsedDataStack().peek(); | 162 | YangTypeDef typeDefNode = (YangTypeDef) listener.getParsedDataStack().peek(); |
... | @@ -161,13 +164,13 @@ public final class TypeDefListener { | ... | @@ -161,13 +164,13 @@ public final class TypeDefListener { |
161 | typeDefNode.validateDataOnExit(); | 164 | typeDefNode.validateDataOnExit(); |
162 | } catch (DataModelException e) { | 165 | } catch (DataModelException e) { |
163 | throw new ParserException(constructListenerErrorMessage(INVALID_CONTENT, TYPEDEF_DATA, | 166 | throw new ParserException(constructListenerErrorMessage(INVALID_CONTENT, TYPEDEF_DATA, |
164 | - ctx.IDENTIFIER().getText(), EXIT)); | 167 | + ctx.identifier().getText(), EXIT)); |
165 | } | 168 | } |
166 | 169 | ||
167 | listener.getParsedDataStack().pop(); | 170 | listener.getParsedDataStack().pop(); |
168 | } else { | 171 | } else { |
169 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, TYPEDEF_DATA, | 172 | throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, TYPEDEF_DATA, |
170 | - ctx.IDENTIFIER().getText(), EXIT)); | 173 | + ctx.identifier().getText(), EXIT)); |
171 | } | 174 | } |
172 | } | 175 | } |
173 | 176 | ||
... | @@ -178,11 +181,11 @@ public final class TypeDefListener { | ... | @@ -178,11 +181,11 @@ public final class TypeDefListener { |
178 | */ | 181 | */ |
179 | private static void validateSubStatementsCardinality(GeneratedYangParser.TypedefStatementContext ctx) { | 182 | private static void validateSubStatementsCardinality(GeneratedYangParser.TypedefStatementContext ctx) { |
180 | 183 | ||
181 | - validateCardinality(ctx.unitsStatement(), UNITS_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText()); | 184 | + validateCardinality(ctx.unitsStatement(), UNITS_DATA, TYPEDEF_DATA, ctx.identifier().getText()); |
182 | - validateCardinality(ctx.defaultStatement(), DEFAULT_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText()); | 185 | + validateCardinality(ctx.defaultStatement(), DEFAULT_DATA, TYPEDEF_DATA, ctx.identifier().getText()); |
183 | - validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText()); | 186 | + validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, TYPEDEF_DATA, ctx.identifier().getText()); |
184 | - validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText()); | 187 | + validateCardinality(ctx.descriptionStatement(), DESCRIPTION_DATA, TYPEDEF_DATA, ctx.identifier().getText()); |
185 | - validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText()); | 188 | + validateCardinality(ctx.referenceStatement(), REFERENCE_DATA, TYPEDEF_DATA, ctx.identifier().getText()); |
186 | - validateCardinality(ctx.statusStatement(), STATUS_DATA, TYPEDEF_DATA, ctx.IDENTIFIER().getText()); | 189 | + validateCardinality(ctx.statusStatement(), STATUS_DATA, TYPEDEF_DATA, ctx.identifier().getText()); |
187 | } | 190 | } |
188 | } | 191 | } | ... | ... |
... | @@ -23,6 +23,7 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser; | ... | @@ -23,6 +23,7 @@ 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 static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat; | ||
26 | import static org.onosproject.yangutils.utils.YangConstructType.VERSION_DATA; | 27 | import static org.onosproject.yangutils.utils.YangConstructType.VERSION_DATA; |
27 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; | 28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY; |
28 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; | 29 | import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage; |
... | @@ -59,7 +60,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati | ... | @@ -59,7 +60,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati |
59 | * submodule_header_statement : yang_version_stmt? belongs_to_stmt | 60 | * submodule_header_statement : yang_version_stmt? belongs_to_stmt |
60 | * | belongs_to_stmt yang_version_stmt? | 61 | * | belongs_to_stmt yang_version_stmt? |
61 | * ; | 62 | * ; |
62 | - * yang_version_stmt : YANG_VERSION_KEYWORD INTEGER STMTEND; | 63 | + * yang_version_stmt : YANG_VERSION_KEYWORD string STMTEND; |
63 | */ | 64 | */ |
64 | 65 | ||
65 | /** | 66 | /** |
... | @@ -85,13 +86,13 @@ public final class VersionListener { | ... | @@ -85,13 +86,13 @@ public final class VersionListener { |
85 | GeneratedYangParser.YangVersionStatementContext ctx) { | 86 | GeneratedYangParser.YangVersionStatementContext ctx) { |
86 | 87 | ||
87 | // Check for stack to be non empty. | 88 | // Check for stack to be non empty. |
88 | - checkStackIsNotEmpty(listener, MISSING_HOLDER, VERSION_DATA, ctx.INTEGER().getText(), ENTRY); | 89 | + checkStackIsNotEmpty(listener, MISSING_HOLDER, VERSION_DATA, ctx.string().getText(), ENTRY); |
89 | 90 | ||
90 | - Integer version = Integer.valueOf(ctx.INTEGER().getText()); | 91 | + String version = removeQuotesAndHandleConcat(ctx.string().getText()); |
91 | - if (!isVersionValid(version)) { | 92 | + if (!isVersionValid(Integer.valueOf(version))) { |
92 | ParserException parserException = new ParserException("YANG file error: Input version not supported"); | 93 | ParserException parserException = new ParserException("YANG file error: Input version not supported"); |
93 | - parserException.setLine(ctx.INTEGER().getSymbol().getLine()); | 94 | + parserException.setLine(ctx.getStart().getLine()); |
94 | - parserException.setCharPosition(ctx.INTEGER().getSymbol().getCharPositionInLine()); | 95 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); |
95 | throw parserException; | 96 | throw parserException; |
96 | } | 97 | } |
97 | 98 | ||
... | @@ -110,7 +111,7 @@ public final class VersionListener { | ... | @@ -110,7 +111,7 @@ public final class VersionListener { |
110 | } | 111 | } |
111 | default: | 112 | default: |
112 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, VERSION_DATA, | 113 | throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, VERSION_DATA, |
113 | - ctx.INTEGER().getText(), ENTRY)); | 114 | + ctx.string().getText(), ENTRY)); |
114 | } | 115 | } |
115 | } | 116 | } |
116 | 117 | ... | ... |
utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 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.parserutils; | ||
18 | + | ||
19 | +import org.antlr.v4.runtime.ParserRuleContext; | ||
20 | + | ||
21 | +import java.text.ParseException; | ||
22 | +import java.text.SimpleDateFormat; | ||
23 | +import java.util.regex.Pattern; | ||
24 | +import org.onosproject.yangutils.utils.YangConstructType; | ||
25 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
26 | + | ||
27 | +/** | ||
28 | + * It's a utility for listener. | ||
29 | + */ | ||
30 | +public final class ListenerUtil { | ||
31 | + private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*"); | ||
32 | + private static final String PLUS = "+"; | ||
33 | + private static final int IDENTIFIER_LENGTH = 64; | ||
34 | + | ||
35 | + /** | ||
36 | + * Creates a new listener util. | ||
37 | + */ | ||
38 | + private ListenerUtil() { | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * Removes doubles quotes and concatenates if string has plus symbol. | ||
43 | + * | ||
44 | + * @param yangStringData string from yang file | ||
45 | + * @return concatenated string after removing double quotes | ||
46 | + */ | ||
47 | + public static String removeQuotesAndHandleConcat(String yangStringData) { | ||
48 | + | ||
49 | + yangStringData = yangStringData.replace("\"", ""); | ||
50 | + String[] tmpData = yangStringData.split(Pattern.quote(PLUS)); | ||
51 | + StringBuilder builder = new StringBuilder(); | ||
52 | + for (String yangString : tmpData) { | ||
53 | + builder.append(yangString); | ||
54 | + } | ||
55 | + return builder.toString(); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Validates identifier and returns concatenated string if string contains plus symbol. | ||
60 | + * | ||
61 | + * @param identifier string from yang file | ||
62 | + * @param yangConstruct yang construct for creating error message | ||
63 | + * @param ctx yang construct's context to get the line number and character position | ||
64 | + * @return concatenated string after removing double quotes | ||
65 | + */ | ||
66 | + public static String getValidIdentifier(String identifier, YangConstructType yangConstruct, ParserRuleContext ctx) { | ||
67 | + | ||
68 | + String identifierString = removeQuotesAndHandleConcat(identifier); | ||
69 | + ParserException parserException; | ||
70 | + | ||
71 | + if (identifierString.length() > IDENTIFIER_LENGTH) { | ||
72 | + parserException = new ParserException("YANG file error : " + | ||
73 | + YangConstructType.getYangConstructType(yangConstruct) + " name " + identifierString + " is " + | ||
74 | + "greater than 64 characters."); | ||
75 | + } else if (!IDENTIFIER_PATTERN.matcher(identifierString).matches()) { | ||
76 | + parserException = new ParserException("YANG file error : " + | ||
77 | + YangConstructType.getYangConstructType(yangConstruct) + " name " + identifierString + " is not " + | ||
78 | + "valid."); | ||
79 | + } else { | ||
80 | + return identifierString; | ||
81 | + } | ||
82 | + | ||
83 | + parserException.setLine(ctx.getStart().getLine()); | ||
84 | + parserException.setCharPosition(ctx.getStart().getCharPositionInLine()); | ||
85 | + throw parserException; | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Validates the revision date. | ||
90 | + * | ||
91 | + * @param dateToValidate input revision date | ||
92 | + * @return validation result, true for success, false for failure | ||
93 | + */ | ||
94 | + public static boolean isDateValid(String dateToValidate) { | ||
95 | + | ||
96 | + if (dateToValidate == null || !dateToValidate.matches("[0-9]{4}-[0-9]{2}-[0-9]{2}")) { | ||
97 | + return false; | ||
98 | + } | ||
99 | + | ||
100 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
101 | + sdf.setLenient(false); | ||
102 | + | ||
103 | + try { | ||
104 | + //if not valid, it will throw ParseException | ||
105 | + sdf.parse(dateToValidate); | ||
106 | + } catch (ParseException e) { | ||
107 | + return false; | ||
108 | + } | ||
109 | + | ||
110 | + return true; | ||
111 | + } | ||
112 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
... | @@ -226,7 +226,7 @@ public class ContainerListenerTest { | ... | @@ -226,7 +226,7 @@ public class ContainerListenerTest { |
226 | @Test | 226 | @Test |
227 | public void processContainerInvalidIdentifier() throws IOException, ParserException { | 227 | public void processContainerInvalidIdentifier() throws IOException, ParserException { |
228 | thrown.expect(ParserException.class); | 228 | thrown.expect(ParserException.class); |
229 | - thrown.expectMessage("mismatched input '1valid' expecting IDENTIFIER"); | 229 | + thrown.expectMessage("YANG file error : container name 1valid is not valid."); |
230 | YangNode node = manager.getDataModel("src/test/resources/ContainerInvalidIdentifier.yang"); | 230 | YangNode node = manager.getDataModel("src/test/resources/ContainerInvalidIdentifier.yang"); |
231 | } | 231 | } |
232 | } | 232 | } | ... | ... |
... | @@ -85,7 +85,7 @@ public class LeafListListenerTest { | ... | @@ -85,7 +85,7 @@ public class LeafListListenerTest { |
85 | @Test | 85 | @Test |
86 | public void processLeafListInvalidIdentifier() throws IOException, ParserException { | 86 | public void processLeafListInvalidIdentifier() throws IOException, ParserException { |
87 | thrown.expect(ParserException.class); | 87 | thrown.expect(ParserException.class); |
88 | - thrown.expectMessage("mismatched input '1invalid-interval' expecting IDENTIFIER"); | 88 | + thrown.expectMessage("YANG file error : leaf-list name 1invalid-interval is not valid."); |
89 | YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidIdentifier.yang"); | 89 | YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidIdentifier.yang"); |
90 | } | 90 | } |
91 | 91 | ... | ... |
... | @@ -85,7 +85,7 @@ public class LeafListenerTest { | ... | @@ -85,7 +85,7 @@ public class LeafListenerTest { |
85 | @Test | 85 | @Test |
86 | public void processLeafInvalidIdentifier() throws IOException, ParserException { | 86 | public void processLeafInvalidIdentifier() throws IOException, ParserException { |
87 | thrown.expect(ParserException.class); | 87 | thrown.expect(ParserException.class); |
88 | - thrown.expectMessage("mismatched input '1invalid-interval' expecting IDENTIFIER"); | 88 | + thrown.expectMessage("YANG file error : leaf name 1invalid-interval is not valid."); |
89 | YangNode node = manager.getDataModel("src/test/resources/LeafInvalidIdentifier.yang"); | 89 | YangNode node = manager.getDataModel("src/test/resources/LeafInvalidIdentifier.yang"); |
90 | } | 90 | } |
91 | 91 | ... | ... |
... | @@ -205,7 +205,7 @@ public class ListListenerTest { | ... | @@ -205,7 +205,7 @@ public class ListListenerTest { |
205 | @Test | 205 | @Test |
206 | public void processListInvalidIdentifier() throws IOException, ParserException { | 206 | public void processListInvalidIdentifier() throws IOException, ParserException { |
207 | thrown.expect(ParserException.class); | 207 | thrown.expect(ParserException.class); |
208 | - thrown.expectMessage("mismatched input '1valid' expecting IDENTIFIER"); | 208 | + thrown.expectMessage("YANG file error : list name 1valid is not valid."); |
209 | YangNode node = manager.getDataModel("src/test/resources/ListInvalidIdentifier.yang"); | 209 | YangNode node = manager.getDataModel("src/test/resources/ListInvalidIdentifier.yang"); |
210 | } | 210 | } |
211 | } | 211 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -16,7 +16,9 @@ | ... | @@ -16,7 +16,9 @@ |
16 | 16 | ||
17 | package org.onosproject.yangutils.parser.impl.listeners; | 17 | package org.onosproject.yangutils.parser.impl.listeners; |
18 | 18 | ||
19 | +import org.junit.Rule; | ||
19 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | +import org.junit.rules.ExpectedException; | ||
20 | import org.onosproject.yangutils.datamodel.YangModule; | 22 | import org.onosproject.yangutils.datamodel.YangModule; |
21 | import org.onosproject.yangutils.datamodel.YangNode; | 23 | import org.onosproject.yangutils.datamodel.YangNode; |
22 | import org.onosproject.yangutils.datamodel.YangNodeType; | 24 | import org.onosproject.yangutils.datamodel.YangNodeType; |
... | @@ -35,6 +37,9 @@ public class ModuleListenerTest { | ... | @@ -35,6 +37,9 @@ public class ModuleListenerTest { |
35 | 37 | ||
36 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); | 38 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
37 | 39 | ||
40 | + @Rule | ||
41 | + public ExpectedException thrown = ExpectedException.none(); | ||
42 | + | ||
38 | /** | 43 | /** |
39 | * Checks if module listener updates the data model root node. | 44 | * Checks if module listener updates the data model root node. |
40 | */ | 45 | */ |
... | @@ -62,4 +67,15 @@ public class ModuleListenerTest { | ... | @@ -62,4 +67,15 @@ public class ModuleListenerTest { |
62 | 67 | ||
63 | YangNode node = manager.getDataModel("src/test/resources/ModuleWithInvalidIdentifier.yang"); | 68 | YangNode node = manager.getDataModel("src/test/resources/ModuleWithInvalidIdentifier.yang"); |
64 | } | 69 | } |
70 | + | ||
71 | + /** | ||
72 | + * Checks whether exception is thrown when module length is greater than 64 characters. | ||
73 | + */ | ||
74 | + @Test | ||
75 | + public void processModuleInvalidIdentifierLength() throws IOException, ParserException { | ||
76 | + thrown.expect(ParserException.class); | ||
77 | + thrown.expectMessage("YANG file error : module name Testttttttttttttttttttttttttttttttttttttttttttttttttttt" + | ||
78 | + "tttttttttt is greater than 64 characters."); | ||
79 | + YangNode node = manager.getDataModel("src/test/resources/ModuleInvalidIdentifierLength.yang"); | ||
80 | + } | ||
65 | } | 81 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -80,6 +80,45 @@ public class PositionListenerTest { | ... | @@ -80,6 +80,45 @@ public class PositionListenerTest { |
80 | } | 80 | } |
81 | 81 | ||
82 | /** | 82 | /** |
83 | + * Checks position value with double quotes. | ||
84 | + */ | ||
85 | + @Test | ||
86 | + public void processPositionWithDoubleQuotes() throws IOException, ParserException { | ||
87 | + | ||
88 | + YangNode node = manager.getDataModel("src/test/resources/PositionWithDoubleQuotes.yang"); | ||
89 | + | ||
90 | + // Check whether the data model tree returned is of type module. | ||
91 | + assertThat((node instanceof YangModule), is(true)); | ||
92 | + | ||
93 | + // Check whether the node type is set properly to module. | ||
94 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
95 | + | ||
96 | + // Check whether the module name is set correctly. | ||
97 | + YangModule yangNode = (YangModule) node; | ||
98 | + assertThat(yangNode.getName(), is("Test")); | ||
99 | + | ||
100 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
101 | + YangLeaf leafInfo = leafIterator.next(); | ||
102 | + | ||
103 | + assertThat(leafInfo.getLeafName(), is("mybits")); | ||
104 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("bits")); | ||
105 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.BITS)); | ||
106 | + assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(), | ||
107 | + is("mybits")); | ||
108 | + | ||
109 | + Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet(); | ||
110 | + for (YangBit tmp : bitSet) { | ||
111 | + if (tmp.getBitName().equals("disable-nagle")) { | ||
112 | + assertThat(tmp.getPosition(), is(0)); | ||
113 | + } else if (tmp.getBitName().equals("auto-sense-speed")) { | ||
114 | + assertThat(tmp.getPosition(), is(1)); | ||
115 | + } else if (tmp.getBitName().equals("Ten-Mb-only")) { | ||
116 | + assertThat(tmp.getPosition(), is(2)); | ||
117 | + } | ||
118 | + } | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
83 | * Checks explicit value and auto generated value. | 122 | * Checks explicit value and auto generated value. |
84 | */ | 123 | */ |
85 | @Test | 124 | @Test | ... | ... |
... | @@ -56,6 +56,16 @@ public class PrefixListenerTest { | ... | @@ -56,6 +56,16 @@ public class PrefixListenerTest { |
56 | } | 56 | } |
57 | 57 | ||
58 | /** | 58 | /** |
59 | + * Checks prefix value with double quotes. | ||
60 | + */ | ||
61 | + @Test | ||
62 | + public void processPrefixWithDoubleQuotes() throws IOException, ParserException { | ||
63 | + | ||
64 | + YangNode node = manager.getDataModel("src/test/resources/PrefixWithDoubleQuotes.yang"); | ||
65 | + assertThat(((YangModule) node).getPrefix(), is("On")); | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
59 | * Checks that prefix should be present just once. | 69 | * Checks that prefix should be present just once. |
60 | */ | 70 | */ |
61 | @Test(expected = ParserException.class) | 71 | @Test(expected = ParserException.class) | ... | ... |
... | @@ -53,21 +53,29 @@ public class RevisionDateListenerTest { | ... | @@ -53,21 +53,29 @@ public class RevisionDateListenerTest { |
53 | } | 53 | } |
54 | 54 | ||
55 | /** | 55 | /** |
56 | - * Checks revision date should not be in quotes inside include. | 56 | + * Checks revision date in quotes inside include. |
57 | */ | 57 | */ |
58 | - @Test(expected = ParserException.class) | 58 | + @Test |
59 | public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException { | 59 | public void processRevisionDateInQuotesAtInclude() throws IOException, ParserException { |
60 | 60 | ||
61 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang"); | 61 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtInclude.yang"); |
62 | + // Checks for the version value in data model tree. | ||
63 | + assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03")); | ||
64 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | ||
65 | + assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); | ||
62 | } | 66 | } |
63 | 67 | ||
64 | /** | 68 | /** |
65 | - * Checks revision date should not be in quotes inside import. | 69 | + * Checks revision date in quotes inside import. |
66 | */ | 70 | */ |
67 | - @Test(expected = ParserException.class) | 71 | + @Test |
68 | public void processRevisionDateInQuotesAtImport() throws IOException, ParserException { | 72 | public void processRevisionDateInQuotesAtImport() throws IOException, ParserException { |
69 | 73 | ||
70 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang"); | 74 | YangNode node = manager.getDataModel("src/test/resources/RevisionDateInQuotesAtImport.yang"); |
75 | + // Checks for the version value in data model tree. | ||
76 | + assertThat(((YangModule) node).getImportList().get(0).getRevision(), is("2015-02-03")); | ||
77 | + assertThat(((YangModule) node).getIncludeList().get(0).getRevision(), is("2016-02-03")); | ||
78 | + assertThat(((YangModule) node).getIncludeList().get(1).getRevision(), is("2014-02-03")); | ||
71 | } | 79 | } |
72 | 80 | ||
73 | /** | 81 | /** | ... | ... |
... | @@ -56,6 +56,18 @@ public class VersionListenerTest { | ... | @@ -56,6 +56,18 @@ public class VersionListenerTest { |
56 | } | 56 | } |
57 | 57 | ||
58 | /** | 58 | /** |
59 | + * Checks version in double quotes. | ||
60 | + */ | ||
61 | + @Test | ||
62 | + public void processValidVersionWithDoubleQuotes() throws IOException, ParserException { | ||
63 | + | ||
64 | + YangNode node = manager.getDataModel("src/test/resources/ValidVersionWithDoubleQuotes.yang"); | ||
65 | + | ||
66 | + // Checks for the version value in data model tree. | ||
67 | + assertThat(((YangModule) node).getVersion(), is((byte) 1)); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
59 | * Checks if version which is optional paramater is not present. | 71 | * Checks if version which is optional paramater is not present. |
60 | */ | 72 | */ |
61 | @Test | 73 | @Test | ... | ... |
1 | +module Test { | ||
2 | +yang-version 1; | ||
3 | +namespace urn:ietf:params:xml:ns:yang:ietf-ospf; | ||
4 | +prefix "On"; | ||
5 | +import ietf { | ||
6 | +prefix On2; | ||
7 | +revision-date 2015-02-03; | ||
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 | +} |
-
Please register or login to post a comment