run: parse-error line numbers offset by prepended stdlib (+32) #18

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

Summary

patch-prolog run reports parse-error line numbers relative to the internally assembled source (stdlib + user files concatenated), not the user's file. Every reported line is shifted by the length of stdlib.pl (+1 for the joining newline) — currently +32.

Repro

A two-line file /tmp/op.pl:

p(foo).
go :- bar(+).
$ patch-prolog run /tmp/op.pl --goal go --format text
Error: Parse error: Unexpected token Plus at line 33 col 3

The error is on the user's line 2, but is reported as line 33. A one-line file reports the error around line 32–33, i.e. past EOF of what the user is looking at.

Cause

src/runner.rs::assemble_source() prepends knowledge/stdlib.pl (31 lines) + '\n' to the user's file content and parses the combined string, so parser line numbers are offset by the stdlib length. knowledge/stdlib.pl is 31 lines → offset is +32.

Impact

Learner-facing tooling (loglings) surfaces this error text verbatim. A beginner whose typo is on their line 5 is told "line 37" — past the end of their file. This makes the single most common error (a syntax slip) effectively impossible to locate from the message.

Suggested fix

Parse stdlib.pl as its own unit, or carry a per-source line offset and subtract the stdlib length before reporting (and ideally attach the originating filename to the span).


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

## Summary `patch-prolog run` reports parse-error line numbers relative to the *internally assembled* source (stdlib + user files concatenated), not the user's file. Every reported line is shifted by the length of `stdlib.pl` (+1 for the joining newline) — currently **+32**. ## Repro A two-line file `/tmp/op.pl`: ```prolog p(foo). go :- bar(+). ``` ``` $ patch-prolog run /tmp/op.pl --goal go --format text Error: Parse error: Unexpected token Plus at line 33 col 3 ``` The error is on the user's **line 2**, but is reported as **line 33**. A one-line file reports the error around line 32–33, i.e. past EOF of what the user is looking at. ## Cause `src/runner.rs::assemble_source()` prepends `knowledge/stdlib.pl` (31 lines) + `'\n'` to the user's file content and parses the combined string, so parser line numbers are offset by the stdlib length. `knowledge/stdlib.pl` is 31 lines → offset is +32. ## Impact Learner-facing tooling (loglings) surfaces this error text verbatim. A beginner whose typo is on their line 5 is told "line 37" — past the end of their file. This makes the single most common error (a syntax slip) effectively impossible to locate from the message. ## Suggested fix Parse `stdlib.pl` as its own unit, or carry a per-source line offset and subtract the stdlib length before reporting (and ideally attach the originating filename to the span). --- Found while building the `loglings` Prolog exercises against the installed engine.
Author
Owner

#23

https://git.navicore.tech/navicore/patch-prolog/pulls/23
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#18
No description provided.