| OLD | NEW |
| (Empty) |
| 1 /** This library contains token types used by the html5 tokenizer. */ | |
| 2 #library('token'); | |
| 3 | |
| 4 /** An html5 token. */ | |
| 5 class Token { | |
| 6 abstract int get kind; | |
| 7 | |
| 8 // TODO(jmesserly): it'd be nice to remove this and always use the ".data" | |
| 9 // on the particular token type. | |
| 10 abstract get data; | |
| 11 abstract set data(value); | |
| 12 } | |
| 13 | |
| 14 class TagToken extends Token { | |
| 15 String name; | |
| 16 | |
| 17 // TODO(jmesserly): this starts as a List, but becomes a Map of attributes. | |
| 18 // Should probably separate these into different named fields. | |
| 19 var data; | |
| 20 | |
| 21 bool selfClosing; | |
| 22 | |
| 23 TagToken(this.name, data, this.selfClosing) | |
| 24 : data = data == null ? [] : data; | |
| 25 } | |
| 26 | |
| 27 class StartTagToken extends TagToken { | |
| 28 bool selfClosingAcknowledged; | |
| 29 | |
| 30 /** The namespace. This is filled in later during tree building. */ | |
| 31 String namespace; | |
| 32 | |
| 33 StartTagToken([String name, data, bool selfClosing = false, | |
| 34 this.selfClosingAcknowledged = false, this.namespace]) | |
| 35 : super(name, data, selfClosing); | |
| 36 | |
| 37 int get kind => TokenKind.startTag; | |
| 38 } | |
| 39 | |
| 40 class EndTagToken extends TagToken { | |
| 41 | |
| 42 EndTagToken([String name, data, bool selfClosing = false]) | |
| 43 : super(name, data, selfClosing); | |
| 44 | |
| 45 int get kind => TokenKind.endTag; | |
| 46 } | |
| 47 | |
| 48 class StringToken extends Token { | |
| 49 String data; | |
| 50 StringToken(this.data); | |
| 51 } | |
| 52 | |
| 53 class ParseErrorToken extends StringToken { | |
| 54 /** Extra information that goes along with the error message. */ | |
| 55 Map messageParams; | |
| 56 | |
| 57 ParseErrorToken([String data, this.messageParams]) : super(data); | |
| 58 | |
| 59 int get kind => TokenKind.parseError; | |
| 60 } | |
| 61 | |
| 62 class CharactersToken extends StringToken { | |
| 63 CharactersToken([String data]) : super(data); | |
| 64 | |
| 65 int get kind => TokenKind.characters; | |
| 66 } | |
| 67 | |
| 68 class SpaceCharactersToken extends StringToken { | |
| 69 SpaceCharactersToken([String data]) : super(data); | |
| 70 | |
| 71 int get kind => TokenKind.spaceCharacters; | |
| 72 } | |
| 73 | |
| 74 class CommentToken extends StringToken { | |
| 75 CommentToken([String data]) : super(data); | |
| 76 | |
| 77 int get kind => TokenKind.comment; | |
| 78 } | |
| 79 | |
| 80 class DoctypeToken extends Token { | |
| 81 String publicId; | |
| 82 String systemId; | |
| 83 String name; | |
| 84 bool correct; | |
| 85 | |
| 86 DoctypeToken([this.publicId, this.systemId, this.correct = false]) | |
| 87 : name = ""; | |
| 88 | |
| 89 int get kind => TokenKind.doctype; | |
| 90 | |
| 91 // TODO(jmesserly): remove. These are only here because of Token.data | |
| 92 String get data { throw const UnsupportedOperationException("data"); } | |
| 93 set data(value) { throw const UnsupportedOperationException("data"); } | |
| 94 } | |
| 95 | |
| 96 | |
| 97 class TokenKind { | |
| 98 static const int spaceCharacters = 0; | |
| 99 static const int characters = 1; | |
| 100 static const int startTag = 2; | |
| 101 static const int endTag = 3; | |
| 102 static const int comment = 4; | |
| 103 static const int doctype = 5; | |
| 104 static const int parseError = 6; | |
| 105 } | |
| OLD | NEW |