| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 | 3 |
| 4 library engine.html; | 4 library engine.html; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'java_core.dart'; | 7 import 'java_core.dart'; |
| 8 import 'java_engine.dart'; | 8 import 'java_engine.dart'; |
| 9 import 'source.dart'; | 9 import 'source.dart'; |
| 10 import 'error.dart' show AnalysisErrorListener; | 10 import 'error.dart' show AnalysisErrorListener; |
| 11 import 'scanner.dart' as sc show Scanner, SubSequenceReader, Token; | 11 import 'scanner.dart' as sc show Scanner, SubSequenceReader, Token; |
| 12 import 'parser.dart' show Parser; | 12 import 'parser.dart' show Parser; |
| 13 import 'ast.dart' show ASTVisitor, CompilationUnit, Expression; | 13 import 'ast.dart' show ASTVisitor, CompilationUnit, Expression; |
| 14 import 'element.dart' show HtmlElementImpl, HtmlScriptElement; | 14 import 'element.dart' show HtmlElementImpl, HtmlScriptElement; |
| 15 import 'engine.dart' show AnalysisEngine; | 15 import 'engine.dart' show AnalysisEngine; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Instances of the class `Token` represent a token that was scanned from the in
put. Each | 18 * Instances of the class `Token` represent a token that was scanned from the in
put. Each |
| 19 * token knows which token follows it, acting as the head of a linked list of to
kens. | 19 * token knows which token follows it, acting as the head of a linked list of to
kens. |
| 20 * | 20 * |
| 21 * @coverage dart.engine.html | 21 * @coverage dart.engine.html |
| 22 */ | 22 */ |
| 23 class Token { | 23 class Token { |
| 24 /** | 24 /** |
| 25 * The offset from the beginning of the file to the first character in the tok
en. | 25 * The offset from the beginning of the file to the first character in the tok
en. |
| 26 */ | 26 */ |
| 27 int offset = 0; | 27 int _offset = 0; |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * The previous token in the token stream. | 30 * The previous token in the token stream. |
| 31 */ | 31 */ |
| 32 Token previous; | 32 Token previous; |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * The next token in the token stream. | 35 * The next token in the token stream. |
| 36 */ | 36 */ |
| 37 Token next; | 37 Token _next; |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * The type of the token. | 40 * The type of the token. |
| 41 */ | 41 */ |
| 42 TokenType type; | 42 TokenType _type; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * The lexeme represented by this token. | 45 * The lexeme represented by this token. |
| 46 */ | 46 */ |
| 47 String lexeme; | 47 String _value; |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Initialize a newly created token. | 50 * Initialize a newly created token. |
| 51 * | 51 * |
| 52 * @param type the token type (not `null`) | 52 * @param type the token type (not `null`) |
| 53 * @param offset the offset from the beginning of the file to the first charac
ter in the token | 53 * @param offset the offset from the beginning of the file to the first charac
ter in the token |
| 54 */ | 54 */ |
| 55 Token.con1(TokenType type, int offset) : this.con2(type, offset, type.lexeme); | 55 Token.con1(TokenType type, int offset) : this.con2(type, offset, type.lexeme); |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * Initialize a newly created token. | 58 * Initialize a newly created token. |
| 59 * | 59 * |
| 60 * @param type the token type (not `null`) | 60 * @param type the token type (not `null`) |
| 61 * @param offset the offset from the beginning of the file to the first charac
ter in the token | 61 * @param offset the offset from the beginning of the file to the first charac
ter in the token |
| 62 * @param value the lexeme represented by this token (not `null`) | 62 * @param value the lexeme represented by this token (not `null`) |
| 63 */ | 63 */ |
| 64 Token.con2(TokenType type, int offset, String value) { | 64 Token.con2(TokenType type, int offset, String value) { |
| 65 this.type = type; | 65 this._type = type; |
| 66 this.lexeme = StringUtilities.intern(value); | 66 this._value = StringUtilities.intern(value); |
| 67 this.offset = offset; | 67 this._offset = offset; |
| 68 } | 68 } |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Return the offset from the beginning of the file to the character after las
t character of the | 71 * Return the offset from the beginning of the file to the character after las
t character of the |
| 72 * token. | 72 * token. |
| 73 * | 73 * |
| 74 * @return the offset from the beginning of the file to the first character af
ter last character | 74 * @return the offset from the beginning of the file to the first character af
ter last character |
| 75 * of the token | 75 * of the token |
| 76 */ | 76 */ |
| 77 int get end => offset + length; | 77 int get end => _offset + length; |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Return the number of characters in the node's source range. | 80 * Return the number of characters in the node's source range. |
| 81 * | 81 * |
| 82 * @return the number of characters in the node's source range | 82 * @return the number of characters in the node's source range |
| 83 */ | 83 */ |
| 84 int get length => lexeme.length; | 84 int get length => lexeme.length; |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * Return the lexeme that represents this token. |
| 88 * |
| 89 * @return the lexeme (not `null`) |
| 90 */ |
| 91 String get lexeme => _value; |
| 92 |
| 93 /** |
| 94 * Return the next token in the token stream. |
| 95 * |
| 96 * @return the next token in the token stream |
| 97 */ |
| 98 Token get next => _next; |
| 99 |
| 100 /** |
| 101 * Return the offset from the beginning of the file to the first character in
the token. |
| 102 * |
| 103 * @return the offset from the beginning of the file to the first character in
the token |
| 104 */ |
| 105 int get offset => _offset; |
| 106 |
| 107 /** |
| 108 * Answer the token type for the receiver. |
| 109 * |
| 110 * @return the token type (not `null`) |
| 111 */ |
| 112 TokenType get type => _type; |
| 113 |
| 114 /** |
| 87 * Return `true` if this token is a synthetic token. A synthetic token is a to
ken that was | 115 * Return `true` if this token is a synthetic token. A synthetic token is a to
ken that was |
| 88 * introduced by the parser in order to recover from an error in the code. Syn
thetic tokens always | 116 * introduced by the parser in order to recover from an error in the code. Syn
thetic tokens always |
| 89 * have a length of zero (`0`). | 117 * have a length of zero (`0`). |
| 90 * | 118 * |
| 91 * @return `true` if this token is a synthetic token | 119 * @return `true` if this token is a synthetic token |
| 92 */ | 120 */ |
| 93 bool get isSynthetic => length == 0; | 121 bool get isSynthetic => length == 0; |
| 94 | 122 |
| 95 /** | 123 /** |
| 96 * Set the next token in the token stream to the given token. This has the sid
e-effect of setting | 124 * Set the next token in the token stream to the given token. This has the sid
e-effect of setting |
| 97 * this token to be the previous token for the given token. | 125 * this token to be the previous token for the given token. |
| 98 * | 126 * |
| 99 * @param token the next token in the token stream | 127 * @param token the next token in the token stream |
| 100 * @return the token that was passed in | 128 * @return the token that was passed in |
| 101 */ | 129 */ |
| 102 Token setNext(Token token) { | 130 Token setNext(Token token) { |
| 103 next = token; | 131 _next = token; |
| 104 token.previous = this; | 132 token.previous = this; |
| 105 return token; | 133 return token; |
| 106 } | 134 } |
| 107 | 135 |
| 108 String toString() => lexeme; | 136 String toString() => lexeme; |
| 109 } | 137 } |
| 110 | 138 |
| 111 /** | 139 /** |
| 112 * Instances of the class `EmbeddedExpression` represent an expression enclosed
between | 140 * Instances of the class `EmbeddedExpression` represent an expression enclosed
between |
| 113 * <code>{{</code> and <code>}}</code> delimiters. | 141 * <code>{{</code> and <code>}}</code> delimiters. |
| 114 */ | 142 */ |
| 115 class EmbeddedExpression { | 143 class EmbeddedExpression { |
| 116 /** | 144 /** |
| 117 * The offset of the first character of the opening delimiter. | 145 * The offset of the first character of the opening delimiter. |
| 118 */ | 146 */ |
| 119 int openingOffset = 0; | 147 final int openingOffset; |
| 120 | 148 |
| 121 /** | 149 /** |
| 122 * The expression that is enclosed between the delimiters. | 150 * The expression that is enclosed between the delimiters. |
| 123 */ | 151 */ |
| 124 Expression expression; | 152 final Expression expression; |
| 125 | 153 |
| 126 /** | 154 /** |
| 127 * The offset of the first character of the closing delimiter. | 155 * The offset of the first character of the closing delimiter. |
| 128 */ | 156 */ |
| 129 int closingOffset = 0; | 157 final int closingOffset; |
| 130 | 158 |
| 131 /** | 159 /** |
| 132 * An empty array of embedded expressions. | 160 * An empty array of embedded expressions. |
| 133 */ | 161 */ |
| 134 static List<EmbeddedExpression> EMPTY_ARRAY = new List<EmbeddedExpression>(0); | 162 static List<EmbeddedExpression> EMPTY_ARRAY = new List<EmbeddedExpression>(0); |
| 135 | 163 |
| 136 /** | 164 /** |
| 137 * Initialize a newly created embedded expression to represent the given expre
ssion. | 165 * Initialize a newly created embedded expression to represent the given expre
ssion. |
| 138 * | 166 * |
| 139 * @param openingOffset the offset of the first character of the opening delim
iter | 167 * @param openingOffset the offset of the first character of the opening delim
iter |
| 140 * @param expression the expression that is enclosed between the delimiters | 168 * @param expression the expression that is enclosed between the delimiters |
| 141 * @param closingOffset the offset of the first character of the closing delim
iter | 169 * @param closingOffset the offset of the first character of the closing delim
iter |
| 142 */ | 170 */ |
| 143 EmbeddedExpression(int openingOffset, Expression expression, int closingOffset
) { | 171 EmbeddedExpression(this.openingOffset, this.expression, this.closingOffset); |
| 144 this.openingOffset = openingOffset; | |
| 145 this.expression = expression; | |
| 146 this.closingOffset = closingOffset; | |
| 147 } | |
| 148 } | 172 } |
| 149 | 173 |
| 150 /** | 174 /** |
| 151 * Instances of `HtmlParseResult` hold the result of parsing an HTML file. | 175 * Instances of `HtmlParseResult` hold the result of parsing an HTML file. |
| 152 * | 176 * |
| 153 * @coverage dart.engine.html | 177 * @coverage dart.engine.html |
| 154 */ | 178 */ |
| 155 class HtmlParseResult extends HtmlScanResult { | 179 class HtmlParseResult extends HtmlScanResult { |
| 156 /** | 180 /** |
| 157 * The unit containing the parsed information (not `null`). | 181 * The unit containing the parsed information (not `null`). |
| 158 */ | 182 */ |
| 159 HtmlUnit htmlUnit; | 183 HtmlUnit _unit; |
| 160 | 184 |
| 161 HtmlParseResult(int modificationTime, Token token, List<int> lineStarts, HtmlU
nit unit) : super(modificationTime, token, lineStarts) { | 185 HtmlParseResult(int modificationTime, Token token, List<int> lineStarts, HtmlU
nit unit) : super(modificationTime, token, lineStarts) { |
| 162 this.htmlUnit = unit; | 186 this._unit = unit; |
| 163 } | 187 } |
| 188 |
| 189 /** |
| 190 * Answer the unit generated by parsing the source |
| 191 * |
| 192 * @return the unit (not `null`) |
| 193 */ |
| 194 HtmlUnit get htmlUnit => _unit; |
| 164 } | 195 } |
| 165 | 196 |
| 166 /** | 197 /** |
| 167 * Instances of the class `TagWithEmbeddedExpressions` represent a tag whose tex
t content | 198 * Instances of the class `TagWithEmbeddedExpressions` represent a tag whose tex
t content |
| 168 * contains one or more embedded expressions. | 199 * contains one or more embedded expressions. |
| 169 */ | 200 */ |
| 170 class TagWithEmbeddedExpressions extends XmlTagNode { | 201 class TagWithEmbeddedExpressions extends XmlTagNode { |
| 171 /** | 202 /** |
| 172 * The expressions that are embedded in the tag's content. | 203 * The expressions that are embedded in the tag's content. |
| 173 */ | 204 */ |
| 174 List<EmbeddedExpression> _expressions; | 205 final List<EmbeddedExpression> expressions; |
| 175 | 206 |
| 176 /** | 207 /** |
| 177 * Initialize a newly created tag whose text content contains one or more embe
dded expressions. | 208 * Initialize a newly created tag whose text content contains one or more embe
dded expressions. |
| 178 * | 209 * |
| 179 * @param nodeStart the token marking the beginning of the tag | 210 * @param nodeStart the token marking the beginning of the tag |
| 180 * @param tag the name of the tag | 211 * @param tag the name of the tag |
| 181 * @param attributes the attributes in the tag | 212 * @param attributes the attributes in the tag |
| 182 * @param attributeEnd the token terminating the region where attributes can b
e | 213 * @param attributeEnd the token terminating the region where attributes can b
e |
| 183 * @param tagNodes the children of the tag | 214 * @param tagNodes the children of the tag |
| 184 * @param contentEnd the token that starts the closing tag | 215 * @param contentEnd the token that starts the closing tag |
| 185 * @param closingTag the name of the tag that occurs in the closing tag | 216 * @param closingTag the name of the tag that occurs in the closing tag |
| 186 * @param nodeEnd the last token in the tag | 217 * @param nodeEnd the last token in the tag |
| 187 * @param expressions the expressions that are embedded in the value | 218 * @param expressions the expressions that are embedded in the value |
| 188 */ | 219 */ |
| 189 TagWithEmbeddedExpressions(Token nodeStart, Token tag, List<XmlAttributeNode>
attributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Tok
en closingTag, Token nodeEnd, List<EmbeddedExpression> expressions) : super(node
Start, tag, attributes, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd)
{ | 220 TagWithEmbeddedExpressions(Token nodeStart, Token tag, List<XmlAttributeNode>
attributes, Token attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Tok
en closingTag, Token nodeEnd, this.expressions) : super(nodeStart, tag, attribut
es, attributeEnd, tagNodes, contentEnd, closingTag, nodeEnd); |
| 190 this._expressions = expressions; | |
| 191 } | |
| 192 | |
| 193 List<EmbeddedExpression> get expressions => _expressions; | |
| 194 } | 221 } |
| 195 | 222 |
| 196 /** | 223 /** |
| 197 * Instances of the class `RecursiveXmlVisitor` implement an XML visitor that wi
ll recursively | 224 * Instances of the class `RecursiveXmlVisitor` implement an XML visitor that wi
ll recursively |
| 198 * visit all of the nodes in an XML structure. For example, using an instance of
this class to visit | 225 * visit all of the nodes in an XML structure. For example, using an instance of
this class to visit |
| 199 * a [XmlTagNode] will also cause all of the contained [XmlAttributeNode]s and | 226 * a [XmlTagNode] will also cause all of the contained [XmlAttributeNode]s and |
| 200 * [XmlTagNode]s to be visited. | 227 * [XmlTagNode]s to be visited. |
| 201 * | 228 * |
| 202 * Subclasses that override a visit method must either invoke the overridden vis
it method or must | 229 * Subclasses that override a visit method must either invoke the overridden vis
it method or must |
| 203 * explicitly ask the visited node to visit its children. Failure to do so will
cause the children | 230 * explicitly ask the visited node to visit its children. Failure to do so will
cause the children |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 485 } |
| 459 | 486 |
| 460 /** | 487 /** |
| 461 * Instances of the class `AttributeWithEmbeddedExpressions` represent an attrib
ute whose | 488 * Instances of the class `AttributeWithEmbeddedExpressions` represent an attrib
ute whose |
| 462 * value contains one or more embedded expressions. | 489 * value contains one or more embedded expressions. |
| 463 */ | 490 */ |
| 464 class AttributeWithEmbeddedExpressions extends XmlAttributeNode { | 491 class AttributeWithEmbeddedExpressions extends XmlAttributeNode { |
| 465 /** | 492 /** |
| 466 * The expressions that are embedded in the attribute's value. | 493 * The expressions that are embedded in the attribute's value. |
| 467 */ | 494 */ |
| 468 List<EmbeddedExpression> _expressions; | 495 final List<EmbeddedExpression> expressions; |
| 469 | 496 |
| 470 /** | 497 /** |
| 471 * Initialize a newly created attribute whose value contains one or more embed
ded expressions. | 498 * Initialize a newly created attribute whose value contains one or more embed
ded expressions. |
| 472 * | 499 * |
| 473 * @param name the name of the attribute | 500 * @param name the name of the attribute |
| 474 * @param equals the equals sign separating the name from the value | 501 * @param equals the equals sign separating the name from the value |
| 475 * @param value the value of the attribute | 502 * @param value the value of the attribute |
| 476 * @param expressions the expressions that are embedded in the value | 503 * @param expressions the expressions that are embedded in the value |
| 477 */ | 504 */ |
| 478 AttributeWithEmbeddedExpressions(Token name, Token equals, Token value, List<E
mbeddedExpression> expressions) : super(name, equals, value) { | 505 AttributeWithEmbeddedExpressions(Token name, Token equals, Token value, this.e
xpressions) : super(name, equals, value); |
| 479 this._expressions = expressions; | |
| 480 } | |
| 481 | |
| 482 List<EmbeddedExpression> get expressions => _expressions; | |
| 483 } | 506 } |
| 484 | 507 |
| 485 /** | 508 /** |
| 486 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing | 509 * Instances of the class `SimpleXmlVisitor` implement an AST visitor that will
do nothing |
| 487 * when visiting an AST node. It is intended to be a superclass for classes that
use the visitor | 510 * when visiting an AST node. It is intended to be a superclass for classes that
use the visitor |
| 488 * pattern primarily as a dispatch mechanism (and hence don't need to recursivel
y visit a whole | 511 * pattern primarily as a dispatch mechanism (and hence don't need to recursivel
y visit a whole |
| 489 * structure) and that only need to visit a small number of node types. | 512 * structure) and that only need to visit a small number of node types. |
| 490 */ | 513 */ |
| 491 class SimpleXmlVisitor<R> implements XmlVisitor<R> { | 514 class SimpleXmlVisitor<R> implements XmlVisitor<R> { |
| 492 R visitHtmlScriptTagNode(HtmlScriptTagNode node) => null; | 515 R visitHtmlScriptTagNode(HtmlScriptTagNode node) => null; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 503 * required to implement the interface used to access the characters being scann
ed. | 526 * required to implement the interface used to access the characters being scann
ed. |
| 504 * | 527 * |
| 505 * @coverage dart.engine.html | 528 * @coverage dart.engine.html |
| 506 */ | 529 */ |
| 507 abstract class AbstractScanner { | 530 abstract class AbstractScanner { |
| 508 static List<String> _NO_PASS_THROUGH_ELEMENTS = <String> []; | 531 static List<String> _NO_PASS_THROUGH_ELEMENTS = <String> []; |
| 509 | 532 |
| 510 /** | 533 /** |
| 511 * The source being scanned. | 534 * The source being scanned. |
| 512 */ | 535 */ |
| 513 Source source; | 536 final Source source; |
| 514 | 537 |
| 515 /** | 538 /** |
| 516 * The token pointing to the head of the linked list of tokens. | 539 * The token pointing to the head of the linked list of tokens. |
| 517 */ | 540 */ |
| 518 Token _tokens; | 541 Token _tokens; |
| 519 | 542 |
| 520 /** | 543 /** |
| 521 * The last token that was scanned. | 544 * The last token that was scanned. |
| 522 */ | 545 */ |
| 523 Token _tail; | 546 Token _tail; |
| 524 | 547 |
| 525 /** | 548 /** |
| 526 * A list containing the offsets of the first character of each line in the so
urce code. | 549 * A list containing the offsets of the first character of each line in the so
urce code. |
| 527 */ | 550 */ |
| 528 List<int> _lineStarts = new List<int>(); | 551 List<int> _lineStarts = new List<int>(); |
| 529 | 552 |
| 530 /** | 553 /** |
| 531 * An array of element tags for which the content between tags should be consi
der a single token. | 554 * An array of element tags for which the content between tags should be consi
der a single token. |
| 532 */ | 555 */ |
| 533 List<String> _passThroughElements = _NO_PASS_THROUGH_ELEMENTS; | 556 List<String> _passThroughElements = _NO_PASS_THROUGH_ELEMENTS; |
| 534 | 557 |
| 535 /** | 558 /** |
| 536 * Initialize a newly created scanner. | 559 * Initialize a newly created scanner. |
| 537 * | 560 * |
| 538 * @param source the source being scanned | 561 * @param source the source being scanned |
| 539 */ | 562 */ |
| 540 AbstractScanner(Source source) { | 563 AbstractScanner(this.source) { |
| 541 this.source = source; | |
| 542 _tokens = new Token.con1(TokenType.EOF, -1); | 564 _tokens = new Token.con1(TokenType.EOF, -1); |
| 543 _tokens.setNext(_tokens); | 565 _tokens.setNext(_tokens); |
| 544 _tail = _tokens; | 566 _tail = _tokens; |
| 545 recordStartOfLine(); | 567 recordStartOfLine(); |
| 546 } | 568 } |
| 547 | 569 |
| 548 /** | 570 /** |
| 549 * Return an array containing the offsets of the first character of each line
in the source code. | 571 * Return an array containing the offsets of the first character of each line
in the source code. |
| 550 * | 572 * |
| 551 * @return an array containing the offsets of the first character of each line
in the source code | 573 * @return an array containing the offsets of the first character of each line
in the source code |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 | 831 |
| 810 /** | 832 /** |
| 811 * Instances of `HtmlScanResult` hold the result of scanning an HTML file. | 833 * Instances of `HtmlScanResult` hold the result of scanning an HTML file. |
| 812 * | 834 * |
| 813 * @coverage dart.engine.html | 835 * @coverage dart.engine.html |
| 814 */ | 836 */ |
| 815 class HtmlScanResult { | 837 class HtmlScanResult { |
| 816 /** | 838 /** |
| 817 * The time at which the contents of the source were last set. | 839 * The time at which the contents of the source were last set. |
| 818 */ | 840 */ |
| 819 int modificationTime = 0; | 841 final int modificationTime; |
| 820 | 842 |
| 821 /** | 843 /** |
| 822 * The first token in the token stream (not `null`). | 844 * The first token in the token stream (not `null`). |
| 823 */ | 845 */ |
| 824 Token token; | 846 final Token token; |
| 825 | 847 |
| 826 /** | 848 /** |
| 827 * The line start information that was produced. | 849 * The line start information that was produced. |
| 828 */ | 850 */ |
| 829 List<int> lineStarts; | 851 final List<int> lineStarts; |
| 830 | 852 |
| 831 HtmlScanResult(int modificationTime, Token token, List<int> lineStarts) { | 853 HtmlScanResult(this.modificationTime, this.token, this.lineStarts); |
| 832 this.modificationTime = modificationTime; | |
| 833 this.token = token; | |
| 834 this.lineStarts = lineStarts; | |
| 835 } | |
| 836 } | 854 } |
| 837 | 855 |
| 838 /** | 856 /** |
| 839 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The | 857 * Instances of the class `StringScanner` implement a scanner that reads from a
string. The |
| 840 * scanning logic is in the superclass. | 858 * scanning logic is in the superclass. |
| 841 * | 859 * |
| 842 * @coverage dart.engine.html | 860 * @coverage dart.engine.html |
| 843 */ | 861 */ |
| 844 class StringScanner extends AbstractScanner { | 862 class StringScanner extends AbstractScanner { |
| 845 /** | 863 /** |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 DECLARATION, | 1090 DECLARATION, |
| 1073 DIRECTIVE, | 1091 DIRECTIVE, |
| 1074 STRING, | 1092 STRING, |
| 1075 TAG, | 1093 TAG, |
| 1076 TEXT]; | 1094 TEXT]; |
| 1077 | 1095 |
| 1078 /** | 1096 /** |
| 1079 * The lexeme that defines this type of token, or `null` if there is more than
one possible | 1097 * The lexeme that defines this type of token, or `null` if there is more than
one possible |
| 1080 * lexeme for this type of token. | 1098 * lexeme for this type of token. |
| 1081 */ | 1099 */ |
| 1082 String lexeme; | 1100 final String lexeme; |
| 1083 | 1101 |
| 1084 TokenType(String name, int ordinal, String lexeme) : super(name, ordinal) { | 1102 TokenType(String name, int ordinal, this.lexeme) : super(name, ordinal); |
| 1085 this.lexeme = lexeme; | |
| 1086 } | |
| 1087 } | 1103 } |
| 1088 | 1104 |
| 1089 class TokenType_EOF extends TokenType { | 1105 class TokenType_EOF extends TokenType { |
| 1090 TokenType_EOF(String name, int ordinal, String arg0) : super(name, ordinal, ar
g0); | 1106 TokenType_EOF(String name, int ordinal, String arg0) : super(name, ordinal, ar
g0); |
| 1091 | 1107 |
| 1092 String toString() => "-eof-"; | 1108 String toString() => "-eof-"; |
| 1093 } | 1109 } |
| 1094 | 1110 |
| 1095 /** | 1111 /** |
| 1096 * Instances of `XmlAttributeNode` represent name/value pairs owned by an [XmlTa
gNode]. | 1112 * Instances of `XmlAttributeNode` represent name/value pairs owned by an [XmlTa
gNode]. |
| 1097 * | 1113 * |
| 1098 * @coverage dart.engine.html | 1114 * @coverage dart.engine.html |
| 1099 */ | 1115 */ |
| 1100 class XmlAttributeNode extends XmlNode { | 1116 class XmlAttributeNode extends XmlNode { |
| 1101 Token name; | 1117 final Token name; |
| 1102 | 1118 |
| 1103 Token equals; | 1119 final Token equals; |
| 1104 | 1120 |
| 1105 Token value; | 1121 final Token value; |
| 1106 | 1122 |
| 1107 /** | 1123 /** |
| 1108 * Construct a new instance representing an XML attribute. | 1124 * Construct a new instance representing an XML attribute. |
| 1109 * | 1125 * |
| 1110 * @param name the name token (not `null`). This may be a zero length token if
the attribute | 1126 * @param name the name token (not `null`). This may be a zero length token if
the attribute |
| 1111 * is badly formed. | 1127 * is badly formed. |
| 1112 * @param equals the equals sign or `null` if none | 1128 * @param equals the equals sign or `null` if none |
| 1113 * @param value the value token (not `null`) | 1129 * @param value the value token (not `null`) |
| 1114 */ | 1130 */ |
| 1115 XmlAttributeNode(Token name, Token equals, Token value) { | 1131 XmlAttributeNode(this.name, this.equals, this.value); |
| 1116 this.name = name; | |
| 1117 this.equals = equals; | |
| 1118 this.value = value; | |
| 1119 } | |
| 1120 | 1132 |
| 1121 accept(XmlVisitor visitor) => visitor.visitXmlAttributeNode(this); | 1133 accept(XmlVisitor visitor) => visitor.visitXmlAttributeNode(this); |
| 1122 | 1134 |
| 1123 Token get beginToken => name; | 1135 Token get beginToken => name; |
| 1124 | 1136 |
| 1125 Token get endToken => value; | 1137 Token get endToken => value; |
| 1126 | 1138 |
| 1127 /** | 1139 /** |
| 1128 * Return the expressions that are embedded in the attribute's value. | 1140 * Return the expressions that are embedded in the attribute's value. |
| 1129 * | 1141 * |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 /** | 1312 /** |
| 1301 * Instances of the class `XmlParser` are used to parse tokens into a AST struct
ure comprised | 1313 * Instances of the class `XmlParser` are used to parse tokens into a AST struct
ure comprised |
| 1302 * of [XmlNode]s. | 1314 * of [XmlNode]s. |
| 1303 * | 1315 * |
| 1304 * @coverage dart.engine.html | 1316 * @coverage dart.engine.html |
| 1305 */ | 1317 */ |
| 1306 class XmlParser { | 1318 class XmlParser { |
| 1307 /** | 1319 /** |
| 1308 * The source being parsed. | 1320 * The source being parsed. |
| 1309 */ | 1321 */ |
| 1310 Source source; | 1322 final Source source; |
| 1311 | 1323 |
| 1312 /** | 1324 /** |
| 1313 * The next token to be parsed. | 1325 * The next token to be parsed. |
| 1314 */ | 1326 */ |
| 1315 Token currentToken; | 1327 Token _currentToken; |
| 1316 | 1328 |
| 1317 /** | 1329 /** |
| 1318 * Construct a parser for the specified source. | 1330 * Construct a parser for the specified source. |
| 1319 * | 1331 * |
| 1320 * @param source the source being parsed | 1332 * @param source the source being parsed |
| 1321 */ | 1333 */ |
| 1322 XmlParser(Source source) { | 1334 XmlParser(this.source); |
| 1323 this.source = source; | |
| 1324 } | |
| 1325 | 1335 |
| 1326 /** | 1336 /** |
| 1327 * Create a node representing an attribute. | 1337 * Create a node representing an attribute. |
| 1328 * | 1338 * |
| 1329 * @param name the name of the attribute | 1339 * @param name the name of the attribute |
| 1330 * @param equals the equals sign, or `null` if there is no value | 1340 * @param equals the equals sign, or `null` if there is no value |
| 1331 * @param value the value of the attribute | 1341 * @param value the value of the attribute |
| 1332 * @return the node that was created | 1342 * @return the node that was created |
| 1333 */ | 1343 */ |
| 1334 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); | 1344 XmlAttributeNode createAttributeNode(Token name, Token equals, Token value) =>
new XmlAttributeNode(name, equals, value); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1357 */ | 1367 */ |
| 1358 bool isSelfClosing(Token tag) => false; | 1368 bool isSelfClosing(Token tag) => false; |
| 1359 | 1369 |
| 1360 /** | 1370 /** |
| 1361 * Parse the entire token stream and in the process, advance the current token
to the end of the | 1371 * Parse the entire token stream and in the process, advance the current token
to the end of the |
| 1362 * token stream. | 1372 * token stream. |
| 1363 * | 1373 * |
| 1364 * @return the list of tag nodes found (not `null`, contains no `null`) | 1374 * @return the list of tag nodes found (not `null`, contains no `null`) |
| 1365 */ | 1375 */ |
| 1366 List<XmlTagNode> parseTopTagNodes(Token firstToken) { | 1376 List<XmlTagNode> parseTopTagNodes(Token firstToken) { |
| 1367 currentToken = firstToken; | 1377 _currentToken = firstToken; |
| 1368 List<XmlTagNode> tagNodes = new List<XmlTagNode>(); | 1378 List<XmlTagNode> tagNodes = new List<XmlTagNode>(); |
| 1369 while (true) { | 1379 while (true) { |
| 1370 while (true) { | 1380 while (true) { |
| 1371 if (currentToken.type == TokenType.LT) { | 1381 if (_currentToken.type == TokenType.LT) { |
| 1372 tagNodes.add(parseTagNode()); | 1382 tagNodes.add(parseTagNode()); |
| 1373 } else if (currentToken.type == TokenType.DECLARATION || currentToken.ty
pe == TokenType.DIRECTIVE || currentToken.type == TokenType.COMMENT) { | 1383 } else if (_currentToken.type == TokenType.DECLARATION || _currentToken.
type == TokenType.DIRECTIVE || _currentToken.type == TokenType.COMMENT) { |
| 1374 currentToken = currentToken.next; | 1384 _currentToken = _currentToken.next; |
| 1375 } else if (currentToken.type == TokenType.EOF) { | 1385 } else if (_currentToken.type == TokenType.EOF) { |
| 1376 return tagNodes; | 1386 return tagNodes; |
| 1377 } else { | 1387 } else { |
| 1378 reportUnexpectedToken(); | 1388 reportUnexpectedToken(); |
| 1379 currentToken = currentToken.next; | 1389 _currentToken = _currentToken.next; |
| 1380 } | 1390 } |
| 1381 break; | 1391 break; |
| 1382 } | 1392 } |
| 1383 } | 1393 } |
| 1384 } | 1394 } |
| 1385 | 1395 |
| 1386 /** | 1396 /** |
| 1397 * Answer the current token. |
| 1398 * |
| 1399 * @return the current token |
| 1400 */ |
| 1401 Token get currentToken => _currentToken; |
| 1402 |
| 1403 /** |
| 1387 * Insert a synthetic token of the specified type before the current token | 1404 * Insert a synthetic token of the specified type before the current token |
| 1388 * | 1405 * |
| 1389 * @param type the type of token to be inserted (not `null`) | 1406 * @param type the type of token to be inserted (not `null`) |
| 1390 * @return the synthetic token that was inserted (not `null`) | 1407 * @return the synthetic token that was inserted (not `null`) |
| 1391 */ | 1408 */ |
| 1392 Token insertSyntheticToken(TokenType type) { | 1409 Token insertSyntheticToken(TokenType type) { |
| 1393 Token token = new Token.con2(type, currentToken.offset, ""); | 1410 Token token = new Token.con2(type, _currentToken.offset, ""); |
| 1394 currentToken.previous.setNext(token); | 1411 _currentToken.previous.setNext(token); |
| 1395 token.setNext(currentToken); | 1412 token.setNext(_currentToken); |
| 1396 return token; | 1413 return token; |
| 1397 } | 1414 } |
| 1398 | 1415 |
| 1399 /** | 1416 /** |
| 1400 * Parse the token stream for an attribute. This method advances the current t
oken over the | 1417 * Parse the token stream for an attribute. This method advances the current t
oken over the |
| 1401 * attribute, but should not be called if the [currentToken] is not [TokenType
#TAG]. | 1418 * attribute, but should not be called if the [currentToken] is not [TokenType
#TAG]. |
| 1402 * | 1419 * |
| 1403 * @return the attribute (not `null`) | 1420 * @return the attribute (not `null`) |
| 1404 */ | 1421 */ |
| 1405 XmlAttributeNode parseAttribute() { | 1422 XmlAttributeNode parseAttribute() { |
| 1406 Token name = currentToken; | 1423 Token name = _currentToken; |
| 1407 currentToken = currentToken.next; | 1424 _currentToken = _currentToken.next; |
| 1408 Token equals; | 1425 Token equals; |
| 1409 if (identical(currentToken.type, TokenType.EQ)) { | 1426 if (identical(_currentToken.type, TokenType.EQ)) { |
| 1410 equals = currentToken; | 1427 equals = _currentToken; |
| 1411 currentToken = currentToken.next; | 1428 _currentToken = _currentToken.next; |
| 1412 } else { | 1429 } else { |
| 1413 reportUnexpectedToken(); | 1430 reportUnexpectedToken(); |
| 1414 equals = insertSyntheticToken(TokenType.EQ); | 1431 equals = insertSyntheticToken(TokenType.EQ); |
| 1415 } | 1432 } |
| 1416 Token value; | 1433 Token value; |
| 1417 if (identical(currentToken.type, TokenType.STRING)) { | 1434 if (identical(_currentToken.type, TokenType.STRING)) { |
| 1418 value = currentToken; | 1435 value = _currentToken; |
| 1419 currentToken = currentToken.next; | 1436 _currentToken = _currentToken.next; |
| 1420 } else { | 1437 } else { |
| 1421 reportUnexpectedToken(); | 1438 reportUnexpectedToken(); |
| 1422 value = insertSyntheticToken(TokenType.STRING); | 1439 value = insertSyntheticToken(TokenType.STRING); |
| 1423 } | 1440 } |
| 1424 return createAttributeNode(name, equals, value); | 1441 return createAttributeNode(name, equals, value); |
| 1425 } | 1442 } |
| 1426 | 1443 |
| 1427 /** | 1444 /** |
| 1428 * Parse the stream for a sequence of attributes. This method advances the cur
rent token to the | 1445 * Parse the stream for a sequence of attributes. This method advances the cur
rent token to the |
| 1429 * next [TokenType#GT], [TokenType#SLASH_GT], or [TokenType#EOF]. | 1446 * next [TokenType#GT], [TokenType#SLASH_GT], or [TokenType#EOF]. |
| 1430 * | 1447 * |
| 1431 * @return a collection of zero or more attributes (not `null`, contains no `n
ull`s) | 1448 * @return a collection of zero or more attributes (not `null`, contains no `n
ull`s) |
| 1432 */ | 1449 */ |
| 1433 List<XmlAttributeNode> parseAttributes() { | 1450 List<XmlAttributeNode> parseAttributes() { |
| 1434 TokenType type = currentToken.type; | 1451 TokenType type = _currentToken.type; |
| 1435 if (identical(type, TokenType.GT) || identical(type, TokenType.SLASH_GT) ||
identical(type, TokenType.EOF)) { | 1452 if (identical(type, TokenType.GT) || identical(type, TokenType.SLASH_GT) ||
identical(type, TokenType.EOF)) { |
| 1436 return XmlTagNode.NO_ATTRIBUTES; | 1453 return XmlTagNode.NO_ATTRIBUTES; |
| 1437 } | 1454 } |
| 1438 List<XmlAttributeNode> attributes = new List<XmlAttributeNode>(); | 1455 List<XmlAttributeNode> attributes = new List<XmlAttributeNode>(); |
| 1439 while (true) { | 1456 while (true) { |
| 1440 while (true) { | 1457 while (true) { |
| 1441 if (currentToken.type == TokenType.GT || currentToken.type == TokenType.
SLASH_GT || currentToken.type == TokenType.EOF) { | 1458 if (_currentToken.type == TokenType.GT || _currentToken.type == TokenTyp
e.SLASH_GT || _currentToken.type == TokenType.EOF) { |
| 1442 return attributes; | 1459 return attributes; |
| 1443 } else if (currentToken.type == TokenType.TAG) { | 1460 } else if (_currentToken.type == TokenType.TAG) { |
| 1444 attributes.add(parseAttribute()); | 1461 attributes.add(parseAttribute()); |
| 1445 } else { | 1462 } else { |
| 1446 reportUnexpectedToken(); | 1463 reportUnexpectedToken(); |
| 1447 currentToken = currentToken.next; | 1464 _currentToken = _currentToken.next; |
| 1448 } | 1465 } |
| 1449 break; | 1466 break; |
| 1450 } | 1467 } |
| 1451 } | 1468 } |
| 1452 } | 1469 } |
| 1453 | 1470 |
| 1454 /** | 1471 /** |
| 1455 * Parse the stream for a sequence of tag nodes existing within a parent tag n
ode. This method | 1472 * Parse the stream for a sequence of tag nodes existing within a parent tag n
ode. This method |
| 1456 * advances the current token to the next [TokenType#LT_SLASH] or [TokenType#E
OF]. | 1473 * advances the current token to the next [TokenType#LT_SLASH] or [TokenType#E
OF]. |
| 1457 * | 1474 * |
| 1458 * @return a list of nodes (not `null`, contains no `null`s) | 1475 * @return a list of nodes (not `null`, contains no `null`s) |
| 1459 */ | 1476 */ |
| 1460 List<XmlTagNode> parseChildTagNodes() { | 1477 List<XmlTagNode> parseChildTagNodes() { |
| 1461 TokenType type = currentToken.type; | 1478 TokenType type = _currentToken.type; |
| 1462 if (identical(type, TokenType.LT_SLASH) || identical(type, TokenType.EOF)) { | 1479 if (identical(type, TokenType.LT_SLASH) || identical(type, TokenType.EOF)) { |
| 1463 return XmlTagNode.NO_TAG_NODES; | 1480 return XmlTagNode.NO_TAG_NODES; |
| 1464 } | 1481 } |
| 1465 List<XmlTagNode> nodes = new List<XmlTagNode>(); | 1482 List<XmlTagNode> nodes = new List<XmlTagNode>(); |
| 1466 while (true) { | 1483 while (true) { |
| 1467 while (true) { | 1484 while (true) { |
| 1468 if (currentToken.type == TokenType.LT) { | 1485 if (_currentToken.type == TokenType.LT) { |
| 1469 nodes.add(parseTagNode()); | 1486 nodes.add(parseTagNode()); |
| 1470 } else if (currentToken.type == TokenType.LT_SLASH || currentToken.type
== TokenType.EOF) { | 1487 } else if (_currentToken.type == TokenType.LT_SLASH || _currentToken.typ
e == TokenType.EOF) { |
| 1471 return nodes; | 1488 return nodes; |
| 1472 } else if (currentToken.type == TokenType.COMMENT) { | 1489 } else if (_currentToken.type == TokenType.COMMENT) { |
| 1473 currentToken = currentToken.next; | 1490 _currentToken = _currentToken.next; |
| 1474 } else { | 1491 } else { |
| 1475 reportUnexpectedToken(); | 1492 reportUnexpectedToken(); |
| 1476 currentToken = currentToken.next; | 1493 _currentToken = _currentToken.next; |
| 1477 } | 1494 } |
| 1478 break; | 1495 break; |
| 1479 } | 1496 } |
| 1480 } | 1497 } |
| 1481 } | 1498 } |
| 1482 | 1499 |
| 1483 /** | 1500 /** |
| 1484 * Parse the token stream for the next tag node. This method advances current
token over the | 1501 * Parse the token stream for the next tag node. This method advances current
token over the |
| 1485 * parsed tag node, but should only be called if the current token is [TokenTy
pe#LT] | 1502 * parsed tag node, but should only be called if the current token is [TokenTy
pe#LT] |
| 1486 * | 1503 * |
| 1487 * @return the tag node or `null` if none found | 1504 * @return the tag node or `null` if none found |
| 1488 */ | 1505 */ |
| 1489 XmlTagNode parseTagNode() { | 1506 XmlTagNode parseTagNode() { |
| 1490 Token nodeStart = currentToken; | 1507 Token nodeStart = _currentToken; |
| 1491 currentToken = currentToken.next; | 1508 _currentToken = _currentToken.next; |
| 1492 Token tag; | 1509 Token tag; |
| 1493 if (identical(currentToken.type, TokenType.TAG)) { | 1510 if (identical(_currentToken.type, TokenType.TAG)) { |
| 1494 tag = currentToken; | 1511 tag = _currentToken; |
| 1495 currentToken = currentToken.next; | 1512 _currentToken = _currentToken.next; |
| 1496 } else { | 1513 } else { |
| 1497 reportUnexpectedToken(); | 1514 reportUnexpectedToken(); |
| 1498 tag = insertSyntheticToken(TokenType.TAG); | 1515 tag = insertSyntheticToken(TokenType.TAG); |
| 1499 } | 1516 } |
| 1500 List<XmlAttributeNode> attributes = parseAttributes(); | 1517 List<XmlAttributeNode> attributes = parseAttributes(); |
| 1501 Token attributeEnd; | 1518 Token attributeEnd; |
| 1502 if (identical(currentToken.type, TokenType.GT) || identical(currentToken.typ
e, TokenType.SLASH_GT)) { | 1519 if (identical(_currentToken.type, TokenType.GT) || identical(_currentToken.t
ype, TokenType.SLASH_GT)) { |
| 1503 attributeEnd = currentToken; | 1520 attributeEnd = _currentToken; |
| 1504 currentToken = currentToken.next; | 1521 _currentToken = _currentToken.next; |
| 1505 } else { | 1522 } else { |
| 1506 reportUnexpectedToken(); | 1523 reportUnexpectedToken(); |
| 1507 attributeEnd = insertSyntheticToken(TokenType.SLASH_GT); | 1524 attributeEnd = insertSyntheticToken(TokenType.SLASH_GT); |
| 1508 } | 1525 } |
| 1509 if (identical(attributeEnd.type, TokenType.SLASH_GT) || isSelfClosing(tag))
{ | 1526 if (identical(attributeEnd.type, TokenType.SLASH_GT) || isSelfClosing(tag))
{ |
| 1510 return createTagNode(nodeStart, tag, attributes, attributeEnd, XmlTagNode.
NO_TAG_NODES, currentToken, null, attributeEnd); | 1527 return createTagNode(nodeStart, tag, attributes, attributeEnd, XmlTagNode.
NO_TAG_NODES, _currentToken, null, attributeEnd); |
| 1511 } | 1528 } |
| 1512 List<XmlTagNode> tagNodes = parseChildTagNodes(); | 1529 List<XmlTagNode> tagNodes = parseChildTagNodes(); |
| 1513 Token contentEnd; | 1530 Token contentEnd; |
| 1514 if (identical(currentToken.type, TokenType.LT_SLASH)) { | 1531 if (identical(_currentToken.type, TokenType.LT_SLASH)) { |
| 1515 contentEnd = currentToken; | 1532 contentEnd = _currentToken; |
| 1516 currentToken = currentToken.next; | 1533 _currentToken = _currentToken.next; |
| 1517 } else { | 1534 } else { |
| 1518 reportUnexpectedToken(); | 1535 reportUnexpectedToken(); |
| 1519 contentEnd = insertSyntheticToken(TokenType.LT_SLASH); | 1536 contentEnd = insertSyntheticToken(TokenType.LT_SLASH); |
| 1520 } | 1537 } |
| 1521 Token closingTag; | 1538 Token closingTag; |
| 1522 if (identical(currentToken.type, TokenType.TAG)) { | 1539 if (identical(_currentToken.type, TokenType.TAG)) { |
| 1523 closingTag = currentToken; | 1540 closingTag = _currentToken; |
| 1524 currentToken = currentToken.next; | 1541 _currentToken = _currentToken.next; |
| 1525 } else { | 1542 } else { |
| 1526 reportUnexpectedToken(); | 1543 reportUnexpectedToken(); |
| 1527 closingTag = insertSyntheticToken(TokenType.TAG); | 1544 closingTag = insertSyntheticToken(TokenType.TAG); |
| 1528 } | 1545 } |
| 1529 Token nodeEnd; | 1546 Token nodeEnd; |
| 1530 if (identical(currentToken.type, TokenType.GT)) { | 1547 if (identical(_currentToken.type, TokenType.GT)) { |
| 1531 nodeEnd = currentToken; | 1548 nodeEnd = _currentToken; |
| 1532 currentToken = currentToken.next; | 1549 _currentToken = _currentToken.next; |
| 1533 } else { | 1550 } else { |
| 1534 reportUnexpectedToken(); | 1551 reportUnexpectedToken(); |
| 1535 nodeEnd = insertSyntheticToken(TokenType.GT); | 1552 nodeEnd = insertSyntheticToken(TokenType.GT); |
| 1536 } | 1553 } |
| 1537 return createTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, con
tentEnd, closingTag, nodeEnd); | 1554 return createTagNode(nodeStart, tag, attributes, attributeEnd, tagNodes, con
tentEnd, closingTag, nodeEnd); |
| 1538 } | 1555 } |
| 1539 | 1556 |
| 1540 /** | 1557 /** |
| 1541 * Report the current token as unexpected | 1558 * Report the current token as unexpected |
| 1542 */ | 1559 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1557 static List<XmlAttributeNode> NO_ATTRIBUTES = new UnmodifiableListView(new Lis
t<XmlAttributeNode>()); | 1574 static List<XmlAttributeNode> NO_ATTRIBUTES = new UnmodifiableListView(new Lis
t<XmlAttributeNode>()); |
| 1558 | 1575 |
| 1559 /** | 1576 /** |
| 1560 * Constant representing empty list of tag nodes. | 1577 * Constant representing empty list of tag nodes. |
| 1561 */ | 1578 */ |
| 1562 static List<XmlTagNode> NO_TAG_NODES = new UnmodifiableListView(new List<XmlTa
gNode>()); | 1579 static List<XmlTagNode> NO_TAG_NODES = new UnmodifiableListView(new List<XmlTa
gNode>()); |
| 1563 | 1580 |
| 1564 /** | 1581 /** |
| 1565 * The starting [TokenType#LT] token (not `null`). | 1582 * The starting [TokenType#LT] token (not `null`). |
| 1566 */ | 1583 */ |
| 1567 Token nodeStart; | 1584 final Token nodeStart; |
| 1568 | 1585 |
| 1569 /** | 1586 /** |
| 1570 * The [TokenType#TAG] token after the starting '<' (not `null`). | 1587 * The [TokenType#TAG] token after the starting '<' (not `null`). |
| 1571 */ | 1588 */ |
| 1572 Token tag; | 1589 final Token tag; |
| 1573 | 1590 |
| 1574 /** | 1591 /** |
| 1575 * The attributes contained by the receiver (not `null`, contains no `null`s). | 1592 * The attributes contained by the receiver (not `null`, contains no `null`s). |
| 1576 */ | 1593 */ |
| 1577 List<XmlAttributeNode> attributes; | 1594 List<XmlAttributeNode> _attributes; |
| 1578 | 1595 |
| 1579 /** | 1596 /** |
| 1580 * The [TokenType#GT] or [TokenType#SLASH_GT] token after the attributes (not | 1597 * The [TokenType#GT] or [TokenType#SLASH_GT] token after the attributes (not |
| 1581 * `null`). The token may be the same token as [nodeEnd] if there are no child | 1598 * `null`). The token may be the same token as [nodeEnd] if there are no child |
| 1582 * [tagNodes]. | 1599 * [tagNodes]. |
| 1583 */ | 1600 */ |
| 1584 Token attributeEnd; | 1601 final Token attributeEnd; |
| 1585 | 1602 |
| 1586 /** | 1603 /** |
| 1587 * The tag nodes contained in the receiver (not `null`, contains no `null`s). | 1604 * The tag nodes contained in the receiver (not `null`, contains no `null`s). |
| 1588 */ | 1605 */ |
| 1589 List<XmlTagNode> tagNodes; | 1606 List<XmlTagNode> _tagNodes; |
| 1590 | 1607 |
| 1591 /** | 1608 /** |
| 1592 * The token (not `null`) after the content, which may be | 1609 * The token (not `null`) after the content, which may be |
| 1593 * | 1610 * |
| 1594 * * (1) [TokenType#LT_SLASH] for nodes with open and close tags, or | 1611 * * (1) [TokenType#LT_SLASH] for nodes with open and close tags, or |
| 1595 * * (2) the [TokenType#LT] nodeStart of the next sibling node if this node is
self | 1612 * * (2) the [TokenType#LT] nodeStart of the next sibling node if this node is
self |
| 1596 * closing or the attributeEnd is [TokenType#SLASH_GT], or | 1613 * closing or the attributeEnd is [TokenType#SLASH_GT], or |
| 1597 * * (3) [TokenType#EOF] if the node does not have a closing tag and is the la
st node in | 1614 * * (3) [TokenType#EOF] if the node does not have a closing tag and is the la
st node in |
| 1598 * the stream [TokenType#LT_SLASH] token after the content, or `null` if there
is no | 1615 * the stream [TokenType#LT_SLASH] token after the content, or `null` if there
is no |
| 1599 * content and the attributes ended with [TokenType#SLASH_GT]. | 1616 * content and the attributes ended with [TokenType#SLASH_GT]. |
| 1600 * | 1617 * |
| 1601 */ | 1618 */ |
| 1602 Token contentEnd; | 1619 final Token contentEnd; |
| 1603 | 1620 |
| 1604 /** | 1621 /** |
| 1605 * The closing [TokenType#TAG] after the child elements or `null` if there is
no | 1622 * The closing [TokenType#TAG] after the child elements or `null` if there is
no |
| 1606 * content and the attributes ended with [TokenType#SLASH_GT] | 1623 * content and the attributes ended with [TokenType#SLASH_GT] |
| 1607 */ | 1624 */ |
| 1608 Token closingTag; | 1625 final Token closingTag; |
| 1609 | 1626 |
| 1610 /** | 1627 /** |
| 1611 * The ending [TokenType#GT] or [TokenType#SLASH_GT] token (not `null`). | 1628 * The ending [TokenType#GT] or [TokenType#SLASH_GT] token (not `null`). |
| 1612 */ | 1629 */ |
| 1613 Token nodeEnd; | 1630 final Token nodeEnd; |
| 1614 | 1631 |
| 1615 /** | 1632 /** |
| 1616 * Construct a new instance representing an XML or HTML element | 1633 * Construct a new instance representing an XML or HTML element |
| 1617 * | 1634 * |
| 1618 * @param nodeStart the starting [TokenType#LT] token (not `null`) | 1635 * @param nodeStart the starting [TokenType#LT] token (not `null`) |
| 1619 * @param tag the [TokenType#TAG] token after the starting '<' (not `null`)
. | 1636 * @param tag the [TokenType#TAG] token after the starting '<' (not `null`)
. |
| 1620 * @param attributes the attributes associated with this element or [NO_ATTRIB
UTES] (not | 1637 * @param attributes the attributes associated with this element or [NO_ATTRIB
UTES] (not |
| 1621 * `null`, contains no `null`s) | 1638 * `null`, contains no `null`s) |
| 1622 * @param attributeEnd The [TokenType#GT] or [TokenType#SLASH_GT] token after
the | 1639 * @param attributeEnd The [TokenType#GT] or [TokenType#SLASH_GT] token after
the |
| 1623 * attributes (not `null`). The token may be the same token as [nodeE
nd] if | 1640 * attributes (not `null`). The token may be the same token as [nodeE
nd] if |
| 1624 * there are no child [tagNodes]. | 1641 * there are no child [tagNodes]. |
| 1625 * @param tagNodes child tag nodes of the receiver or [NO_TAG_NODES] (not `nul
l`, | 1642 * @param tagNodes child tag nodes of the receiver or [NO_TAG_NODES] (not `nul
l`, |
| 1626 * contains no `null`s) | 1643 * contains no `null`s) |
| 1627 * @param contentEnd the token (not `null`) after the content, which may be | 1644 * @param contentEnd the token (not `null`) after the content, which may be |
| 1628 * | 1645 * |
| 1629 * * (1) [TokenType#LT_SLASH] for nodes with open and close tags, or | 1646 * * (1) [TokenType#LT_SLASH] for nodes with open and close tags, or |
| 1630 * * (2) the [TokenType#LT] nodeStart of the next sibling node if thi
s node is | 1647 * * (2) the [TokenType#LT] nodeStart of the next sibling node if thi
s node is |
| 1631 * self closing or the attributeEnd is [TokenType#SLASH_GT], or | 1648 * self closing or the attributeEnd is [TokenType#SLASH_GT], or |
| 1632 * * (3) [TokenType#EOF] if the node does not have a closing tag and
is the last | 1649 * * (3) [TokenType#EOF] if the node does not have a closing tag and
is the last |
| 1633 * node in the stream [TokenType#LT_SLASH] token after the content, o
r `null` | 1650 * node in the stream [TokenType#LT_SLASH] token after the content, o
r `null` |
| 1634 * if there is no content and the attributes ended with [TokenType#SL
ASH_GT]. | 1651 * if there is no content and the attributes ended with [TokenType#SL
ASH_GT]. |
| 1635 * | 1652 * |
| 1636 * @param closingTag the closing [TokenType#TAG] after the child elements or `
null` if | 1653 * @param closingTag the closing [TokenType#TAG] after the child elements or `
null` if |
| 1637 * there is no content and the attributes ended with [TokenType#SLASH
_GT] | 1654 * there is no content and the attributes ended with [TokenType#SLASH
_GT] |
| 1638 * @param nodeEnd the ending [TokenType#GT] or [TokenType#SLASH_GT] token (not | 1655 * @param nodeEnd the ending [TokenType#GT] or [TokenType#SLASH_GT] token (not |
| 1639 * `null`) | 1656 * `null`) |
| 1640 */ | 1657 */ |
| 1641 XmlTagNode(Token nodeStart, Token tag, List<XmlAttributeNode> attributes, Toke
n attributeEnd, List<XmlTagNode> tagNodes, Token contentEnd, Token closingTag, T
oken nodeEnd) { | 1658 XmlTagNode(this.nodeStart, this.tag, List<XmlAttributeNode> attributes, this.a
ttributeEnd, List<XmlTagNode> tagNodes, this.contentEnd, this.closingTag, this.n
odeEnd) { |
| 1642 this.nodeStart = nodeStart; | 1659 this._attributes = becomeParentOfEmpty(attributes, NO_ATTRIBUTES); |
| 1643 this.tag = tag; | 1660 this._tagNodes = becomeParentOfEmpty(tagNodes, NO_TAG_NODES); |
| 1644 this.attributes = becomeParentOfEmpty(attributes, NO_ATTRIBUTES); | |
| 1645 this.attributeEnd = attributeEnd; | |
| 1646 this.tagNodes = becomeParentOfEmpty(tagNodes, NO_TAG_NODES); | |
| 1647 this.contentEnd = contentEnd; | |
| 1648 this.closingTag = closingTag; | |
| 1649 this.nodeEnd = nodeEnd; | |
| 1650 } | 1661 } |
| 1651 | 1662 |
| 1652 accept(XmlVisitor visitor) => visitor.visitXmlTagNode(this); | 1663 accept(XmlVisitor visitor) => visitor.visitXmlTagNode(this); |
| 1653 | 1664 |
| 1654 /** | 1665 /** |
| 1655 * Answer the attribute with the specified name. | 1666 * Answer the attribute with the specified name. |
| 1656 * | 1667 * |
| 1657 * @param name the attribute name | 1668 * @param name the attribute name |
| 1658 * @return the attribute or `null` if no matching attribute is found | 1669 * @return the attribute or `null` if no matching attribute is found |
| 1659 */ | 1670 */ |
| 1660 XmlAttributeNode getAttribute(String name) { | 1671 XmlAttributeNode getAttribute(String name) { |
| 1661 for (XmlAttributeNode attribute in attributes) { | 1672 for (XmlAttributeNode attribute in _attributes) { |
| 1662 if (attribute.name.lexeme == name) { | 1673 if (attribute.name.lexeme == name) { |
| 1663 return attribute; | 1674 return attribute; |
| 1664 } | 1675 } |
| 1665 } | 1676 } |
| 1666 return null; | 1677 return null; |
| 1667 } | 1678 } |
| 1668 | 1679 |
| 1669 /** | 1680 /** |
| 1681 * Answer the receiver's attributes. Callers should not manipulate the returne
d list to edit the |
| 1682 * AST structure. |
| 1683 * |
| 1684 * @return the attributes (not `null`, contains no `null`s) |
| 1685 */ |
| 1686 List<XmlAttributeNode> get attributes => _attributes; |
| 1687 |
| 1688 /** |
| 1670 * Find the attribute with the given name (see [getAttribute] and answer the l
exeme | 1689 * Find the attribute with the given name (see [getAttribute] and answer the l
exeme |
| 1671 * for the attribute's value token without the leading and trailing quotes (se
e | 1690 * for the attribute's value token without the leading and trailing quotes (se
e |
| 1672 * [XmlAttributeNode#getText]). | 1691 * [XmlAttributeNode#getText]). |
| 1673 * | 1692 * |
| 1674 * @param name the attribute name | 1693 * @param name the attribute name |
| 1675 * @return the attribute text or `null` if no matching attribute is found | 1694 * @return the attribute text or `null` if no matching attribute is found |
| 1676 */ | 1695 */ |
| 1677 String getAttributeText(String name) { | 1696 String getAttributeText(String name) { |
| 1678 XmlAttributeNode attribute = getAttribute(name); | 1697 XmlAttributeNode attribute = getAttribute(name); |
| 1679 return attribute != null ? attribute.text : null; | 1698 return attribute != null ? attribute.text : null; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1709 Token get endToken { | 1728 Token get endToken { |
| 1710 if (nodeEnd != null) { | 1729 if (nodeEnd != null) { |
| 1711 return nodeEnd; | 1730 return nodeEnd; |
| 1712 } | 1731 } |
| 1713 if (closingTag != null) { | 1732 if (closingTag != null) { |
| 1714 return closingTag; | 1733 return closingTag; |
| 1715 } | 1734 } |
| 1716 if (contentEnd != null) { | 1735 if (contentEnd != null) { |
| 1717 return contentEnd; | 1736 return contentEnd; |
| 1718 } | 1737 } |
| 1719 if (!tagNodes.isEmpty) { | 1738 if (!_tagNodes.isEmpty) { |
| 1720 return tagNodes[tagNodes.length - 1].endToken; | 1739 return _tagNodes[_tagNodes.length - 1].endToken; |
| 1721 } | 1740 } |
| 1722 if (attributeEnd != null) { | 1741 if (attributeEnd != null) { |
| 1723 return attributeEnd; | 1742 return attributeEnd; |
| 1724 } | 1743 } |
| 1725 if (!attributes.isEmpty) { | 1744 if (!_attributes.isEmpty) { |
| 1726 return attributes[attributes.length - 1].endToken; | 1745 return _attributes[_attributes.length - 1].endToken; |
| 1727 } | 1746 } |
| 1728 return tag; | 1747 return tag; |
| 1729 } | 1748 } |
| 1730 | 1749 |
| 1731 /** | 1750 /** |
| 1732 * Return the expressions that are embedded in the tag's content. | 1751 * Return the expressions that are embedded in the tag's content. |
| 1733 * | 1752 * |
| 1734 * @return the expressions that are embedded in the tag's content | 1753 * @return the expressions that are embedded in the tag's content |
| 1735 */ | 1754 */ |
| 1736 List<EmbeddedExpression> get expressions => EmbeddedExpression.EMPTY_ARRAY; | 1755 List<EmbeddedExpression> get expressions => EmbeddedExpression.EMPTY_ARRAY; |
| 1737 | 1756 |
| 1757 /** |
| 1758 * Answer the tag nodes contained in the receiver. Callers should not manipula
te the returned list |
| 1759 * to edit the AST structure. |
| 1760 * |
| 1761 * @return the children (not `null`, contains no `null`s) |
| 1762 */ |
| 1763 List<XmlTagNode> get tagNodes => _tagNodes; |
| 1764 |
| 1738 void visitChildren(XmlVisitor visitor) { | 1765 void visitChildren(XmlVisitor visitor) { |
| 1739 for (XmlAttributeNode node in attributes) { | 1766 for (XmlAttributeNode node in _attributes) { |
| 1740 node.accept(visitor); | 1767 node.accept(visitor); |
| 1741 } | 1768 } |
| 1742 for (XmlTagNode node in tagNodes) { | 1769 for (XmlTagNode node in _tagNodes) { |
| 1743 node.accept(visitor); | 1770 node.accept(visitor); |
| 1744 } | 1771 } |
| 1745 } | 1772 } |
| 1746 | 1773 |
| 1747 /** | 1774 /** |
| 1748 * Same as [becomeParentOf], but returns given "ifEmpty" if "children" is empt
y | 1775 * Same as [becomeParentOf], but returns given "ifEmpty" if "children" is empt
y |
| 1749 */ | 1776 */ |
| 1750 List becomeParentOfEmpty(List children, List ifEmpty) { | 1777 List becomeParentOfEmpty(List children, List ifEmpty) { |
| 1751 if (children != null && children.isEmpty) { | 1778 if (children != null && children.isEmpty) { |
| 1752 return ifEmpty; | 1779 return ifEmpty; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1955 | 1982 |
| 1956 /** | 1983 /** |
| 1957 * Instances of the class `HtmlUnit` represent the contents of an HTML file. | 1984 * Instances of the class `HtmlUnit` represent the contents of an HTML file. |
| 1958 * | 1985 * |
| 1959 * @coverage dart.engine.html | 1986 * @coverage dart.engine.html |
| 1960 */ | 1987 */ |
| 1961 class HtmlUnit extends XmlNode { | 1988 class HtmlUnit extends XmlNode { |
| 1962 /** | 1989 /** |
| 1963 * The first token in the token stream that was parsed to form this HTML unit. | 1990 * The first token in the token stream that was parsed to form this HTML unit. |
| 1964 */ | 1991 */ |
| 1965 Token _beginToken; | 1992 final Token beginToken; |
| 1966 | 1993 |
| 1967 /** | 1994 /** |
| 1968 * The last token in the token stream that was parsed to form this compilation
unit. This token | 1995 * The last token in the token stream that was parsed to form this compilation
unit. This token |
| 1969 * should always have a type of [TokenType.EOF]. | 1996 * should always have a type of [TokenType.EOF]. |
| 1970 */ | 1997 */ |
| 1971 Token _endToken; | 1998 final Token endToken; |
| 1972 | 1999 |
| 1973 /** | 2000 /** |
| 1974 * The tag nodes contained in the receiver (not `null`, contains no `null`s). | 2001 * The tag nodes contained in the receiver (not `null`, contains no `null`s). |
| 1975 */ | 2002 */ |
| 1976 List<XmlTagNode> tagNodes; | 2003 List<XmlTagNode> _tagNodes; |
| 1977 | 2004 |
| 1978 /** | 2005 /** |
| 1979 * The element associated with this HTML unit or `null` if the receiver is not
resolved. | 2006 * The element associated with this HTML unit or `null` if the receiver is not
resolved. |
| 1980 */ | 2007 */ |
| 1981 HtmlElementImpl element; | 2008 HtmlElementImpl element; |
| 1982 | 2009 |
| 1983 /** | 2010 /** |
| 1984 * Construct a new instance representing the content of an HTML file. | 2011 * Construct a new instance representing the content of an HTML file. |
| 1985 * | 2012 * |
| 1986 * @param beginToken the first token in the file (not `null`) | 2013 * @param beginToken the first token in the file (not `null`) |
| 1987 * @param tagNodes child tag nodes of the receiver (not `null`, contains no `n
ull`s) | 2014 * @param tagNodes child tag nodes of the receiver (not `null`, contains no `n
ull`s) |
| 1988 * @param endToken the last token in the token stream which should be of type | 2015 * @param endToken the last token in the token stream which should be of type |
| 1989 * [TokenType.EOF] | 2016 * [TokenType.EOF] |
| 1990 */ | 2017 */ |
| 1991 HtmlUnit(Token beginToken, List<XmlTagNode> tagNodes, Token endToken) { | 2018 HtmlUnit(this.beginToken, List<XmlTagNode> tagNodes, this.endToken) { |
| 1992 this._beginToken = beginToken; | 2019 this._tagNodes = becomeParentOf(tagNodes); |
| 1993 this.tagNodes = becomeParentOf(tagNodes); | |
| 1994 this._endToken = endToken; | |
| 1995 } | 2020 } |
| 1996 | 2021 |
| 1997 accept(XmlVisitor visitor) => visitor.visitHtmlUnit(this); | 2022 accept(XmlVisitor visitor) => visitor.visitHtmlUnit(this); |
| 1998 | 2023 |
| 1999 Token get beginToken => _beginToken; | 2024 /** |
| 2000 | 2025 * Answer the tag nodes contained in the receiver. Callers should not manipula
te the returned list |
| 2001 Token get endToken => _endToken; | 2026 * to edit the AST structure. |
| 2027 * |
| 2028 * @return the children (not `null`, contains no `null`s) |
| 2029 */ |
| 2030 List<XmlTagNode> get tagNodes => _tagNodes; |
| 2002 | 2031 |
| 2003 void visitChildren(XmlVisitor visitor) { | 2032 void visitChildren(XmlVisitor visitor) { |
| 2004 for (XmlTagNode node in tagNodes) { | 2033 for (XmlTagNode node in _tagNodes) { |
| 2005 node.accept(visitor); | 2034 node.accept(visitor); |
| 2006 } | 2035 } |
| 2007 } | 2036 } |
| 2008 } | 2037 } |
| OLD | NEW |