Parse errors carry line/column + context snippet - #4
Merged
Conversation
…ror) Adopts the errors.mojo pattern shared across the mojo-* parser suite (byte-identical copy of the reference module). Exports line_col and parse_error from the package, adds 20 unit tests covering every documented edge case, and registers the new test file in the pixi test task and CI. No parser call sites wired: CommonMark accepts all input, so the parser has no input-error raise sites to attach positions to. 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.
Adds the position-aware parse-error module used across the mojo-* parser suite, following the pattern established in mojo-xml#3.
What
src/markdown/errors.mojo— byte-identical copy of the suite's referenceerrors.mojo:line_col(source, offset)maps a byte offset to a 1-based (line, byte-column) pair;parse_error(msg, source, offset)builds anErrorreading<msg> at line <L>, column <C>: '<snippet>'(offending line, whitespace-trimmed, ~30-byte window centered on the column,...where cut, UTF-8-safe, never multi-line).line_colandparse_errorexported from themarkdownpackage.test/test_errors.mojo— 20 unit tests covering every documented edge case (LF/CRLF, clamping, empty source, exact message format, truncation, UTF-8 window nudging). Registered in the pixitesttask and as a CI step.Why no call sites are wired
CommonMark treats every input as valid markdown, so this parser has zero input-error
raisesites — the only defensive limit (the 256-level container nesting cap) degrades silently to paragraph text rather than raising. The module lands for suite consistency and for downstream users validating markdown-adjacent input.Verification
pixi run test: 49 + 20 tests, all pass.pixi run conformance: 643/652 — unchanged from baseline.pixi run fmt && git diff --exit-code) clean on the committed tree.🤖 Generated with Claude Code