Skip to content

Commit 3e57c20

Browse files
committed
parser: Add Token() to Node interface
Add Token() to ast Node interface so that we can more accurately pinpoint the error position, e.g.: func numf n:num print n end numf "abc" The example above only highlighted the end of line with the `numf` with a message saying first argument is of wrong type, but now it also highlights `"abc"` correctly. This is still problematic for error sources that are whole nodes, e.g.: numf "abc"+"123" Should probably highlight all of `"abc"+"123"` rather than just the first token. However, the might end up as undesired result for _very_ long expressions or multiline array / map literals.
1 parent a9e1f04 commit 3e57c20

File tree

5 files changed

+217
-90
lines changed

5 files changed

+217
-90
lines changed

pkg/evaluator/evaluator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ func TestHasErr(t *testing.T) {
789789
prog := `
790790
has ["a"] "a" // cannot run 'has' on array
791791
`
792-
want := "line 2 column 15: 'has' takes 1st argument of type '{}', found '[]string'"
792+
want := "line 2 column 5: 'has' takes 1st argument of type '{}', found '[]string'"
793793
got := run(prog)
794794
assert.Equal(t, want, got)
795795
}
@@ -825,7 +825,7 @@ func TestDelErr(t *testing.T) {
825825
prog := `
826826
del ["a"] "a" // cannot delete from array
827827
`
828-
want := "line 2 column 15: 'del' takes 1st argument of type '{}', found '[]string'"
828+
want := "line 2 column 5: 'del' takes 1st argument of type '{}', found '[]string'"
829829
got := run(prog)
830830
assert.Equal(t, want, got)
831831
}

0 commit comments

Comments
 (0)