| OLD | NEW |
| 1 /** This library contains token types used by the html5 tokenizer. */ | 1 /// This library contains token types used by the html5 tokenizer. |
| 2 library token; | 2 library token; |
| 3 | 3 |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'package:source_maps/span.dart' show FileSpan; | 5 import 'package:source_maps/span.dart' show FileSpan; |
| 6 | 6 |
| 7 /** An html5 token. */ | 7 /// An html5 token. |
| 8 abstract class Token { | 8 abstract class Token { |
| 9 FileSpan span; | 9 FileSpan span; |
| 10 | 10 |
| 11 int get kind; | 11 int get kind; |
| 12 } | 12 } |
| 13 | 13 |
| 14 abstract class TagToken extends Token { | 14 abstract class TagToken extends Token { |
| 15 String name; | 15 String name; |
| 16 | 16 |
| 17 bool selfClosing; | 17 bool selfClosing; |
| 18 | 18 |
| 19 TagToken(this.name, this.selfClosing); | 19 TagToken(this.name, this.selfClosing); |
| 20 } | 20 } |
| 21 | 21 |
| 22 class StartTagToken extends TagToken { | 22 class StartTagToken extends TagToken { |
| 23 /** | 23 /// The tag's attributes. A map from the name to the value, where the name |
| 24 * The tag's attributes. A map from the name to the value, where the name | 24 /// can be a [String] or [AttributeName]. |
| 25 * can be a [String] or [AttributeName]. | |
| 26 */ | |
| 27 LinkedHashMap<dynamic, String> data; | 25 LinkedHashMap<dynamic, String> data; |
| 28 | 26 |
| 29 /** The attribute spans if requested. Otherwise null. */ | 27 /// The attribute spans if requested. Otherwise null. |
| 30 List<TagAttribute> attributeSpans; | 28 List<TagAttribute> attributeSpans; |
| 31 | 29 |
| 32 bool selfClosingAcknowledged; | 30 bool selfClosingAcknowledged; |
| 33 | 31 |
| 34 /** The namespace. This is filled in later during tree building. */ | 32 /// The namespace. This is filled in later during tree building. |
| 35 String namespace; | 33 String namespace; |
| 36 | 34 |
| 37 StartTagToken(String name, {this.data, bool selfClosing: false, | 35 StartTagToken(String name, {this.data, bool selfClosing: false, |
| 38 this.selfClosingAcknowledged: false, this.namespace}) | 36 this.selfClosingAcknowledged: false, this.namespace}) |
| 39 : super(name, selfClosing); | 37 : super(name, selfClosing); |
| 40 | 38 |
| 41 int get kind => TokenKind.startTag; | 39 int get kind => TokenKind.startTag; |
| 42 } | 40 } |
| 43 | 41 |
| 44 class EndTagToken extends TagToken { | 42 class EndTagToken extends TagToken { |
| 45 EndTagToken(String name, {bool selfClosing: false}) | 43 EndTagToken(String name, {bool selfClosing: false}) |
| 46 : super(name, selfClosing); | 44 : super(name, selfClosing); |
| 47 | 45 |
| 48 int get kind => TokenKind.endTag; | 46 int get kind => TokenKind.endTag; |
| 49 } | 47 } |
| 50 | 48 |
| 51 abstract class StringToken extends Token { | 49 abstract class StringToken extends Token { |
| 52 String data; | 50 String data; |
| 53 StringToken(this.data); | 51 StringToken(this.data); |
| 54 } | 52 } |
| 55 | 53 |
| 56 class ParseErrorToken extends StringToken { | 54 class ParseErrorToken extends StringToken { |
| 57 /** Extra information that goes along with the error message. */ | 55 /// Extra information that goes along with the error message. |
| 58 Map messageParams; | 56 Map messageParams; |
| 59 | 57 |
| 60 ParseErrorToken(String data, {this.messageParams}) : super(data); | 58 ParseErrorToken(String data, {this.messageParams}) : super(data); |
| 61 | 59 |
| 62 int get kind => TokenKind.parseError; | 60 int get kind => TokenKind.parseError; |
| 63 } | 61 } |
| 64 | 62 |
| 65 class CharactersToken extends StringToken { | 63 class CharactersToken extends StringToken { |
| 66 CharactersToken([String data]) : super(data); | 64 CharactersToken([String data]) : super(data); |
| 67 | 65 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 84 String publicId; | 82 String publicId; |
| 85 String systemId; | 83 String systemId; |
| 86 String name = ""; | 84 String name = ""; |
| 87 bool correct; | 85 bool correct; |
| 88 | 86 |
| 89 DoctypeToken({this.publicId, this.systemId, this.correct: false}); | 87 DoctypeToken({this.publicId, this.systemId, this.correct: false}); |
| 90 | 88 |
| 91 int get kind => TokenKind.doctype; | 89 int get kind => TokenKind.doctype; |
| 92 } | 90 } |
| 93 | 91 |
| 94 /** | 92 /// These are used by the tokenizer to build up the attribute map. |
| 95 * These are used by the tokenizer to build up the attribute map. | 93 /// They're also used by [StartTagToken.attributeSpans] if attribute spans are |
| 96 * They're also used by [StartTagToken.attributeSpans] if attribute spans are | 94 /// requested. |
| 97 * requested. | |
| 98 */ | |
| 99 class TagAttribute { | 95 class TagAttribute { |
| 100 String name; | 96 String name; |
| 101 String value; | 97 String value; |
| 102 | 98 |
| 103 // The spans of the attribute. This is not used unless we are computing an | 99 // The spans of the attribute. This is not used unless we are computing an |
| 104 // attribute span on demand. | 100 // attribute span on demand. |
| 105 int start; | 101 int start; |
| 106 int end; | 102 int end; |
| 107 int startValue; | 103 int startValue; |
| 108 int endValue; | 104 int endValue; |
| 109 | 105 |
| 110 TagAttribute(this.name, [this.value = '']); | 106 TagAttribute(this.name, [this.value = '']); |
| 111 } | 107 } |
| 112 | 108 |
| 113 | 109 |
| 114 class TokenKind { | 110 class TokenKind { |
| 115 static const int spaceCharacters = 0; | 111 static const int spaceCharacters = 0; |
| 116 static const int characters = 1; | 112 static const int characters = 1; |
| 117 static const int startTag = 2; | 113 static const int startTag = 2; |
| 118 static const int endTag = 3; | 114 static const int endTag = 3; |
| 119 static const int comment = 4; | 115 static const int comment = 4; |
| 120 static const int doctype = 5; | 116 static const int doctype = 5; |
| 121 static const int parseError = 6; | 117 static const int parseError = 6; |
| 122 } | 118 } |
| OLD | NEW |