| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.html; | 8 library engine.html; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 * | 128 * |
| 129 * @param token the next token in the token stream | 129 * @param token the next token in the token stream |
| 130 * @return the token that was passed in | 130 * @return the token that was passed in |
| 131 */ | 131 */ |
| 132 Token setNext(Token token) { | 132 Token setNext(Token token) { |
| 133 _next = token; | 133 _next = token; |
| 134 token.previous = this; | 134 token.previous = this; |
| 135 return token; | 135 return token; |
| 136 } | 136 } |
| 137 | 137 |
| 138 @override |
| 138 String toString() => lexeme; | 139 String toString() => lexeme; |
| 139 } | 140 } |
| 140 | 141 |
| 141 /** | 142 /** |
| 142 * Implementation of [XmlExpression] for an [Expression] embedded without any wr
apping | 143 * Implementation of [XmlExpression] for an [Expression] embedded without any wr
apping |
| 143 * characters. | 144 * characters. |
| 144 */ | 145 */ |
| 145 class RawXmlExpression extends XmlExpression { | 146 class RawXmlExpression extends XmlExpression { |
| 146 final Expression expression; | 147 final Expression expression; |
| 147 | 148 |
| 148 RawXmlExpression(this.expression); | 149 RawXmlExpression(this.expression); |
| 149 | 150 |
| 151 @override |
| 150 int get end => expression.end; | 152 int get end => expression.end; |
| 151 | 153 |
| 154 @override |
| 152 int get length => expression.length; | 155 int get length => expression.length; |
| 153 | 156 |
| 157 @override |
| 154 int get offset => expression.offset; | 158 int get offset => expression.offset; |
| 155 | 159 |
| 160 @override |
| 156 XmlExpression_Reference getReference(int offset) { | 161 XmlExpression_Reference getReference(int offset) { |
| 157 AstNode node = new NodeLocator.con1(offset).searchWithin(expression); | 162 AstNode node = new NodeLocator.con1(offset).searchWithin(expression); |
| 158 if (node != null) { | 163 if (node != null) { |
| 159 Element element = ElementLocator.locate(node); | 164 Element element = ElementLocator.locate(node); |
| 160 return new XmlExpression_Reference(element, node.offset, node.length); | 165 return new XmlExpression_Reference(element, node.offset, node.length); |
| 161 } | 166 } |
| 162 return null; | 167 return null; |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 /** | 171 /** |
| 167 * Instances of the class `RecursiveXmlVisitor` implement an XML visitor that wi
ll recursively | 172 * Instances of the class `RecursiveXmlVisitor` implement an XML visitor that wi
ll recursively |
| 168 * visit all of the nodes in an XML structure. For example, using an instance of
this class to visit | 173 * visit all of the nodes in an XML structure. For example, using an instance of
this class to visit |
| 169 * a [XmlTagNode] will also cause all of the contained [XmlAttributeNode]s and | 174 * a [XmlTagNode] will also cause all of the contained [XmlAttributeNode]s and |
| 170 * [XmlTagNode]s to be visited. | 175 * [XmlTagNode]s to be visited. |
| 171 * | 176 * |
| 172 * Subclasses that override a visit method must either invoke the overridden vis
it method or must | 177 * Subclasses that override a visit method must either invoke the overridden vis
it method or must |
| 173 * explicitly ask the visited node to visit its children. Failure to do so will
cause the children | 178 * explicitly ask the visited node to visit its children. Failure to do so will
cause the children |
| 174 * of the visited node to not be visited. | 179 * of the visited node to not be visited. |
| 175 */ | 180 */ |
| 176 class RecursiveXmlVisitor<R> implements XmlVisitor<R> { | 181 class RecursiveXmlVisitor<R> implements XmlVisitor<R> { |
| 182 @override |
| 177 R visitHtmlScriptTagNode(HtmlScriptTagNode node) { | 183 R visitHtmlScriptTagNode(HtmlScriptTagNode node) { |
| 178 node.visitChildren(this); | 184 node.visitChildren(this); |
| 179 return null; | 185 return null; |
| 180 } | 186 } |
| 181 | 187 |
| 188 @override |
| 182 R visitHtmlUnit(HtmlUnit node) { | 189 R visitHtmlUnit(HtmlUnit node) { |
| 183 node.visitChildren(this); | 190 node.visitChildren(this); |
| 184 return null; | 191 return null; |
| 185 } | 192 } |
| 186 | 193 |
| 194 @override |
| 187 R visitXmlAttributeNode(XmlAttributeNode node) { | 195 R visitXmlAttributeNode(XmlAttributeNode node) { |
| 188 node.visitChildren(this); | 196 node.visitChildren(this); |
| 189 return null; | 197 return null; |
| 190 } | 198 } |
| 191 | 199 |
| 200 @override |
| 192 R visitXmlTagNode(XmlTagNode node) { | 201 R visitXmlTagNode(XmlTagNode node) { |
| 193 node.visitChildren(this); | 202 node.visitChildren(this); |
| 194 return null; | 203 return null; |
| 195 } | 204 } |
| 196 } | 205 } |
| 197 | 206 |
| 198 /** | 207 /** |
| 199 * Utilities locating [Expression]s and [Element]s in [HtmlUnit]. | 208 * Utilities locating [Expression]s and [Element]s in [HtmlUnit]. |
| 200 */ | 209 */ |
| 201 class HtmlUnitUtils { | 210 class HtmlUnitUtils { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 class HtmlUnitUtils_FoundTagNodeError extends Error { | 317 class HtmlUnitUtils_FoundTagNodeError extends Error { |
| 309 } | 318 } |
| 310 | 319 |
| 311 class RecursiveXmlVisitor_HtmlUnitUtils_getAttributeNode extends RecursiveXmlVis
itor<Object> { | 320 class RecursiveXmlVisitor_HtmlUnitUtils_getAttributeNode extends RecursiveXmlVis
itor<Object> { |
| 312 int offset = 0; | 321 int offset = 0; |
| 313 | 322 |
| 314 List<XmlAttributeNode> result; | 323 List<XmlAttributeNode> result; |
| 315 | 324 |
| 316 RecursiveXmlVisitor_HtmlUnitUtils_getAttributeNode(this.offset, this.result) :
super(); | 325 RecursiveXmlVisitor_HtmlUnitUtils_getAttributeNode(this.offset, this.result) :
super(); |
| 317 | 326 |
| 327 @override |
| 318 Object visitXmlAttributeNode(XmlAttributeNode node) { | 328 Object visitXmlAttributeNode(XmlAttributeNode node) { |
| 319 Token nameToken = node.nameToken; | 329 Token nameToken = node.nameToken; |
| 320 if (nameToken.offset <= offset && offset < nameToken.end) { | 330 if (nameToken.offset <= offset && offset < nameToken.end) { |
| 321 result[0] = node; | 331 result[0] = node; |
| 322 throw new HtmlUnitUtils_FoundAttributeNodeError(); | 332 throw new HtmlUnitUtils_FoundAttributeNodeError(); |
| 323 } | 333 } |
| 324 return super.visitXmlAttributeNode(node); | 334 return super.visitXmlAttributeNode(node); |
| 325 } | 335 } |
| 326 } | 336 } |
| 327 | 337 |
| 328 class ExpressionVisitor_HtmlUnitUtils_getExpression extends ExpressionVisitor { | 338 class ExpressionVisitor_HtmlUnitUtils_getExpression extends ExpressionVisitor { |
| 329 int offset = 0; | 339 int offset = 0; |
| 330 | 340 |
| 331 List<Expression> result; | 341 List<Expression> result; |
| 332 | 342 |
| 333 ExpressionVisitor_HtmlUnitUtils_getExpression(this.offset, this.result) : supe
r(); | 343 ExpressionVisitor_HtmlUnitUtils_getExpression(this.offset, this.result) : supe
r(); |
| 334 | 344 |
| 345 @override |
| 335 void visitExpression(Expression expression) { | 346 void visitExpression(Expression expression) { |
| 336 Expression at = HtmlUnitUtils._getExpressionAt(expression, offset); | 347 Expression at = HtmlUnitUtils._getExpressionAt(expression, offset); |
| 337 if (at != null) { | 348 if (at != null) { |
| 338 result[0] = at; | 349 result[0] = at; |
| 339 throw new HtmlUnitUtils_FoundExpressionError(); | 350 throw new HtmlUnitUtils_FoundExpressionError(); |
| 340 } | 351 } |
| 341 } | 352 } |
| 342 } | 353 } |
| 343 | 354 |
| 344 class RecursiveXmlVisitor_HtmlUnitUtils_getTagNode extends RecursiveXmlVisitor<O
bject> { | 355 class RecursiveXmlVisitor_HtmlUnitUtils_getTagNode extends RecursiveXmlVisitor<O
bject> { |
| 345 int offset = 0; | 356 int offset = 0; |
| 346 | 357 |
| 347 List<XmlTagNode> result; | 358 List<XmlTagNode> result; |
| 348 | 359 |
| 349 RecursiveXmlVisitor_HtmlUnitUtils_getTagNode(this.offset, this.result) : super
(); | 360 RecursiveXmlVisitor_HtmlUnitUtils_getTagNode(this.offset, this.result) : super
(); |
| 350 | 361 |
| 362 @override |
| 351 Object visitXmlTagNode(XmlTagNode node) { | 363 Object visitXmlTagNode(XmlTagNode node) { |
| 352 super.visitXmlTagNode(node); | 364 super.visitXmlTagNode(node); |
| 353 Token tagToken = node.tagToken; | 365 Token tagToken = node.tagToken; |
| 354 if (tagToken.offset <= offset && offset < tagToken.end) { | 366 if (tagToken.offset <= offset && offset < tagToken.end) { |
| 355 result[0] = node; | 367 result[0] = node; |
| 356 throw new HtmlUnitUtils_FoundTagNodeError(); | 368 throw new HtmlUnitUtils_FoundTagNodeError(); |
| 357 } | 369 } |
| 358 return null; | 370 return null; |
| 359 } | 371 } |
| 360 } | 372 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 382 * @param tag the name of the tag | 394 * @param tag the name of the tag |
| 383 * @param attributes the attributes in the tag | 395 * @param attributes the attributes in the tag |
| 384 * @param attributeEnd the token terminating the region where attributes can b
e | 396 * @param attributeEnd the token terminating the region where attributes can b
e |
| 385 * @param tagNodes the children of the tag | 397 * @param tagNodes the children of the tag |
| 386 * @param contentEnd the token that starts the closing tag | 398 * @param contentEnd the token that starts the closing tag |
| 387 * @param closingTag the name of the tag that occurs in the closing tag | 399 * @param closingTag the name of the tag that occurs in the closing tag |
| 388 * @param nodeEnd the last token in the tag | 400 * @param nodeEnd the last token in the tag |
| 389 */ | 401 */ |
| 390 HtmlScriptTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> attribute
s, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token closin
gTag, Token nodeEnd) : super(nodeStart, tag, attributes, attributeEnd, tagNodes,
contentEnd, closingTag, nodeEnd); | 402 HtmlScriptTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> attribute
s, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token closin
gTag, Token nodeEnd) : super(nodeStart, tag, attributes, attributeEnd, tagNodes,
contentEnd, closingTag, nodeEnd); |
| 391 | 403 |
| 404 @override |
| 392 accept(XmlVisitor visitor) => visitor.visitHtmlScriptTagNode(this); | 405 accept(XmlVisitor visitor) => visitor.visitHtmlScriptTagNode(this); |
| 393 | 406 |
| 394 /** | 407 /** |
| 395 * Return the AST structure representing the Dart code within this tag, or `nu
ll` if this | 408 * Return the AST structure representing the Dart code within this tag, or `nu
ll` if this |
| 396 * tag references an external script. | 409 * tag references an external script. |
| 397 * | 410 * |
| 398 * @return the AST structure representing the Dart code within this tag | 411 * @return the AST structure representing the Dart code within this tag |
| 399 */ | 412 */ |
| 400 CompilationUnit get script => _script; | 413 CompilationUnit get script => _script; |
| 401 | 414 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 515 |
| 503 /** | 516 /** |
| 504 * Set the element associated with this node. | 517 * Set the element associated with this node. |
| 505 * | 518 * |
| 506 * @param element the element | 519 * @param element the element |
| 507 */ | 520 */ |
| 508 void set element(Element element) { | 521 void set element(Element element) { |
| 509 this._element = element; | 522 this._element = element; |
| 510 } | 523 } |
| 511 | 524 |
| 525 @override |
| 512 String toString() { | 526 String toString() { |
| 513 PrintStringWriter writer = new PrintStringWriter(); | 527 PrintStringWriter writer = new PrintStringWriter(); |
| 514 accept(new ToSourceVisitor(writer)); | 528 accept(new ToSourceVisitor(writer)); |
| 515 return writer.toString(); | 529 return writer.toString(); |
| 516 } | 530 } |
| 517 | 531 |
| 518 /** | 532 /** |
| 519 * Use the given visitor to visit all of the children of this node. The childr
en will be visited | 533 * Use the given visitor to visit all of the children of this node. The childr
en will be visited |
| 520 * in source order. | 534 * in source order. |
| 521 * | 535 * |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 } | 629 } |
| 616 } | 630 } |
| 617 | 631 |
| 618 /** | 632 /** |
| 619 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing | 633 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing |
| 620 * when visiting an AST node. It is intended to be a superclass for classes that
use the visitor | 634 * when visiting an AST node. It is intended to be a superclass for classes that
use the visitor |
| 621 * pattern primarily as a dispatch mechanism (and hence don't need to recursivel
y visit a whole | 635 * pattern primarily as a dispatch mechanism (and hence don't need to recursivel
y visit a whole |
| 622 * structure) and that only need to visit a small number of node types. | 636 * structure) and that only need to visit a small number of node types. |
| 623 */ | 637 */ |
| 624 class SimpleXmlVisitor<R> implements XmlVisitor<R> { | 638 class SimpleXmlVisitor<R> implements XmlVisitor<R> { |
| 639 @override |
| 625 R visitHtmlScriptTagNode(HtmlScriptTagNode node) => null; | 640 R visitHtmlScriptTagNode(HtmlScriptTagNode node) => null; |
| 626 | 641 |
| 642 @override |
| 627 R visitHtmlUnit(HtmlUnit htmlUnit) => null; | 643 R visitHtmlUnit(HtmlUnit htmlUnit) => null; |
| 628 | 644 |
| 645 @override |
| 629 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode) => null; | 646 R visitXmlAttributeNode(XmlAttributeNode xmlAttributeNode) => null; |
| 630 | 647 |
| 648 @override |
| 631 R visitXmlTagNode(XmlTagNode xmlTagNode) => null; | 649 R visitXmlTagNode(XmlTagNode xmlTagNode) => null; |
| 632 } | 650 } |
| 633 | 651 |
| 634 /** | 652 /** |
| 635 * The abstract class `AbstractScanner` implements a scanner for HTML code. Subc
lasses are | 653 * The abstract class `AbstractScanner` implements a scanner for HTML code. Subc
lasses are |
| 636 * required to implement the interface used to access the characters being scann
ed. | 654 * required to implement the interface used to access the characters being scann
ed. |
| 637 */ | 655 */ |
| 638 abstract class AbstractScanner { | 656 abstract class AbstractScanner { |
| 639 static List<String> _NO_PASS_THROUGH_ELEMENTS = <String> []; | 657 static List<String> _NO_PASS_THROUGH_ELEMENTS = <String> []; |
| 640 | 658 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 * | 993 * |
| 976 * @param source the source being scanned | 994 * @param source the source being scanned |
| 977 * @param string the string from which characters will be read | 995 * @param string the string from which characters will be read |
| 978 */ | 996 */ |
| 979 StringScanner(Source source, String string) : super(source) { | 997 StringScanner(Source source, String string) : super(source) { |
| 980 this._string = string; | 998 this._string = string; |
| 981 this._stringLength = string.length; | 999 this._stringLength = string.length; |
| 982 this._charOffset = -1; | 1000 this._charOffset = -1; |
| 983 } | 1001 } |
| 984 | 1002 |
| 1003 @override |
| 985 int get offset => _charOffset; | 1004 int get offset => _charOffset; |
| 986 | 1005 |
| 987 void set offset(int offset) { | 1006 void set offset(int offset) { |
| 988 _charOffset = offset; | 1007 _charOffset = offset; |
| 989 } | 1008 } |
| 990 | 1009 |
| 1010 @override |
| 991 int advance() { | 1011 int advance() { |
| 992 if (++_charOffset < _stringLength) { | 1012 if (++_charOffset < _stringLength) { |
| 993 return _string.codeUnitAt(_charOffset); | 1013 return _string.codeUnitAt(_charOffset); |
| 994 } | 1014 } |
| 995 _charOffset = _stringLength; | 1015 _charOffset = _stringLength; |
| 996 return -1; | 1016 return -1; |
| 997 } | 1017 } |
| 998 | 1018 |
| 1019 @override |
| 999 String getString(int start, int endDelta) => _string.substring(start, _charOff
set + 1 + endDelta).toString(); | 1020 String getString(int start, int endDelta) => _string.substring(start, _charOff
set + 1 + endDelta).toString(); |
| 1000 | 1021 |
| 1022 @override |
| 1001 int peek() { | 1023 int peek() { |
| 1002 if (_charOffset + 1 < _stringLength) { | 1024 if (_charOffset + 1 < _stringLength) { |
| 1003 return _string.codeUnitAt(_charOffset + 1); | 1025 return _string.codeUnitAt(_charOffset + 1); |
| 1004 } | 1026 } |
| 1005 return -1; | 1027 return -1; |
| 1006 } | 1028 } |
| 1007 } | 1029 } |
| 1008 | 1030 |
| 1009 /** | 1031 /** |
| 1010 * Instances of the class `ToSourceVisitor` write a source representation of a v
isited XML | 1032 * Instances of the class `ToSourceVisitor` write a source representation of a v
isited XML |
| 1011 * node (and all of it's children) to a writer. | 1033 * node (and all of it's children) to a writer. |
| 1012 */ | 1034 */ |
| 1013 class ToSourceVisitor implements XmlVisitor<Object> { | 1035 class ToSourceVisitor implements XmlVisitor<Object> { |
| 1014 /** | 1036 /** |
| 1015 * The writer to which the source is to be written. | 1037 * The writer to which the source is to be written. |
| 1016 */ | 1038 */ |
| 1017 PrintWriter _writer; | 1039 PrintWriter _writer; |
| 1018 | 1040 |
| 1019 /** | 1041 /** |
| 1020 * Initialize a newly created visitor to write source code representing the vi
sited nodes to the | 1042 * Initialize a newly created visitor to write source code representing the vi
sited nodes to the |
| 1021 * given writer. | 1043 * given writer. |
| 1022 * | 1044 * |
| 1023 * @param writer the writer to which the source is to be written | 1045 * @param writer the writer to which the source is to be written |
| 1024 */ | 1046 */ |
| 1025 ToSourceVisitor(PrintWriter writer) { | 1047 ToSourceVisitor(PrintWriter writer) { |
| 1026 this._writer = writer; | 1048 this._writer = writer; |
| 1027 } | 1049 } |
| 1028 | 1050 |
| 1051 @override |
| 1029 Object visitHtmlScriptTagNode(HtmlScriptTagNode node) => visitXmlTagNode(node)
; | 1052 Object visitHtmlScriptTagNode(HtmlScriptTagNode node) => visitXmlTagNode(node)
; |
| 1030 | 1053 |
| 1054 @override |
| 1031 Object visitHtmlUnit(HtmlUnit node) { | 1055 Object visitHtmlUnit(HtmlUnit node) { |
| 1032 for (XmlTagNode child in node.tagNodes) { | 1056 for (XmlTagNode child in node.tagNodes) { |
| 1033 _visit(child); | 1057 _visit(child); |
| 1034 } | 1058 } |
| 1035 return null; | 1059 return null; |
| 1036 } | 1060 } |
| 1037 | 1061 |
| 1062 @override |
| 1038 Object visitXmlAttributeNode(XmlAttributeNode node) { | 1063 Object visitXmlAttributeNode(XmlAttributeNode node) { |
| 1039 String name = node.name; | 1064 String name = node.name; |
| 1040 Token value = node.valueToken; | 1065 Token value = node.valueToken; |
| 1041 if (name.length == 0) { | 1066 if (name.length == 0) { |
| 1042 _writer.print("__"); | 1067 _writer.print("__"); |
| 1043 } else { | 1068 } else { |
| 1044 _writer.print(name); | 1069 _writer.print(name); |
| 1045 } | 1070 } |
| 1046 _writer.print("="); | 1071 _writer.print("="); |
| 1047 if (value == null) { | 1072 if (value == null) { |
| 1048 _writer.print("__"); | 1073 _writer.print("__"); |
| 1049 } else { | 1074 } else { |
| 1050 _writer.print(value.lexeme); | 1075 _writer.print(value.lexeme); |
| 1051 } | 1076 } |
| 1052 return null; | 1077 return null; |
| 1053 } | 1078 } |
| 1054 | 1079 |
| 1080 @override |
| 1055 Object visitXmlTagNode(XmlTagNode node) { | 1081 Object visitXmlTagNode(XmlTagNode node) { |
| 1056 _writer.print("<"); | 1082 _writer.print("<"); |
| 1057 String tagName = node.tag; | 1083 String tagName = node.tag; |
| 1058 _writer.print(tagName); | 1084 _writer.print(tagName); |
| 1059 for (XmlAttributeNode attribute in node.attributes) { | 1085 for (XmlAttributeNode attribute in node.attributes) { |
| 1060 _writer.print(" "); | 1086 _writer.print(" "); |
| 1061 _visit(attribute); | 1087 _visit(attribute); |
| 1062 } | 1088 } |
| 1063 _writer.print(node.attributeEnd.lexeme); | 1089 _writer.print(node.attributeEnd.lexeme); |
| 1064 if (node.closingTag != null) { | 1090 if (node.closingTag != null) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 * lexeme for this type of token. | 1161 * lexeme for this type of token. |
| 1136 */ | 1162 */ |
| 1137 final String lexeme; | 1163 final String lexeme; |
| 1138 | 1164 |
| 1139 TokenType(String name, int ordinal, this.lexeme) : super(name, ordinal); | 1165 TokenType(String name, int ordinal, this.lexeme) : super(name, ordinal); |
| 1140 } | 1166 } |
| 1141 | 1167 |
| 1142 class TokenType_EOF extends TokenType { | 1168 class TokenType_EOF extends TokenType { |
| 1143 TokenType_EOF(String name, int ordinal, String arg0) : super(name, ordinal, ar
g0); | 1169 TokenType_EOF(String name, int ordinal, String arg0) : super(name, ordinal, ar
g0); |
| 1144 | 1170 |
| 1171 @override |
| 1145 String toString() => "-eof-"; | 1172 String toString() => "-eof-"; |
| 1146 } | 1173 } |
| 1147 | 1174 |
| 1148 /** | 1175 /** |
| 1149 * Instances of `XmlAttributeNode` represent name/value pairs owned by an [XmlTa
gNode]. | 1176 * Instances of `XmlAttributeNode` represent name/value pairs owned by an [XmlTa
gNode]. |
| 1150 */ | 1177 */ |
| 1151 class XmlAttributeNode extends XmlNode { | 1178 class XmlAttributeNode extends XmlNode { |
| 1152 Token _name; | 1179 Token _name; |
| 1153 | 1180 |
| 1154 final Token equals; | 1181 final Token equals; |
| 1155 | 1182 |
| 1156 Token _value; | 1183 Token _value; |
| 1157 | 1184 |
| 1158 List<XmlExpression> expressions = XmlExpression.EMPTY_ARRAY; | 1185 List<XmlExpression> expressions = XmlExpression.EMPTY_ARRAY; |
| 1159 | 1186 |
| 1160 /** | 1187 /** |
| 1161 * Construct a new instance representing an XML attribute. | 1188 * Construct a new instance representing an XML attribute. |
| 1162 * | 1189 * |
| 1163 * @param name the name token (not `null`). This may be a zero length token if
the attribute | 1190 * @param name the name token (not `null`). This may be a zero length token if
the attribute |
| 1164 * is badly formed. | 1191 * is badly formed. |
| 1165 * @param equals the equals sign or `null` if none | 1192 * @param equals the equals sign or `null` if none |
| 1166 * @param value the value token (not `null`) | 1193 * @param value the value token (not `null`) |
| 1167 */ | 1194 */ |
| 1168 XmlAttributeNode(Token name, this.equals, Token value) { | 1195 XmlAttributeNode(Token name, this.equals, Token value) { |
| 1169 this._name = name; | 1196 this._name = name; |
| 1170 this._value = value; | 1197 this._value = value; |
| 1171 } | 1198 } |
| 1172 | 1199 |
| 1200 @override |
| 1173 accept(XmlVisitor visitor) => visitor.visitXmlAttributeNode(this); | 1201 accept(XmlVisitor visitor) => visitor.visitXmlAttributeNode(this); |
| 1174 | 1202 |
| 1203 @override |
| 1175 Token get beginToken => _name; | 1204 Token get beginToken => _name; |
| 1176 | 1205 |
| 1206 @override |
| 1177 Token get endToken => _value; | 1207 Token get endToken => _value; |
| 1178 | 1208 |
| 1179 /** | 1209 /** |
| 1180 * Answer the attribute name. This may be a zero length string if the attribut
e is badly formed. | 1210 * Answer the attribute name. This may be a zero length string if the attribut
e is badly formed. |
| 1181 * | 1211 * |
| 1182 * @return the name (not `null`) | 1212 * @return the name (not `null`) |
| 1183 */ | 1213 */ |
| 1184 String get name => _name.lexeme; | 1214 String get name => _name.lexeme; |
| 1185 | 1215 |
| 1186 /** | 1216 /** |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 } | 1252 } |
| 1223 | 1253 |
| 1224 /** | 1254 /** |
| 1225 * Answer the attribute value token. A properly formed value will start and en
d with matching | 1255 * Answer the attribute value token. A properly formed value will start and en
d with matching |
| 1226 * quote characters, but the value returned may not be properly formed. | 1256 * quote characters, but the value returned may not be properly formed. |
| 1227 * | 1257 * |
| 1228 * @return the value token or `null` if this represents a badly formed attribu
te | 1258 * @return the value token or `null` if this represents a badly formed attribu
te |
| 1229 */ | 1259 */ |
| 1230 Token get valueToken => _value; | 1260 Token get valueToken => _value; |
| 1231 | 1261 |
| 1262 @override |
| 1232 void visitChildren(XmlVisitor visitor) { | 1263 void visitChildren(XmlVisitor visitor) { |
| 1233 } | 1264 } |
| 1234 } | 1265 } |
| 1235 | 1266 |
| 1236 /** | 1267 /** |
| 1237 * The interface `XmlVisitor` defines the behavior of objects that can be used t
o visit an | 1268 * The interface `XmlVisitor` defines the behavior of objects that can be used t
o visit an |
| 1238 * [XmlNode] structure. | 1269 * [XmlNode] structure. |
| 1239 */ | 1270 */ |
| 1240 abstract class XmlVisitor<R> { | 1271 abstract class XmlVisitor<R> { |
| 1241 R visitHtmlScriptTagNode(HtmlScriptTagNode node); | 1272 R visitHtmlScriptTagNode(HtmlScriptTagNode node); |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 * there is no content and the attributes ended with [TokenType#SLASH
_GT] | 1687 * there is no content and the attributes ended with [TokenType#SLASH
_GT] |
| 1657 * @param nodeEnd the ending [TokenType#GT] or [TokenType#SLASH_GT] token (not | 1688 * @param nodeEnd the ending [TokenType#GT] or [TokenType#SLASH_GT] token (not |
| 1658 * `null`) | 1689 * `null`) |
| 1659 */ | 1690 */ |
| 1660 XmlTagNode(this.nodeStart, Token tag, List<XmlAttributeNode> attributes, this.
attributeEnd, List<XmlTagNode> tagNodes, this.contentEnd, this.closingTag, this.
nodeEnd) { | 1691 XmlTagNode(this.nodeStart, Token tag, List<XmlAttributeNode> attributes, this.
attributeEnd, List<XmlTagNode> tagNodes, this.contentEnd, this.closingTag, this.
nodeEnd) { |
| 1661 this._tag = tag; | 1692 this._tag = tag; |
| 1662 this._attributes = becomeParentOfAll(attributes, ifEmpty: NO_ATTRIBUTES); | 1693 this._attributes = becomeParentOfAll(attributes, ifEmpty: NO_ATTRIBUTES); |
| 1663 this._tagNodes = becomeParentOfAll(tagNodes, ifEmpty: NO_TAG_NODES); | 1694 this._tagNodes = becomeParentOfAll(tagNodes, ifEmpty: NO_TAG_NODES); |
| 1664 } | 1695 } |
| 1665 | 1696 |
| 1697 @override |
| 1666 accept(XmlVisitor visitor) => visitor.visitXmlTagNode(this); | 1698 accept(XmlVisitor visitor) => visitor.visitXmlTagNode(this); |
| 1667 | 1699 |
| 1668 /** | 1700 /** |
| 1669 * Answer the attribute with the specified name. | 1701 * Answer the attribute with the specified name. |
| 1670 * | 1702 * |
| 1671 * @param name the attribute name | 1703 * @param name the attribute name |
| 1672 * @return the attribute or `null` if no matching attribute is found | 1704 * @return the attribute or `null` if no matching attribute is found |
| 1673 */ | 1705 */ |
| 1674 XmlAttributeNode getAttribute(String name) { | 1706 XmlAttributeNode getAttribute(String name) { |
| 1675 for (XmlAttributeNode attribute in _attributes) { | 1707 for (XmlAttributeNode attribute in _attributes) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1694 * [XmlAttributeNode#getText]). | 1726 * [XmlAttributeNode#getText]). |
| 1695 * | 1727 * |
| 1696 * @param name the attribute name | 1728 * @param name the attribute name |
| 1697 * @return the attribute text or `null` if no matching attribute is found | 1729 * @return the attribute text or `null` if no matching attribute is found |
| 1698 */ | 1730 */ |
| 1699 String getAttributeText(String name) { | 1731 String getAttributeText(String name) { |
| 1700 XmlAttributeNode attribute = getAttribute(name); | 1732 XmlAttributeNode attribute = getAttribute(name); |
| 1701 return attribute != null ? attribute.text : null; | 1733 return attribute != null ? attribute.text : null; |
| 1702 } | 1734 } |
| 1703 | 1735 |
| 1736 @override |
| 1704 Token get beginToken => nodeStart; | 1737 Token get beginToken => nodeStart; |
| 1705 | 1738 |
| 1706 /** | 1739 /** |
| 1707 * Answer a string representing the content contained in the receiver. This in
cludes the textual | 1740 * Answer a string representing the content contained in the receiver. This in
cludes the textual |
| 1708 * representation of any child tag nodes ([getTagNodes]). Whitespace between '
<', | 1741 * representation of any child tag nodes ([getTagNodes]). Whitespace between '
<', |
| 1709 * '</', and '>', '/>' is discarded, but all other whitespace is preserved. | 1742 * '</', and '>', '/>' is discarded, but all other whitespace is preserved. |
| 1710 * | 1743 * |
| 1711 * @return the content (not `null`) | 1744 * @return the content (not `null`) |
| 1712 */ | 1745 */ |
| 1713 String get content { | 1746 String get content { |
| 1714 Token token = attributeEnd.next; | 1747 Token token = attributeEnd.next; |
| 1715 if (identical(token, contentEnd)) { | 1748 if (identical(token, contentEnd)) { |
| 1716 return ""; | 1749 return ""; |
| 1717 } | 1750 } |
| 1718 //TODO (danrubel): handle CDATA and replace HTML character encodings with th
e actual characters | 1751 //TODO (danrubel): handle CDATA and replace HTML character encodings with th
e actual characters |
| 1719 String content = token.lexeme; | 1752 String content = token.lexeme; |
| 1720 token = token.next; | 1753 token = token.next; |
| 1721 if (identical(token, contentEnd)) { | 1754 if (identical(token, contentEnd)) { |
| 1722 return content; | 1755 return content; |
| 1723 } | 1756 } |
| 1724 JavaStringBuilder buffer = new JavaStringBuilder(); | 1757 JavaStringBuilder buffer = new JavaStringBuilder(); |
| 1725 while (token != contentEnd) { | 1758 while (token != contentEnd) { |
| 1726 buffer.append(token.lexeme); | 1759 buffer.append(token.lexeme); |
| 1727 token = token.next; | 1760 token = token.next; |
| 1728 } | 1761 } |
| 1729 return buffer.toString(); | 1762 return buffer.toString(); |
| 1730 } | 1763 } |
| 1731 | 1764 |
| 1765 @override |
| 1732 Token get endToken { | 1766 Token get endToken { |
| 1733 if (nodeEnd != null) { | 1767 if (nodeEnd != null) { |
| 1734 return nodeEnd; | 1768 return nodeEnd; |
| 1735 } | 1769 } |
| 1736 if (closingTag != null) { | 1770 if (closingTag != null) { |
| 1737 return closingTag; | 1771 return closingTag; |
| 1738 } | 1772 } |
| 1739 if (contentEnd != null) { | 1773 if (contentEnd != null) { |
| 1740 return contentEnd; | 1774 return contentEnd; |
| 1741 } | 1775 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1766 */ | 1800 */ |
| 1767 List<XmlTagNode> get tagNodes => _tagNodes; | 1801 List<XmlTagNode> get tagNodes => _tagNodes; |
| 1768 | 1802 |
| 1769 /** | 1803 /** |
| 1770 * Answer the [TokenType#TAG] token after the starting '<'. | 1804 * Answer the [TokenType#TAG] token after the starting '<'. |
| 1771 * | 1805 * |
| 1772 * @return the token (not `null`) | 1806 * @return the token (not `null`) |
| 1773 */ | 1807 */ |
| 1774 Token get tagToken => _tag; | 1808 Token get tagToken => _tag; |
| 1775 | 1809 |
| 1810 @override |
| 1776 void visitChildren(XmlVisitor visitor) { | 1811 void visitChildren(XmlVisitor visitor) { |
| 1777 for (XmlAttributeNode node in _attributes) { | 1812 for (XmlAttributeNode node in _attributes) { |
| 1778 node.accept(visitor); | 1813 node.accept(visitor); |
| 1779 } | 1814 } |
| 1780 for (XmlTagNode node in _tagNodes) { | 1815 for (XmlTagNode node in _tagNodes) { |
| 1781 node.accept(visitor); | 1816 node.accept(visitor); |
| 1782 } | 1817 } |
| 1783 } | 1818 } |
| 1784 } | 1819 } |
| 1785 | 1820 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1856 * @param token the first token in the stream of tokens to be parsed | 1891 * @param token the first token in the stream of tokens to be parsed |
| 1857 * @param lineInfo the line information created by the scanner | 1892 * @param lineInfo the line information created by the scanner |
| 1858 * @return the parse result (not `null`) | 1893 * @return the parse result (not `null`) |
| 1859 */ | 1894 */ |
| 1860 HtmlUnit parse(Token token, LineInfo lineInfo) { | 1895 HtmlUnit parse(Token token, LineInfo lineInfo) { |
| 1861 this._lineInfo = lineInfo; | 1896 this._lineInfo = lineInfo; |
| 1862 List<XmlTagNode> tagNodes = parseTopTagNodes(token); | 1897 List<XmlTagNode> tagNodes = parseTopTagNodes(token); |
| 1863 return new HtmlUnit(token, tagNodes, currentToken); | 1898 return new HtmlUnit(token, tagNodes, currentToken); |
| 1864 } | 1899 } |
| 1865 | 1900 |
| 1901 @override |
| 1866 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); | 1902 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); |
| 1867 | 1903 |
| 1904 @override |
| 1868 XmlTagNode createTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> at
tributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token
closingTag, Token nodeEnd) { | 1905 XmlTagNode createTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> at
tributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token
closingTag, Token nodeEnd) { |
| 1869 if (_isScriptNode(tag, attributes, tagNodes)) { | 1906 if (_isScriptNode(tag, attributes, tagNodes)) { |
| 1870 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, attribut
es, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); | 1907 HtmlScriptTagNode tagNode = new HtmlScriptTagNode(nodeStart, tag, attribut
es, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); |
| 1871 String contents = tagNode.content; | 1908 String contents = tagNode.content; |
| 1872 int contentOffset = attributeEnd.end; | 1909 int contentOffset = attributeEnd.end; |
| 1873 LineInfo_Location location = _lineInfo.getLocation(contentOffset); | 1910 LineInfo_Location location = _lineInfo.getLocation(contentOffset); |
| 1874 sc.Scanner scanner = new sc.Scanner(source, new sc.SubSequenceReader(conte
nts, contentOffset), _errorListener); | 1911 sc.Scanner scanner = new sc.Scanner(source, new sc.SubSequenceReader(conte
nts, contentOffset), _errorListener); |
| 1875 scanner.setSourceStart(location.lineNumber, location.columnNumber); | 1912 scanner.setSourceStart(location.lineNumber, location.columnNumber); |
| 1876 sc.Token firstToken = scanner.tokenize(); | 1913 sc.Token firstToken = scanner.tokenize(); |
| 1877 Parser parser = new Parser(source, _errorListener); | 1914 Parser parser = new Parser(source, _errorListener); |
| 1878 CompilationUnit unit = parser.parseCompilationUnit(firstToken); | 1915 CompilationUnit unit = parser.parseCompilationUnit(firstToken); |
| 1879 unit.lineInfo = _lineInfo; | 1916 unit.lineInfo = _lineInfo; |
| 1880 tagNode.script = unit; | 1917 tagNode.script = unit; |
| 1881 return tagNode; | 1918 return tagNode; |
| 1882 } | 1919 } |
| 1883 return new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, co
ntentEnd, closingTag, nodeEnd); | 1920 return new XmlTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, co
ntentEnd, closingTag, nodeEnd); |
| 1884 } | 1921 } |
| 1885 | 1922 |
| 1923 @override |
| 1886 bool isSelfClosing(Token tag) => SELF_CLOSING.contains(tag.lexeme); | 1924 bool isSelfClosing(Token tag) => SELF_CLOSING.contains(tag.lexeme); |
| 1887 | 1925 |
| 1888 /** | 1926 /** |
| 1889 * Determine if the specified node is a Dart script. | 1927 * Determine if the specified node is a Dart script. |
| 1890 * | 1928 * |
| 1891 * @param node the node to be tested (not `null`) | 1929 * @param node the node to be tested (not `null`) |
| 1892 * @return `true` if the node is a Dart script | 1930 * @return `true` if the node is a Dart script |
| 1893 */ | 1931 */ |
| 1894 bool _isScriptNode(Token tag, List<XmlAttributeNode> attributes, List<XmlTagNo
de> tagNodes) { | 1932 bool _isScriptNode(Token tag, List<XmlAttributeNode> attributes, List<XmlTagNo
de> tagNodes) { |
| 1895 if (tagNodes.length != 0 || tag.lexeme != _SCRIPT) { | 1933 if (tagNodes.length != 0 || tag.lexeme != _SCRIPT) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 * | 1973 * |
| 1936 * @param beginToken the first token in the file (not `null`) | 1974 * @param beginToken the first token in the file (not `null`) |
| 1937 * @param tagNodes child tag nodes of the receiver (not `null`, contains no `n
ull`s) | 1975 * @param tagNodes child tag nodes of the receiver (not `null`, contains no `n
ull`s) |
| 1938 * @param endToken the last token in the token stream which should be of type | 1976 * @param endToken the last token in the token stream which should be of type |
| 1939 * [TokenType.EOF] | 1977 * [TokenType.EOF] |
| 1940 */ | 1978 */ |
| 1941 HtmlUnit(this.beginToken, List<XmlTagNode> tagNodes, this.endToken) { | 1979 HtmlUnit(this.beginToken, List<XmlTagNode> tagNodes, this.endToken) { |
| 1942 this._tagNodes = becomeParentOfAll(tagNodes); | 1980 this._tagNodes = becomeParentOfAll(tagNodes); |
| 1943 } | 1981 } |
| 1944 | 1982 |
| 1983 @override |
| 1945 accept(XmlVisitor visitor) => visitor.visitHtmlUnit(this); | 1984 accept(XmlVisitor visitor) => visitor.visitHtmlUnit(this); |
| 1946 | 1985 |
| 1947 /** | 1986 /** |
| 1948 * Return the element associated with this HTML unit. | 1987 * Return the element associated with this HTML unit. |
| 1949 * | 1988 * |
| 1950 * @return the element or `null` if the receiver is not resolved | 1989 * @return the element or `null` if the receiver is not resolved |
| 1951 */ | 1990 */ |
| 1991 @override |
| 1952 HtmlElement get element => super.element as HtmlElement; | 1992 HtmlElement get element => super.element as HtmlElement; |
| 1953 | 1993 |
| 1954 /** | 1994 /** |
| 1955 * Answer the tag nodes contained in the receiver. Callers should not manipula
te the returned list | 1995 * Answer the tag nodes contained in the receiver. Callers should not manipula
te the returned list |
| 1956 * to edit the AST structure. | 1996 * to edit the AST structure. |
| 1957 * | 1997 * |
| 1958 * @return the children (not `null`, contains no `null`s) | 1998 * @return the children (not `null`, contains no `null`s) |
| 1959 */ | 1999 */ |
| 1960 List<XmlTagNode> get tagNodes => _tagNodes; | 2000 List<XmlTagNode> get tagNodes => _tagNodes; |
| 1961 | 2001 |
| 2002 @override |
| 1962 void set element(Element element) { | 2003 void set element(Element element) { |
| 1963 if (element != null && element is! HtmlElement) { | 2004 if (element != null && element is! HtmlElement) { |
| 1964 throw new IllegalArgumentException("HtmlElement expected, but ${element.ru
ntimeType} given"); | 2005 throw new IllegalArgumentException("HtmlElement expected, but ${element.ru
ntimeType} given"); |
| 1965 } | 2006 } |
| 1966 super.element = element; | 2007 super.element = element; |
| 1967 } | 2008 } |
| 1968 | 2009 |
| 2010 @override |
| 1969 void visitChildren(XmlVisitor visitor) { | 2011 void visitChildren(XmlVisitor visitor) { |
| 1970 for (XmlTagNode node in _tagNodes) { | 2012 for (XmlTagNode node in _tagNodes) { |
| 1971 node.accept(visitor); | 2013 node.accept(visitor); |
| 1972 } | 2014 } |
| 1973 } | 2015 } |
| 1974 } | 2016 } |
| OLD | NEW |