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