Skip to content

Commit

Permalink
Update our parse errors to match latest illuaminate
Browse files Browse the repository at this point in the history
We've been out-of-date for a while now, as we needed to update
lua_menhir to work with lrgrep 3.

 - Better handling of standalone names/expressions - we now correctly
   handle lists of names.

 - Handle missing commas in tables in a few more places.
  • Loading branch information
SquidDev committed Feb 8, 2024
1 parent f14cb2a commit d289647
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 142 deletions.
4 changes: 4 additions & 0 deletions illuaminate.sexp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
/projects/core/src/main/resources/data/computercraft/lua/rom/apis/turtle/turtle.lua)
(linters -var:deprecated))

;; Suppress unused variable warnings in the parser.
(at /projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/parser.lua
(linters -var:unused))

(at /projects/core/src/test/resources/test-rom
; We should still be able to test deprecated members.
(linters -var:deprecated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,32 +453,53 @@ function errors.local_function_dot(local_start, local_end, dot_start, dot_end)
}
end

--[[- A statement of the form `x.y z`
--[[- A statement of the form `x.y`
@tparam number token The token id.
@tparam number pos The position right after this name.
@return The resulting parse error.
]]
function errors.standalone_name(pos)
expect(1, pos, "number")
function errors.standalone_name(token, pos)
expect(1, token, "number")
expect(2, pos, "number")

return {
"Unexpected symbol after name.",
"Unexpected " .. token_names[token] .. " after name.",
annotate(pos),
"Did you mean to assign this or call it as a function?",
}
end

--[[- A statement of the form `x.y, z`
@tparam number token The token id.
@tparam number pos The position right after this name.
@return The resulting parse error.
]]
function errors.standalone_names(token, pos)
expect(1, token, "number")
expect(2, pos, "number")

return {
"Unexpected " .. token_names[token] .. " after name.",
annotate(pos),
"Did you mean to assign this?",
}
end

--[[- A statement of the form `x.y`. This is similar to [`standalone_name`], but
when the next token is on another line.
@tparam number token The token id.
@tparam number pos The position right after this name.
@return The resulting parse error.
]]
function errors.standalone_name_call(pos)
expect(1, pos, "number")
function errors.standalone_name_call(token, pos)
expect(1, token, "number")
expect(2, pos, "number")

return {
"Unexpected symbol after variable.",
"Unexpected " .. token_names[token] .. " after name.",
annotate(pos + 1, "Expected something before the end of the line."),
"Tip: Use " .. code("()") .. " to call with no arguments.",
}
Expand Down
Loading

0 comments on commit d289647

Please sign in to comment.