parserino.html.tokenizer
HTML tokenizer (HTML Living Standard, "Tokenization").
The input comes in chunks of any size: a token can span many chunks. Tokens are given to a sink (the tree builder) as soon as they are complete; their data is valid only during the call.
Types 6
enumTokenType : ubyte
Token types (a text token is a run of characters)
StartTag
EndTag
Text
Comment
Doctype
ProcessingInstruction
Eof
structTokenAttribute
An attribute of a tag token
Fields
const(char)[] nameconst(char)[] valuestructToken
A token. Slices are valid only while the sink processes it.
Fields
TokenType typeuint tagTag id (interned in the document) and lowercase name, for tags; the name of a doctypeconst(char)[] namebool selfClosingconst(TokenAttribute)[] attributesconst(char)[] dataText, comment or processing instruction databool hasNullThe text contains U+0000const(char)[] targetProcessing instruction targetbool forceQuirksDoctype: the force-quirks flagbool hasNamebool hasPublicIdbool hasSystemIdconst(char)[] publicIdconst(char)[] systemIdstructTokenSink
The receiver of the tokens (the tree builder)
Fields
void * contextbool function(void * context, ref Token token) @nogc nothrow pure @safe processProcess a token. It returns false to stop (out of memory).bool function(void * context) @nogc nothrow pure @safe inForeignContentIs the adjusted current node an element not in the html namespace? (for CDATA sections)enumState : ubyte
States of the tokenizer, named after the states of the standard (BeforeAttrName is the "before attribute name state"). The ones the tree builder can set are Data, Rcdata, Rawtext, ScriptData, Plaintext.
Data
Rcdata
Rawtext
ScriptData
Plaintext
TagOpen
EndTagOpen
TagName
RcdataLessThan
RcdataEndTagOpen
RcdataEndTagName
RawtextLessThan
RawtextEndTagOpen
RawtextEndTagName
ScriptDataLessThan
ScriptDataEndTagOpen
ScriptDataEndTagName
ScriptDataEscapeStart
ScriptDataEscapeStartDash
ScriptDataEscaped
ScriptDataEscapedDash
ScriptDataEscapedDashDash
ScriptDataEscapedLessThan
ScriptDataEscapedEndTagOpen
ScriptDataEscapedEndTagName
ScriptDataDoubleEscapeStart
ScriptDataDoubleEscaped
ScriptDataDoubleEscapedDash
ScriptDataDoubleEscapedDashDash
ScriptDataDoubleEscapedLessThan
ScriptDataDoubleEscapeEnd
BeforeAttrName
AttrName
AfterAttrName
BeforeAttrValue
AttrValueDoubleQuoted
AttrValueSingleQuoted
AttrValueUnquoted
AfterAttrValueQuoted
SelfClosingStartTag
BogusComment
MarkupDeclarationOpen
CommentStart
CommentStartDash
Comment
CommentLessThan
CommentLessThanBang
CommentLessThanBangDash
CommentLessThanBangDashDash
CommentEndDash
CommentEnd
CommentEndBang
Doctype
BeforeDoctypeName
DoctypeName
AfterDoctypeName
AfterDoctypePublicKeyword
BeforeDoctypePublicId
DoctypePublicIdDoubleQuoted
DoctypePublicIdSingleQuoted
AfterDoctypePublicId
BetweenDoctypePublicAndSystem
AfterDoctypeSystemKeyword
BeforeDoctypeSystemId
DoctypeSystemIdDoubleQuoted
DoctypeSystemIdSingleQuoted
AfterDoctypeSystemId
BogusDoctype
CDataSection
CDataSectionBracket
CDataSectionEnd
CharRef
NamedCharRef
NumericCharRef
HexCharRefStart
DecimalCharRefStart
HexCharRef
DecimalCharRef
ProcessingInstructionOpen
ProcessingInstructionTarget
AfterProcessingInstructionTarget
ProcessingInstructionData
ProcessingInstructionQuestionable
AmbiguousAmpersand
structTokenizer
The tokenizer: feed it the input, then finish
Fields
Utf8Decoder decoderThe UTF-8 decoding of the input (set `decoder.stripBom` for documents)bool collectErrorsCollect the parse errors in `errors` (off by default: then they cost nothing)Buffer!RawParseError errorsThe parse errors found so far (with `collectErrors`), in the order they were foundbool failedOut of memory (or stopped by the sink)Methods
void switchTo(State s) @nogc nothrow pure @safeSet by the tree builder, while it processes a start tag (or before the input for fragments). For RCDATA, RAWTEXT and script data, the current start tag is the one that closes them.void setLastStartTag(scope const(char)[] name) @nogc nothrow pure @safeSet the last start tag, which closes RCDATA, RAWTEXT and script data (for tests of the tokenizer alone)void error(ParseErrorCode code) @nogc nothrow pure @safeA parse error at the current position (the tree builder reports its errors here too)bool feed(scope const(char)[] chunk) @nogc nothrow pure @safeTokenize a chunk. It returns false on errors (out of memory).bool finish() @nogc nothrow pure @safeEnd of input: the pending data is completed and an EOF token is emittedConstructors
this(DomDocument * document, TokenSink sink)Tokens go to `sink`; the tag names are interned in `document`Nested Templates
AttrSpan