Skip to main content

parse

Function parse 

Source
pub fn parse(input: &str) -> ParseResult
Expand 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 currently covers every tokenizer-level parse error (src/tokenizer.rs’s error() call sites); tree-construction-level errors (e.g. stray end tags) are follow-up work, not yet collected here.