OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library engine.html; | 5 library engine.html; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'ast.dart'; | 9 import 'ast.dart'; |
10 import 'element.dart'; | 10 import 'element.dart'; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 * listener to which errors will be reported. [_options] is the analysis | 394 * listener to which errors will be reported. [_options] is the analysis |
395 * options which should be used for parsing. | 395 * options which should be used for parsing. |
396 */ | 396 */ |
397 HtmlParser(Source source, this._errorListener, this._options) : super(source); | 397 HtmlParser(Source source, this._errorListener, this._options) : super(source); |
398 | 398 |
399 @override | 399 @override |
400 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) => | 400 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) => |
401 new XmlAttributeNode(name, equals, value); | 401 new XmlAttributeNode(name, equals, value); |
402 | 402 |
403 @override | 403 @override |
404 XmlTagNode createTagNode(Token nodeStart, Token tag, | 404 XmlTagNode createTagNode( |
405 List<XmlAttributeNode> attributes, Token attributeEnd, | 405 Token nodeStart, |
406 List<XmlTagNode> tagNodes, Token contentEnd, Token closingTag, | 406 Token tag, |
| 407 List<XmlAttributeNode> attributes, |
| 408 Token attributeEnd, |
| 409 List<XmlTagNode> tagNodes, |
| 410 Token contentEnd, |
| 411 Token closingTag, |
407 Token nodeEnd) { | 412 Token nodeEnd) { |
408 if (_isScriptNode(tag, attributes, tagNodes)) { | 413 if (_isScriptNode(tag, attributes, tagNodes)) { |
409 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, | 414 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, |
410 attributes, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); | 415 attributes, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); |
411 String contents = tagNode.content; | 416 String contents = tagNode.content; |
412 int contentOffset = attributeEnd.end; | 417 int contentOffset = attributeEnd.end; |
413 LineInfo_Location location = _lineInfo.getLocation(contentOffset); | 418 LineInfo_Location location = _lineInfo.getLocation(contentOffset); |
414 sc.Scanner scanner = new sc.Scanner(source, | 419 sc.Scanner scanner = new sc.Scanner(source, |
415 new sc.SubSequenceReader(contents, contentOffset), _errorListener); | 420 new sc.SubSequenceReader(contents, contentOffset), _errorListener); |
416 scanner.setSourceStart(location.lineNumber, location.columnNumber); | 421 scanner.setSourceStart(location.lineNumber, location.columnNumber); |
417 sc.Token firstToken = scanner.tokenize(); | 422 sc.Token firstToken = scanner.tokenize(); |
418 Parser parser = new Parser(source, _errorListener); | 423 Parser parser = new Parser(source, _errorListener, |
| 424 enableAssertMessage: _options.enableAssertMessage); |
419 CompilationUnit unit = parser.parseCompilationUnit(firstToken); | 425 CompilationUnit unit = parser.parseCompilationUnit(firstToken); |
420 unit.lineInfo = _lineInfo; | 426 unit.lineInfo = _lineInfo; |
421 tagNode.script = unit; | 427 tagNode.script = unit; |
422 return tagNode; | 428 return tagNode; |
423 } | 429 } |
424 return new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, | 430 return new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, |
425 contentEnd, closingTag, nodeEnd); | 431 contentEnd, closingTag, nodeEnd); |
426 } | 432 } |
427 | 433 |
428 @override | 434 @override |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 * | 528 * |
523 * @param nodeStart the token marking the beginning of the tag | 529 * @param nodeStart the token marking the beginning of the tag |
524 * @param tag the name of the tag | 530 * @param tag the name of the tag |
525 * @param attributes the attributes in the tag | 531 * @param attributes the attributes in the tag |
526 * @param attributeEnd the token terminating the region where attributes can b
e | 532 * @param attributeEnd the token terminating the region where attributes can b
e |
527 * @param tagNodes the children of the tag | 533 * @param tagNodes the children of the tag |
528 * @param contentEnd the token that starts the closing tag | 534 * @param contentEnd the token that starts the closing tag |
529 * @param closingTag the name of the tag that occurs in the closing tag | 535 * @param closingTag the name of the tag that occurs in the closing tag |
530 * @param nodeEnd the last token in the tag | 536 * @param nodeEnd the last token in the tag |
531 */ | 537 */ |
532 HtmlScriptTagNode(Token nodeStart, Token tag, | 538 HtmlScriptTagNode( |
533 List<XmlAttributeNode> attributes, Token attributeEnd, | 539 Token nodeStart, |
534 List<XmlTagNode> tagNodes, Token contentEnd, Token closingTag, | 540 Token tag, |
| 541 List<XmlAttributeNode> attributes, |
| 542 Token attributeEnd, |
| 543 List<XmlTagNode> tagNodes, |
| 544 Token contentEnd, |
| 545 Token closingTag, |
535 Token nodeEnd) | 546 Token nodeEnd) |
536 : super(nodeStart, tag, attributes, attributeEnd, tagNodes, contentEnd, | 547 : super(nodeStart, tag, attributes, attributeEnd, tagNodes, contentEnd, |
537 closingTag, nodeEnd); | 548 closingTag, nodeEnd); |
538 | 549 |
539 /** | 550 /** |
540 * Return the AST structure representing the Dart code within this tag, or `nu
ll` if this | 551 * Return the AST structure representing the Dart code within this tag, or `nu
ll` if this |
541 * tag references an external script. | 552 * tag references an external script. |
542 * | 553 * |
543 * @return the AST structure representing the Dart code within this tag | 554 * @return the AST structure representing the Dart code within this tag |
544 */ | 555 */ |
545 CompilationUnit get script => _script; | 556 CompilationUnit get script => _script; |
546 | 557 |
547 /** | 558 /** |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 * @param nodeStart the token marking the beginning of the tag | 1425 * @param nodeStart the token marking the beginning of the tag |
1415 * @param tag the name of the tag | 1426 * @param tag the name of the tag |
1416 * @param attributes the attributes in the tag | 1427 * @param attributes the attributes in the tag |
1417 * @param attributeEnd the token terminating the region where attributes can b
e | 1428 * @param attributeEnd the token terminating the region where attributes can b
e |
1418 * @param tagNodes the children of the tag | 1429 * @param tagNodes the children of the tag |
1419 * @param contentEnd the token that starts the closing tag | 1430 * @param contentEnd the token that starts the closing tag |
1420 * @param closingTag the name of the tag that occurs in the closing tag | 1431 * @param closingTag the name of the tag that occurs in the closing tag |
1421 * @param nodeEnd the last token in the tag | 1432 * @param nodeEnd the last token in the tag |
1422 * @return the node that was created | 1433 * @return the node that was created |
1423 */ | 1434 */ |
1424 XmlTagNode createTagNode(Token nodeStart, Token tag, | 1435 XmlTagNode createTagNode( |
1425 List<XmlAttributeNode> attributes, Token attributeEnd, | 1436 Token nodeStart, |
1426 List<XmlTagNode> tagNodes, Token contentEnd, Token closingTag, | 1437 Token tag, |
1427 Token nodeEnd) => new XmlTagNode(nodeStart, tag, attributes, attributeEnd, | 1438 List<XmlAttributeNode> attributes, |
1428 tagNodes, contentEnd, closingTag, nodeEnd); | 1439 Token attributeEnd, |
| 1440 List<XmlTagNode> tagNodes, |
| 1441 Token contentEnd, |
| 1442 Token closingTag, |
| 1443 Token nodeEnd) => |
| 1444 new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, |
| 1445 contentEnd, closingTag, nodeEnd); |
1429 | 1446 |
1430 /** | 1447 /** |
1431 * Answer `true` if the specified tag is self closing and thus should never ha
ve content or | 1448 * Answer `true` if the specified tag is self closing and thus should never ha
ve content or |
1432 * child tag nodes. | 1449 * child tag nodes. |
1433 * | 1450 * |
1434 * @param tag the tag (not `null`) | 1451 * @param tag the tag (not `null`) |
1435 * @return `true` if self closing | 1452 * @return `true` if self closing |
1436 */ | 1453 */ |
1437 bool isSelfClosing(Token tag) => false; | 1454 bool isSelfClosing(Token tag) => false; |
1438 | 1455 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 * * (2) the [TokenType.LT] nodeStart of the next sibling node if thi
s node is | 1746 * * (2) the [TokenType.LT] nodeStart of the next sibling node if thi
s node is |
1730 * self closing or the attributeEnd is [TokenType.SLASH_GT], or | 1747 * self closing or the attributeEnd is [TokenType.SLASH_GT], or |
1731 * * (3) [TokenType.EOF] if the node does not have a closing tag and
is the last | 1748 * * (3) [TokenType.EOF] if the node does not have a closing tag and
is the last |
1732 * node in the stream [TokenType.LT_SLASH] token after the content, o
r `null` | 1749 * node in the stream [TokenType.LT_SLASH] token after the content, o
r `null` |
1733 * if there is no content and the attributes ended with [TokenType.SL
ASH_GT]. | 1750 * if there is no content and the attributes ended with [TokenType.SL
ASH_GT]. |
1734 * @param closingTag the closing [TokenType.TAG] after the child elements or `
null` if | 1751 * @param closingTag the closing [TokenType.TAG] after the child elements or `
null` if |
1735 * there is no content and the attributes ended with [TokenType.SLASH
_GT] | 1752 * there is no content and the attributes ended with [TokenType.SLASH
_GT] |
1736 * @param nodeEnd the ending [TokenType.GT] or [TokenType.SLASH_GT] token (not | 1753 * @param nodeEnd the ending [TokenType.GT] or [TokenType.SLASH_GT] token (not |
1737 * `null`) | 1754 * `null`) |
1738 */ | 1755 */ |
1739 XmlTagNode(this.nodeStart, this._tag, List<XmlAttributeNode> attributes, | 1756 XmlTagNode( |
1740 this.attributeEnd, List<XmlTagNode> tagNodes, this.contentEnd, | 1757 this.nodeStart, |
1741 this.closingTag, this.nodeEnd) { | 1758 this._tag, |
| 1759 List<XmlAttributeNode> attributes, |
| 1760 this.attributeEnd, |
| 1761 List<XmlTagNode> tagNodes, |
| 1762 this.contentEnd, |
| 1763 this.closingTag, |
| 1764 this.nodeEnd) { |
1742 this._attributes = becomeParentOfAll(attributes, ifEmpty: NO_ATTRIBUTES); | 1765 this._attributes = becomeParentOfAll(attributes, ifEmpty: NO_ATTRIBUTES); |
1743 this._tagNodes = becomeParentOfAll(tagNodes, ifEmpty: NO_TAG_NODES); | 1766 this._tagNodes = becomeParentOfAll(tagNodes, ifEmpty: NO_TAG_NODES); |
1744 } | 1767 } |
1745 | 1768 |
1746 /** | 1769 /** |
1747 * Answer the receiver's attributes. Callers should not manipulate the returne
d list to edit the | 1770 * Answer the receiver's attributes. Callers should not manipulate the returne
d list to edit the |
1748 * AST structure. | 1771 * AST structure. |
1749 * | 1772 * |
1750 * @return the attributes (not `null`, contains no `null`s) | 1773 * @return the attributes (not `null`, contains no `null`s) |
1751 */ | 1774 */ |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 */ | 1897 */ |
1875 abstract class XmlVisitor<R> { | 1898 abstract class XmlVisitor<R> { |
1876 R visitHtmlScriptTagNode(HtmlScriptTagNode node); | 1899 R visitHtmlScriptTagNode(HtmlScriptTagNode node); |
1877 | 1900 |
1878 R visitHtmlUnit(HtmlUnit htmlUnit); | 1901 R visitHtmlUnit(HtmlUnit htmlUnit); |
1879 | 1902 |
1880 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode); | 1903 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode); |
1881 | 1904 |
1882 R visitXmlTagNode(XmlTagNode xmlTagNode); | 1905 R visitXmlTagNode(XmlTagNode xmlTagNode); |
1883 } | 1906 } |
OLD | NEW |