Skip to content

Parse errors carry line/column + context snippet - #4

Merged
conorbronsdon merged 1 commit into
mainfrom
error-positions
Jul 8, 2026
Merged

Parse errors carry line/column + context snippet#4
conorbronsdon merged 1 commit into
mainfrom
error-positions

Conversation

@conorbronsdon

Copy link
Copy Markdown
Owner

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 reference errors.mojo: line_col(source, offset) maps a byte offset to a 1-based (line, byte-column) pair; parse_error(msg, source, offset) builds an Error reading <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_col and parse_error exported from the markdown package.
  • 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 pixi test task and as a CI step.
  • CHANGELOG entry.

Why no call sites are wired

CommonMark treats every input as valid markdown, so this parser has zero input-error raise sites — 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.
  • Format gate (pixi run fmt && git diff --exit-code) clean on the committed tree.

🤖 Generated with Claude Code

…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>
@conorbronsdon
conorbronsdon merged commit 0ad227a into main Jul 8, 2026
1 check passed
@conorbronsdon
conorbronsdon deleted the error-positions branch July 8, 2026 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant