@@ -20,15 +20,18 @@ pub use self::Token::{CharacterTokens, CommentToken, DoctypeToken, TagToken};
2020pub use self :: Token :: { EOFToken , NullCharacterToken , ParseError } ;
2121
2222/// A `DOCTYPE` token.
23- // FIXME: already exists in Servo DOM
2423#[ derive( PartialEq , Eq , Clone , Debug , Default ) ]
2524pub struct Doctype {
2625 pub name : Option < StrTendril > ,
2726 pub public_id : Option < StrTendril > ,
2827 pub system_id : Option < StrTendril > ,
28+ /// Indicates if this DOCTYPE token should put the document in [quirks mode].
29+ ///
30+ /// [quirks mode]: https://dom.spec.whatwg.org/#concept-document-quirks
2931 pub force_quirks : bool ,
3032}
3133
34+ /// Whether the tag is a start or an end tag.
3235#[ derive( PartialEq , Eq , Hash , Copy , Clone , Debug ) ]
3336pub enum TagKind {
3437 StartTag ,
@@ -38,8 +41,12 @@ pub enum TagKind {
3841/// A tag token.
3942#[ derive( PartialEq , Eq , Clone , Debug ) ]
4043pub struct Tag {
44+ /// Whether the tag is a start or an end tag.
4145 pub kind : TagKind ,
4246 pub name : LocalName ,
47+ /// Whether the tag closes itself.
48+ ///
49+ /// An example of a self closing tag is `<foo />`.
4350 pub self_closing : bool ,
4451 pub attrs : Vec < Attribute > ,
4552}
@@ -70,21 +77,32 @@ impl Tag {
7077
7178#[ derive( PartialEq , Eq , Debug ) ]
7279pub enum Token {
80+ /// A DOCTYPE declaration like `<!DOCTYPE html>`
7381 DoctypeToken ( Doctype ) ,
82+ /// A opening or closing tag, like `<foo>` or `</bar>`
7483 TagToken ( Tag ) ,
84+ /// A comment like `<!-- foo -->`.
7585 CommentToken ( StrTendril ) ,
86+ /// A sequence of characters.
7687 CharacterTokens ( StrTendril ) ,
88+ /// A `U+0000 NULL` character in the input.
7789 NullCharacterToken ,
7890 EOFToken ,
7991 ParseError ( Cow < ' static , str > ) ,
8092}
8193
94+ /// The result of a [TokenSink] consuming a single token.
8295#[ derive( Debug , PartialEq ) ]
8396#[ must_use]
8497pub enum TokenSinkResult < Handle > {
98+ /// The tokenizer can continue parsing the input as usual.
8599 Continue ,
100+ /// The token sink has completed parsing a `<script>` tag, blocking the tokenizer
101+ /// until the script is executed.
86102 Script ( Handle ) ,
103+ /// The tokenizer should set its state to the [PLAINTEXT state](https://html.spec.whatwg.org/#plaintext-state).
87104 Plaintext ,
105+ /// The tokenizer should set its state to the given rawdata state.
88106 RawData ( states:: RawKind ) ,
89107 /// The document indicated that the given encoding should be used to parse it.
90108 ///
@@ -99,18 +117,20 @@ pub enum TokenSinkResult<Handle> {
99117
100118/// Types which can receive tokens from the tokenizer.
101119pub trait TokenSink {
120+ /// The type of a DOM node.
102121 type Handle ;
103122
104123 /// Process a token.
105124 fn process_token ( & self , token : Token , line_number : u64 ) -> TokenSinkResult < Self :: Handle > ;
106125
107- // Signal sink that tokenization reached the end.
126+ /// Signal that tokenization reached the end of the document .
108127 fn end ( & self ) { }
109128
110- /// Used in the markup declaration open state. By default, this always
129+ /// Used in the [ markup declaration open state] . By default, this always
111130 /// returns false and thus all CDATA sections are tokenized as bogus
112131 /// comments.
113- /// <https://html.spec.whatwg.org/multipage/#markup-declaration-open-state>
132+ ///
133+ /// [markup declaration open state]: https://html.spec.whatwg.org/multipage/#markup-declaration-open-state
114134 fn adjusted_current_node_present_but_not_in_html_namespace ( & self ) -> bool {
115135 false
116136 }
0 commit comments