Skip to content

Commit

Permalink
Remove extra spaces in syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thedae committed Nov 14, 2024
1 parent 4729585 commit d0ebcab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func parseSyntaxError(errorText string) (string, int) {

parts := strings.Split(errorText, " near ")
if len(parts) == 2 {
text = strings.TrimSuffix(parts[1], "\n")
text = strings.Join(strings.Fields(strings.TrimSuffix(parts[1], "\n")), " ")
where := strings.Split(strings.TrimSuffix(strings.ReplaceAll(parts[0], "<string> line:", ""), ")"), "(column:")
if v, err := strconv.Atoi(where[0]); err == nil {
problem = v
Expand Down
8 changes: 4 additions & 4 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ func TestErrorSourceSyntaxError(t *testing.T) {
{
name: "Inline",
src: "local p = person.new('Steeve');lokal t = 'fail'",
expected: "Line 1: 't': parse error",
expected: "Line 1: 't': parse error",
},
{
name: "Parsing error",
src: "local p = person.new('Steeve')\nlokal t = 'fail'",
expected: "Line 2: 't': parse error",
expected: "Line 2: 't': parse error",
},
{
name: "Bad token",
src: "local p = person.new('Steeve')\nlocal t & 'fail'",
expected: "Line 2: '&': Invalid token",
expected: "Line 2: '&': Invalid token",
},
{
name: "Unterminated string",
src: "local p = person.new('Steeve)\nlocal t = 'okay'",
expected: "Line 2: 'Steeve)': unterminated string",
expected: "Line 2: 'Steeve)': unterminated string",
},
{
name: "End of file",
Expand Down

0 comments on commit d0ebcab

Please sign in to comment.