Parse errors report internal token names (Plus, Star, Lt) instead of surface syntax #20

Closed
opened 2026-06-02 17:42:48 +00:00 by navicore · 1 comment
Owner

Summary

Parse errors name the engine's internal token variants (Plus, Star, Lt, Mod, Equals, Comma …) rather than the surface syntax the user actually typed.

Repro

$ patch-prolog run /tmp/x.pl --goal go
Error: Parse error: Unexpected token Plus at line .. col ..
Error: Parse error: Unexpected token Star at line .. col ..
Error: Parse error: Unexpected token Lt at line .. col ..

A user has no way to know Plus means +, Star means *, or Lt means <.

Suggested fix

Map each token back to its surface lexeme in the message, e.g.:

Parse error: unexpected `+` at line 2 col 3

A Display impl on the token type that yields the lexeme (+, *, <, mod, ,, =) would cover it. Pairs naturally with the line-offset fix (#18) — together they make parse errors actionable for beginners.

Impact

Lower severity than the line-number offset, but it's an easy win that directly improves the error experience for the learner-facing tooling (loglings) that surfaces these messages verbatim.


Found while building the loglings Prolog exercises against the installed engine.

## Summary Parse errors name the engine's internal token variants (`Plus`, `Star`, `Lt`, `Mod`, `Equals`, `Comma` …) rather than the surface syntax the user actually typed. ## Repro ``` $ patch-prolog run /tmp/x.pl --goal go Error: Parse error: Unexpected token Plus at line .. col .. Error: Parse error: Unexpected token Star at line .. col .. Error: Parse error: Unexpected token Lt at line .. col .. ``` A user has no way to know `Plus` means `+`, `Star` means `*`, or `Lt` means `<`. ## Suggested fix Map each token back to its surface lexeme in the message, e.g.: ``` Parse error: unexpected `+` at line 2 col 3 ``` A `Display` impl on the token type that yields the lexeme (`+`, `*`, `<`, `mod`, `,`, `=`) would cover it. Pairs naturally with the line-offset fix (#18) — together they make parse errors actionable for beginners. ## Impact Lower severity than the line-number offset, but it's an easy win that directly improves the error experience for the learner-facing tooling (loglings) that surfaces these messages verbatim. --- Found while building the `loglings` Prolog exercises against the installed engine.
Author
Owner

#25

https://git.navicore.tech/navicore/patch-prolog/pulls/25
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
navicore/patch-prolog#20
No description provided.