Parse errors carry line/column + context snippet - #5
Merged
Conversation
New html.errors module (line_col + parse_error), following the shared mojo-* suite pattern. Strict-mode tokenizer errors now read "mojo-html [strict]: <msg> at line <L>, column <C>: <snippet>" with more useful offsets: unclosed-element errors point at the unclosed start tag instead of EOF, and entity errors point at the offending & in text, attribute values, and escapable raw text. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Adopts the suite-wide error-reporting pattern from conorbronsdon/mojo-xml#3: parse errors now carry a 1-based line/column position and a snippet of the offending line.
What changed
html.errorsmodule — a verbatim copy of mojo-xml'serrors.mojo.line_col(source, offset)maps a byte offset to a 1-based (line, column) pair (column = byte offset within the line; LF-only terminator, CRLF-safe), andparse_error(msg, source, offset)builds anErrorreading<msg> at line <L>, column <C>: '<snippet>'— snippet is the whitespace-trimmed offending line, windowed to ~30 bytes centered on the offset,...on cut sides, never split mid-UTF-8-sequence, never multi-line. Both exported from the package.strict=Trueand already had a byte offset, so all of them now carry position + snippet (previously a bare(line L, column C)suffix with no snippet):_open_posbookkeeping, strict mode only)&, malformed numeric reference — now point at the offending&(in text, attribute values, and escapable raw text) instead of the tokenizer's position after the runraise Error(...); the repo-specificmojo-html [strict]:prefix stays in the caller; existingcontains=-style assertions keep matching.test/test_errors.mojo(31 tests) — the fullline_col/parse_erroredge-case suite ported from mojo-xml, plus 11 integration tests asserting hand-verified line/column/snippet output for every wired raise site. Registered in the pixitesttask and the CI workflow. Full suite: 99 tests green.🤖 Generated with Claude Code