Report tree-construction parse errors for dropped tokens and misnesting (0.4.0) - #4
Merged
Merged
Conversation
Records the WHATWG §13.2.6 parse errors at every site where the tree builder ignored a token or ran the adoption agency algorithm's error steps without reporting anything. Tree construction is unchanged: html5lib-tests conformance stays at 1,726/1,726. New ParseErrorKind variants (the enum is #[non_exhaustive]): - StrayStartTag: html/body/frameset in body, a second head, table structure tags outside a table, a nested select. - NestedFormattingElement: <a> while an a is still active, <nobr> while one is in scope. - MisnestedFormattingElement: adoption agency step 4.6. - FormattingElementNotInScope: adoption agency step 4.5. Existing kinds now reported at more sites: - StrayEndTag: the "in body" end-tag rules with no matching element in scope (</div>, </li>, </dd>, </h1>-</h6>, </form>, </object>, </body>, </html>, ...), "any other end tag" in the head-phase modes and "in template", and adoption agency step 4.4. - StrayEndTagInTable / MisplacedTokenInTable: tokens ignored by the caption, column group, table body, row and cell modes; <form> in a table. - StrayDoctype: a DOCTYPE in foreign content. close_table_body/close_row now return bool like close_caption, so the callers can report the ignored-token error; no behaviour change. html5lib-tests error counts: exact matches 482 -> 568 of 1,726 cases, reported errors 1,641 -> 2,144 (expected 3,806), cases reporting more errors than expected unchanged at 53. Bump to 0.4.0: ParseResult::errors changes for the same input, the same kind of change that took 0.2.0 to 0.3.0. Add CHANGELOG.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The tree builder ignored many tokens, and ran the adoption agency algorithm's error steps, without recording the parse error the WHATWG spec requires (§13.2.6). This PR records those errors. Tree construction does not change.
html-conform needs this. It pins
=0.3.0and currently can't report a stray</div>or misnested<b><i>…</b></i>, which vnu flags.New
ParseErrorKindvariants (the enum is#[non_exhaustive])StrayStartTaghtml/body/framesetstart tags ("Parse error."),caption/col/colgroup/frame/head/tbody/td/tfoot/th/thead/tr("Parse error. Ignore the token."), nestedselect; §13.2.6.4.4–.6: a secondhead/noscriptNestedFormattingElementastart tag while anais still in the active formatting list;nobrwhile anobris in scopeMisnestedFormattingElementFormattingElementNotInScopeExisting kinds, now reported at more sites
StrayEndTag:address…ulgroup incl.div/header/select, plusli,dd/dt,h1–h6,form(all three branches),applet/marquee/object,body,html;</template>in head with no template open;StrayEndTagInTable/MisplacedTokenInTable: tokens ignored in "in table" (</table>out of scope,<form>), "in caption", "in column group", "in table body", "in row" and "in cell".StrayDoctype: a DOCTYPE in foreign content (§13.2.6.5).Not covered here
These are spec parse errors where the token is not dropped, e.g. "current node is not an X element" on a matching end tag, or "after after body" reprocessing. Also not covered: frameset modes, and U+0000 in body, which the tokenizer already reports at the same position.
Numbers
#errorscounts, measured with a throwaway harness (not committed):cargo test: 267 lib tests (9 new), plus conformance.cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.cargo publish --dry-runpasses.Version: 0.4.0
The API change is additive only (
ParseErrorKindis#[non_exhaustive]). Behaviour does change:ParseResult::errorsreturns more entries for the same input. That is the same kind of change that took 0.2.0 to 0.3.0, so this is a minor (0.x-breaking) bump rather than 0.3.1. The PR also adds CHANGELOG.md.Not published or tagged.