Repository navigation
fix: Let tree-building parses report the locations streaming ones do - #131
Conversation
Problem: In the Nu HTML Checker, with --no-stream, each HTML parser message got a range that started at the start of the document — or at the end of the previous message — so its extract and highlight took in all the markup from there to the error. And a checker message reported at an end tag got no location at all. Cause: When its streamability violation policy is ALLOW, HtmlParser uses its SAXTreeBuilder, which builds the whole tree before TreeParser replays it as SAX events. So a SAX consumer that tracks locations had none for any error the parser reported, which the checker needs to find where the range of each error starts. Also, SAXTreeBuilder never set an element’s end locator, so the replay gave endElement events no location. Fix: As SAXTreeBuilder builds the tree, it now sends the events a streaming parse emits, at the same points, to any handlers set with the new HtmlParser.setTreeBuildingWiretap() — so those handlers get the same locations a streaming parse gives, interleaved with the parser’s errors. SAXTreeBuilder also now sets the end locator of each element it pops. Fixes validator/validator#2168
|
@hsivonen, could you review this please? Again, we need this in htmlparser to be able to build latest vnu in Debian. |
|
Does SAXTree itself record too little in the Locators in the tree? Does this give you results that work for the purpose when there are foster-parented nodes or when the adoption agency algorithm transforms the tree? |
In one place: But the wiretap’s not about what the tree records. Given that the parser reports its own errors to the
Yes, basically (caveat below). Since the location recorder that the checker sets as the wiretap just notes the tokenizer’s position at each event, then it doesn’t care where a node lands in the tree — or if the events nest. In documents with foster-parented text, And the replay gives foster-parented elements their own source locations, in their tree positions. The (one) caveat is: When the adoption agency algorithm takes the formatting element out of the middle of the stack with But I couldn’t find any checker message that’s reported at the end tag of a formatting element — so in practice that doesn’t ever actually show up. I guess the fix for that would be in All that said, I’m not wedded to any of this. It’s just what was sufficient to resolve validator/validator#2168. If it seem to you it rightly should be done differently, I’m happy to try to rework along whatever lines you’d prefer. |
Problem: In the Nu HTML Checker, with
--no-stream, each HTML parser message got a range that started at the start of the document — or at the end of the previous message — so its extract and highlight took in all the markup from there to the error. And a checker message reported at an end tag got no location at all.Cause: When its streamability violation policy is
ALLOW,HtmlParseruses itsSAXTreeBuilder, which builds the whole tree beforeTreeParserreplays it as SAX events. So a SAX consumer that tracks locations had none for any error the parser reported, which the checker needs to find where the range of each error starts. Also,SAXTreeBuildernever set an element’s end locator, so the replay gaveendElementevents no location.Fix: As
SAXTreeBuilderbuilds the tree, it now sends the events a streaming parse emits, at the same points, to any handlers set with the newHtmlParser.setTreeBuildingWiretap()— so those handlers get the same locations a streaming parse gives, interleaved with the parser’s errors.SAXTreeBuilderalso now sets the end locator of each element it pops.Fixes validator/validator#2168