| 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); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 * | 527 * |
| 523 * @param nodeStart the token marking the beginning of the tag | 528 * @param nodeStart the token marking the beginning of the tag |
| 524 * @param tag the name of the tag | 529 * @param tag the name of the tag |
| 525 * @param attributes the attributes in the tag | 530 * @param attributes the attributes in the tag |
| 526 * @param attributeEnd the token terminating the region where attributes can b
e | 531 * @param attributeEnd the token terminating the region where attributes can b
e |
| 527 * @param tagNodes the children of the tag | 532 * @param tagNodes the children of the tag |
| 528 * @param contentEnd the token that starts the closing tag | 533 * @param contentEnd the token that starts the closing tag |
| 529 * @param closingTag the name of the tag that occurs in the closing tag | 534 * @param closingTag the name of the tag that occurs in the closing tag |
| 530 * @param nodeEnd the last token in the tag | 535 * @param nodeEnd the last token in the tag |
| 531 */ | 536 */ |
| 532 HtmlScriptTagNode(Token nodeStart, Token tag, | 537 HtmlScriptTagNode( |
| 533 List<XmlAttributeNode> attributes, Token attributeEnd, | 538 Token nodeStart, |
| 534 List<XmlTagNode> tagNodes, Token contentEnd, Token closingTag, | 539 Token tag, |
| 540 List<XmlAttributeNode> attributes, |
| 541 Token attributeEnd, |
| 542 List<XmlTagNode> tagNodes, |
| 543 Token contentEnd, |
| 544 Token closingTag, |
| 535 Token nodeEnd) | 545 Token nodeEnd) |
| 536 : super(nodeStart, tag, attributes, attributeEnd, tagNodes, contentEnd, | 546 : super(nodeStart, tag, attributes, attributeEnd, tagNodes, contentEnd, |
| 537 closingTag, nodeEnd); | 547 closingTag, nodeEnd); |
| 538 | 548 |
| 539 /** | 549 /** |
| 540 * Return the AST structure representing the Dart code within this tag, or `nu
ll` if this | 550 * Return the AST structure representing the Dart code within this tag, or `nu
ll` if this |
| 541 * tag references an external script. | 551 * tag references an external script. |
| 542 * | 552 * |
| 543 * @return the AST structure representing the Dart code within this tag | 553 * @return the AST structure representing the Dart code within this tag |
| 544 */ | 554 */ |
| 545 CompilationUnit get script => _script; | 555 CompilationUnit get script => _script; |
| 546 | 556 |
| 547 /** | 557 /** |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 * @param nodeStart the token marking the beginning of the tag | 1424 * @param nodeStart the token marking the beginning of the tag |
| 1415 * @param tag the name of the tag | 1425 * @param tag the name of the tag |
| 1416 * @param attributes the attributes in the tag | 1426 * @param attributes the attributes in the tag |
| 1417 * @param attributeEnd the token terminating the region where attributes can b
e | 1427 * @param attributeEnd the token terminating the region where attributes can b
e |
| 1418 * @param tagNodes the children of the tag | 1428 * @param tagNodes the children of the tag |
| 1419 * @param contentEnd the token that starts the closing tag | 1429 * @param contentEnd the token that starts the closing tag |
| 1420 * @param closingTag the name of the tag that occurs in the closing tag | 1430 * @param closingTag the name of the tag that occurs in the closing tag |
| 1421 * @param nodeEnd the last token in the tag | 1431 * @param nodeEnd the last token in the tag |
| 1422 * @return the node that was created | 1432 * @return the node that was created |
| 1423 */ | 1433 */ |
| 1424 XmlTagNode createTagNode(Token nodeStart, Token tag, | 1434 XmlTagNode createTagNode( |
| 1425 List<XmlAttributeNode> attributes, Token attributeEnd, | 1435 Token nodeStart, |
| 1426 List<XmlTagNode> tagNodes, Token contentEnd, Token closingTag, | 1436 Token tag, |
| 1427 Token nodeEnd) => new XmlTagNode(nodeStart, tag, attributes, attributeEnd, | 1437 List<XmlAttributeNode> attributes, |
| 1428 tagNodes, contentEnd, closingTag, nodeEnd); | 1438 Token attributeEnd, |
| 1439 List<XmlTagNode> tagNodes, |
| 1440 Token contentEnd, |
| 1441 Token closingTag, |
| 1442 Token nodeEnd) => |
| 1443 new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, |
| 1444 contentEnd, closingTag, nodeEnd); |
| 1429 | 1445 |
| 1430 /** | 1446 /** |
| 1431 * Answer `true` if the specified tag is self closing and thus should never ha
ve content or | 1447 * Answer `true` if the specified tag is self closing and thus should never ha
ve content or |
| 1432 * child tag nodes. | 1448 * child tag nodes. |
| 1433 * | 1449 * |
| 1434 * @param tag the tag (not `null`) | 1450 * @param tag the tag (not `null`) |
| 1435 * @return `true` if self closing | 1451 * @return `true` if self closing |
| 1436 */ | 1452 */ |
| 1437 bool isSelfClosing(Token tag) => false; | 1453 bool isSelfClosing(Token tag) => false; |
| 1438 | 1454 |
| (...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 | 1745 * * (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 | 1746 * 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 | 1747 * * (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` | 1748 * 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]. | 1749 * 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 | 1750 * @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] | 1751 * 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 | 1752 * @param nodeEnd the ending [TokenType.GT] or [TokenType.SLASH_GT] token (not |
| 1737 * `null`) | 1753 * `null`) |
| 1738 */ | 1754 */ |
| 1739 XmlTagNode(this.nodeStart, this._tag, List<XmlAttributeNode> attributes, | 1755 XmlTagNode( |
| 1740 this.attributeEnd, List<XmlTagNode> tagNodes, this.contentEnd, | 1756 this.nodeStart, |
| 1741 this.closingTag, this.nodeEnd) { | 1757 this._tag, |
| 1758 List<XmlAttributeNode> attributes, |
| 1759 this.attributeEnd, |
| 1760 List<XmlTagNode> tagNodes, |
| 1761 this.contentEnd, |
| 1762 this.closingTag, |
| 1763 this.nodeEnd) { |
| 1742 this._attributes = becomeParentOfAll(attributes, ifEmpty: NO_ATTRIBUTES); | 1764 this._attributes = becomeParentOfAll(attributes, ifEmpty: NO_ATTRIBUTES); |
| 1743 this._tagNodes = becomeParentOfAll(tagNodes, ifEmpty: NO_TAG_NODES); | 1765 this._tagNodes = becomeParentOfAll(tagNodes, ifEmpty: NO_TAG_NODES); |
| 1744 } | 1766 } |
| 1745 | 1767 |
| 1746 /** | 1768 /** |
| 1747 * Answer the receiver's attributes. Callers should not manipulate the returne
d list to edit the | 1769 * Answer the receiver's attributes. Callers should not manipulate the returne
d list to edit the |
| 1748 * AST structure. | 1770 * AST structure. |
| 1749 * | 1771 * |
| 1750 * @return the attributes (not `null`, contains no `null`s) | 1772 * @return the attributes (not `null`, contains no `null`s) |
| 1751 */ | 1773 */ |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1874 */ | 1896 */ |
| 1875 abstract class XmlVisitor<R> { | 1897 abstract class XmlVisitor<R> { |
| 1876 R visitHtmlScriptTagNode(HtmlScriptTagNode node); | 1898 R visitHtmlScriptTagNode(HtmlScriptTagNode node); |
| 1877 | 1899 |
| 1878 R visitHtmlUnit(HtmlUnit htmlUnit); | 1900 R visitHtmlUnit(HtmlUnit htmlUnit); |
| 1879 | 1901 |
| 1880 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode); | 1902 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode); |
| 1881 | 1903 |
| 1882 R visitXmlTagNode(XmlTagNode xmlTagNode); | 1904 R visitXmlTagNode(XmlTagNode xmlTagNode); |
| 1883 } | 1905 } |
| OLD | NEW |