Improve parser errors on extra exprs/tokens on line #35

Closed
opened 2024-05-18 22:18:38 +00:00 by scott · 1 comment
Owner

I think there's an off-by-one error, in the parse functions for scripts and blocks, at least.

Test case:

foo bar
baz

Expected behaviour: error on line 1: "expected terminator", resumed parsing on line 2.

Actual behaviour: error on line 1: "expected terminator", error on line 2: "expected expression, got newline"

Here's the error dump, lightly structured:

@[{:data 
 @[
  {:input :input :lexeme "bar" :line 1 :literal :none :source "foo bar\nbaz\n" :start 4 :type :word} 
  {:input :input :lexeme "\n" :line 2 :source "foo bar\nbaz\n" :start 7 :type :newline}] 
 :msg "expected terminator" :token { :input :input :lexeme "bar" :line 1 :literal :none :source "foo bar\nbaz\n" :start 4 :type :word} :type :error}
{:data 
 @[
  {:input :input :lexeme "\n" :line 2 :source  "foo bar\nbaz\n":start 7 :type :newline} 
  {:input :input :lexeme "baz" :line 2 :literal :none :source  "foo bar\nbaz\n" :start 8 :type :word} 
  {:input :input :lexeme "\n" :line 3 :source "foo bar\nbaz\n" :start 11 :type :newline}] 
 :msg "expected expression, got newline" :token { :input :input :lexeme "\n" :line 2 :source "foo bar\nbaz\n" :start 7 :type :newline} :type :error}
]
I think there's an off-by-one error, in the parse functions for scripts and blocks, at least. Test case: ``` foo bar baz ``` Expected behaviour: error on line 1: "expected terminator", resumed parsing on line 2. Actual behaviour: error on line 1: "expected terminator", error on line 2: "expected expression, got newline" Here's the error dump, lightly structured: ```janet @[{:data @[ {:input :input :lexeme "bar" :line 1 :literal :none :source "foo bar\nbaz\n" :start 4 :type :word} {:input :input :lexeme "\n" :line 2 :source "foo bar\nbaz\n" :start 7 :type :newline}] :msg "expected terminator" :token { :input :input :lexeme "bar" :line 1 :literal :none :source "foo bar\nbaz\n" :start 4 :type :word} :type :error} {:data @[ {:input :input :lexeme "\n" :line 2 :source "foo bar\nbaz\n":start 7 :type :newline} {:input :input :lexeme "baz" :line 2 :literal :none :source "foo bar\nbaz\n" :start 8 :type :word} {:input :input :lexeme "\n" :line 3 :source "foo bar\nbaz\n" :start 11 :type :newline}] :msg "expected expression, got newline" :token { :input :input :lexeme "\n" :line 2 :source "foo bar\nbaz\n" :start 7 :type :newline} :type :error} ] ```
scott added this to the Computer Class milestone 2024-05-18 22:19:44 +00:00
scott added the
bug
enhancement
now
labels 2024-05-18 22:20:06 +00:00
scott self-assigned this 2024-05-29 19:09:06 +00:00
scott modified the milestone from Computer Class to 0.2.0 2024-06-24 21:05:55 +00:00
scott added this to the Better errors project 2024-07-03 00:19:54 +00:00
Author
Owner

Finally figured this out. Complete in 4a069278b8

Finally figured this out. Complete in https://alea.ludus.dev/twc/ludus/commit/4a069278b8f3caf8f3661047e012d10395b5bb5d
scott closed this issue 2024-07-19 20:14:18 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
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: twc/ludus#35
No description provided.