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

An attribute of a tag token

Fields
const(char)[] name
const(char)[] value
structToken

A token. Slices are valid only while the sink processes it.

Fields
uint tagTag id (interned in the document) and lowercase name, for tags; the name of a doctype
const(char)[] name
bool selfClosing
const(TokenAttribute)[] attributes
const(char)[] dataText, comment or processing instruction data
bool hasNullThe text contains U+0000
const(char)[] targetProcessing instruction target
bool forceQuirksDoctype: the force-quirks flag
bool hasName
bool hasPublicId
bool hasSystemId
const(char)[] publicId
const(char)[] systemId
structTokenSink

The receiver of the tokens (the tree builder)

Fields
void * context
bool 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 found
bool 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 emitted
Constructors
this(DomDocument * document, TokenSink sink)Tokens go to `sink`; the tag names are interned in `document`
Nested Templates
AttrSpan