Skip to content

v1.10.0 - Parse errors report the real location (8 languages)

Choose a tag to compare

@gmpassos gmpassos released this 11 Jul 04:48
· 180 commits to master since this release
7b010df

Parse errors now point at the real mistake, not the top of the file

Every ApolloVM grammar's top rule is compilationUnit().star().trim().end(). When a syntax error appeared deep in a file, the last top-level definition failed deep in the input, but star() discarded that failure and end() reported a generic end of input expected at offset 0 (line 1). petitparser's plain parse() does not track the farthest failure, so the deep position was lost.

Parsers now record the farthest point the grammar actually reached and report the error there — at or immediately adjacent to the real mistake.

  • New opt-in ApolloSourceCodeParser.trackFarthestFailure: on failure, the source is re-parsed with a copy of the grammar (petitparser transformParser + callCC) in which every parser records each Failure if it is the deepest seen — capturing failures that star()/optional() would swallow. The deeper of the two positions is used, so the reported position never gets worse. The happy path is untouched: the fast plain parser runs first; the tracking re-parse only runs on failure.
  • Enabled for Dart, Java 11, Kotlin, Go, C#, JavaScript, TypeScript and Lua — an invalid token mid-expression is now reported exactly at that token instead of at line 1.
  • Python is intentionally excluded: its indentation preprocessor rewrites the source, so grammar offsets are in preprocessed coordinates (shifted lines, leaked markers). A source map back to the original is future work.

LSP

  • locateParseError now runs its structural heuristics (bracket-imbalance, missing ;) before trusting the raw parser position, then falls back to the now-precise position — preserving editor-friendly locations while improving the fallback for every other failure.

Full Changelog: v1.9.2...v1.10.0