Skip to content

Preserve diagnostics at newlines and unconsumed input - #14

Open
OskarEichler wants to merge 1 commit into
floraison:masterfrom
OskarEichler:codex/repair-newline-error-diagnostics
Open

Preserve diagnostics at newlines and unconsumed input#14
OskarEichler wants to merge 1 commit into
floraison:masterfrom
OskarEichler:codex/repair-newline-error-diagnostics

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Fix error reporting in three related boundary cases:

  • Compute line/column using characters preceding the error, so an error on a newline has a valid column.
  • Retain empty/trailing lines for caret rendering.
  • When a successful primitive parser leaves input unconsumed and has no failed child, report the end of its matched prefix instead of dereferencing a missing error tree.

Reproduction

A grammar requiring a literal x raises NoMethodError when parsing "xy" with error:true; it now returns a diagnostic at line 1, column 2, offset 1. A grammar requiring "x\n" followed by y reports EOF at line 2, column 1 for input "x\n".

Temporary comparisons cover an error on the first newline, an unconsumed newline, plain trailing text, EOF on an empty final line, an empty failed Tree and Unicode character offsets. Both prune:true and prune:false are checked. Existing multiline/CRLF diagnostics remain covered by the upstream suite.

Verification

  • Reviewed master baseline, each individual patch, and the combined installed-release branch: existing suite passes 94 tests / 169 assertions, zero failures.
  • Ruby 4.0.6 via rbenv, Probatio 1.6.2. No new or modified test files.
  • Focused temporary repros, Ruby syntax and gem packaging checks pass. Targeted Lint reports the same 13 pre-existing warnings on baseline and fixed source, with no new warnings.
  • Consumer branch is based on installed 1.5.0 rather than importing unrelated master changes.

No production operations. Other Ruby/platform combinations were not run locally; no full supported-platform claim. Current open/closed issue/PR searches found no overlapping fix.

Breaking changes

No intended API break; diagnostic array shape is preserved. Previously crashing paths return diagnostics, with corrected newline coordinates. Does not change parser acceptance or introduce general recovery from malformed custom Tree objects. The separate all-combinator patch addresses failed grammars incorrectly accepting empty input.

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