OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 /** | 61 /** |
62 * Answer the source being parsed. | 62 * Answer the source being parsed. |
63 * | 63 * |
64 * @return the source | 64 * @return the source |
65 */ | 65 */ |
66 public Source getSource() { | 66 public Source getSource() { |
67 return source; | 67 return source; |
68 } | 68 } |
69 | 69 |
70 /** | 70 /** |
| 71 * Create a node representing an attribute. |
| 72 * |
| 73 * @param name the name of the attribute |
| 74 * @param equals the equals sign, or {@code null} if there is no value |
| 75 * @param value the value of the attribute |
| 76 * @return the node that was created |
| 77 */ |
| 78 protected XmlAttributeNode createAttributeNode(Token name, Token equals, Token
value) { |
| 79 return new XmlAttributeNode(name, equals, value); |
| 80 } |
| 81 |
| 82 /** |
| 83 * Create a node representing a tag. |
| 84 * |
| 85 * @param nodeStart the token marking the beginning of the tag |
| 86 * @param tag the name of the tag |
| 87 * @param attributes the attributes in the tag |
| 88 * @param attributeEnd the token terminating the region where attributes can b
e |
| 89 * @param tagNodes the children of the tag |
| 90 * @param contentEnd the token that starts the closing tag |
| 91 * @param closingTag the name of the tag that occurs in the closing tag |
| 92 * @param nodeEnd the last token in the tag |
| 93 * @return the node that was created |
| 94 */ |
| 95 protected XmlTagNode createTagNode(Token nodeStart, Token tag, List<XmlAttribu
teNode> attributes, |
| 96 Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token clo
singTag, |
| 97 Token nodeEnd) { |
| 98 return new XmlTagNode( |
| 99 nodeStart, |
| 100 tag, |
| 101 attributes, |
| 102 attributeEnd, |
| 103 tagNodes, |
| 104 contentEnd, |
| 105 closingTag, |
| 106 nodeEnd); |
| 107 } |
| 108 |
| 109 /** |
71 * Answer {@code true} if the specified tag is self closing and thus should ne
ver have content or | 110 * Answer {@code true} if the specified tag is self closing and thus should ne
ver have content or |
72 * child tag nodes. | 111 * child tag nodes. |
73 * | 112 * |
74 * @param tag the tag (not {@code null}) | 113 * @param tag the tag (not {@code null}) |
75 * @return {@code true} if self closing | 114 * @return {@code true} if self closing |
76 */ | 115 */ |
77 protected boolean isSelfClosing(Token tag) { | 116 protected boolean isSelfClosing(Token tag) { |
78 return false; | 117 return false; |
79 } | 118 } |
80 | 119 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // String value | 198 // String value |
160 Token value; | 199 Token value; |
161 if (currentToken.getType() == TokenType.STRING) { | 200 if (currentToken.getType() == TokenType.STRING) { |
162 value = currentToken; | 201 value = currentToken; |
163 currentToken = currentToken.getNext(); | 202 currentToken = currentToken.getNext(); |
164 } else { | 203 } else { |
165 reportUnexpectedToken(); | 204 reportUnexpectedToken(); |
166 value = insertSyntheticToken(STRING); | 205 value = insertSyntheticToken(STRING); |
167 } | 206 } |
168 | 207 |
169 return new XmlAttributeNode(name, equals, value); | 208 return createAttributeNode(name, equals, value); |
170 } | 209 } |
171 | 210 |
172 /** | 211 /** |
173 * Parse the stream for a sequence of attributes. This method advances the cur
rent token to the | 212 * Parse the stream for a sequence of attributes. This method advances the cur
rent token to the |
174 * next {@link TokenType#GT}, {@link TokenType#SLASH_GT}, or {@link TokenType#
EOF}. | 213 * next {@link TokenType#GT}, {@link TokenType#SLASH_GT}, or {@link TokenType#
EOF}. |
175 * | 214 * |
176 * @return a collection of zero or more attributes (not {@code null}, contains
no {@code null}s) | 215 * @return a collection of zero or more attributes (not {@code null}, contains
no {@code null}s) |
177 */ | 216 */ |
178 private List<XmlAttributeNode> parseAttributes() { | 217 private List<XmlAttributeNode> parseAttributes() { |
179 TokenType type = currentToken.getType(); | 218 TokenType type = currentToken.getType(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 if (currentToken.getType() == GT || currentToken.getType() == SLASH_GT) { | 306 if (currentToken.getType() == GT || currentToken.getType() == SLASH_GT) { |
268 attributeEnd = currentToken; | 307 attributeEnd = currentToken; |
269 currentToken = currentToken.getNext(); | 308 currentToken = currentToken.getNext(); |
270 } else { | 309 } else { |
271 reportUnexpectedToken(); | 310 reportUnexpectedToken(); |
272 attributeEnd = insertSyntheticToken(SLASH_GT); | 311 attributeEnd = insertSyntheticToken(SLASH_GT); |
273 } | 312 } |
274 | 313 |
275 // If the node has no children, then return the node | 314 // If the node has no children, then return the node |
276 if (attributeEnd.getType() == SLASH_GT || isSelfClosing(tag)) { | 315 if (attributeEnd.getType() == SLASH_GT || isSelfClosing(tag)) { |
277 return new XmlTagNode( | 316 return createTagNode( |
278 nodeStart, | 317 nodeStart, |
279 tag, | 318 tag, |
280 attributes, | 319 attributes, |
281 attributeEnd, | 320 attributeEnd, |
282 XmlTagNode.NO_TAG_NODES, | 321 XmlTagNode.NO_TAG_NODES, |
283 currentToken, | 322 currentToken, |
284 null, | 323 null, |
285 attributeEnd); | 324 attributeEnd); |
286 } | 325 } |
287 | 326 |
(...skipping 25 matching lines...) Expand all Loading... |
313 // Token ending node | 352 // Token ending node |
314 Token nodeEnd; | 353 Token nodeEnd; |
315 if (currentToken.getType() == GT) { | 354 if (currentToken.getType() == GT) { |
316 nodeEnd = currentToken; | 355 nodeEnd = currentToken; |
317 currentToken = currentToken.getNext(); | 356 currentToken = currentToken.getNext(); |
318 } else { | 357 } else { |
319 reportUnexpectedToken(); | 358 reportUnexpectedToken(); |
320 nodeEnd = insertSyntheticToken(GT); | 359 nodeEnd = insertSyntheticToken(GT); |
321 } | 360 } |
322 | 361 |
323 return new XmlTagNode( | 362 return createTagNode( |
324 nodeStart, | 363 nodeStart, |
325 tag, | 364 tag, |
326 attributes, | 365 attributes, |
327 attributeEnd, | 366 attributeEnd, |
328 tagNodes, | 367 tagNodes, |
329 contentEnd, | 368 contentEnd, |
330 closingTag, | 369 closingTag, |
331 nodeEnd); | 370 nodeEnd); |
332 } | 371 } |
333 | 372 |
334 /** | 373 /** |
335 * Report the current token as unexpected | 374 * Report the current token as unexpected |
336 */ | 375 */ |
337 private void reportUnexpectedToken() { | 376 private void reportUnexpectedToken() { |
338 // TODO (danrubel): report unexpected token | 377 // TODO (danrubel): report unexpected token |
339 } | 378 } |
340 } | 379 } |
OLD | NEW |