pub fn parse(input: &str) -> ParseResultExpand description
The driver loop (§13.2 “Parsing HTML documents”, the “tokenization and
tree construction” step): parses input into a Document tree with
per-node source positions, feeding it through the tokenizer and handing
each token to the tree builder, applying the two pieces of feedback
tree construction sends back to the tokenizer — a state switch
(Tokenizer::switch_to, for RCDATA/RAWTEXT/script-data/PLAINTEXT
elements) and the foreign-content flag (Tokenizer::set_in_foreign_content,
consulted only by CDATA-section handling).
The tokenizer’s iterator yields exactly one Eof token and then ends
(None) on the next call, so the loop needs no separate condition for
when to stop feeding it tokens. TreeBuilder::stop_parsing (§13.2.7
“The end”) still runs once, explicitly, right after — its one
tree-shape-relevant step (“pop all the nodes off the stack of open
elements”) isn’t implied by the loop simply ending.
Returns ParseResult, not a bare Document, as of Phase 07
(plan/07-parse-errors.md) — errors covers every tokenizer-level
parse error (src/tokenizer.rs’s error() call sites) plus, as of
Phase 08 (plan/08-tree-construction-errors.md), the
tree-construction-level (§13.2.6) conditions listed there. Both
sources are merged and sorted by source position, so errors is
always in document order regardless of which stage produced each
entry (the two stages interleave: the tokenizer runs ahead of the
tree builder token by token).