Parse errors carry line/column + context snippet - #4
Merged
Conversation
New template.errors module (line_col + parse_error), copied from the suite-wide pattern established in mojo-xml. Lexer tokens and expression tokens now carry byte offsets into the template source; every lexer and parser raise site reports "<msg> at line L, column C: <snippet>" — unclosed constructs point at their opening tag, expression errors at the offending byte. Render-time errors are unchanged (the AST carries no source positions). 26 new tests in test/test_errors.mojo, wired into the pixi test task and CI. 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 position info to every parse-time error, following the shared
errors.mojopattern established in conorbronsdon/mojo-xml#3.template.errorsmodule, copied verbatim from mojo-xml:line_col(source, offset)(1-based line; column = 1-based byte offset in the line, LF-only terminators, clamped) andparse_error(msg, source, offset)producing<msg> at line <L>, column <C>: '<snippet>'with a ~30-byte, UTF-8-safe, single-line snippet of the offending line. Both exported from the package.Tokens carry byte offsets (tag opener + inner-content start) instead of line numbers; expression tokens carry absolute byte offsets. Every lexer/parser raise site now reports an exact position: unclosed tags and unclosed{% if %}/{% for %}point at the opening tag (not EOF), expression errors (unexpected character, unterminated string literal, trailing tokens, missing]/)/names, depth-cap guards) point at the offending byte. Guard conditions untouched — only error construction changed.test/test_errors.mojo(ported edge-case suite + 6 integration tests with hand-verified line/column), wired into the pixitesttask and CI as a separate step. Full suite: 104 tests green;mojo formatclean.🤖 Generated with Claude Code