mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-08 23:20:06 +00:00
Update our parse errors to match latest illuaminate
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.
This commit is contained in:
parent
f14cb2a3d1
commit
d2896473f2
@ -105,6 +105,10 @@
|
|||||||
/projects/core/src/main/resources/data/computercraft/lua/rom/apis/turtle/turtle.lua)
|
/projects/core/src/main/resources/data/computercraft/lua/rom/apis/turtle/turtle.lua)
|
||||||
(linters -var:deprecated))
|
(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
|
(at /projects/core/src/test/resources/test-rom
|
||||||
; We should still be able to test deprecated members.
|
; We should still be able to test deprecated members.
|
||||||
(linters -var:deprecated)
|
(linters -var:deprecated)
|
||||||
|
@ -453,32 +453,53 @@ function errors.local_function_dot(local_start, local_end, dot_start, dot_end)
|
|||||||
}
|
}
|
||||||
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.
|
@tparam number pos The position right after this name.
|
||||||
@return The resulting parse error.
|
@return The resulting parse error.
|
||||||
]]
|
]]
|
||||||
function errors.standalone_name(pos)
|
function errors.standalone_name(token, pos)
|
||||||
expect(1, pos, "number")
|
expect(1, token, "number")
|
||||||
|
expect(2, pos, "number")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"Unexpected symbol after name.",
|
"Unexpected " .. token_names[token] .. " after name.",
|
||||||
annotate(pos),
|
annotate(pos),
|
||||||
"Did you mean to assign this or call it as a function?",
|
"Did you mean to assign this or call it as a function?",
|
||||||
}
|
}
|
||||||
end
|
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
|
--[[- A statement of the form `x.y`. This is similar to [`standalone_name`], but
|
||||||
when the next token is on another line.
|
when the next token is on another line.
|
||||||
|
|
||||||
|
@tparam number token The token id.
|
||||||
@tparam number pos The position right after this name.
|
@tparam number pos The position right after this name.
|
||||||
@return The resulting parse error.
|
@return The resulting parse error.
|
||||||
]]
|
]]
|
||||||
function errors.standalone_name_call(pos)
|
function errors.standalone_name_call(token, pos)
|
||||||
expect(1, pos, "number")
|
expect(1, token, "number")
|
||||||
|
expect(2, pos, "number")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"Unexpected symbol after variable.",
|
"Unexpected " .. token_names[token] .. " after name.",
|
||||||
annotate(pos + 1, "Expected something before the end of the line."),
|
annotate(pos + 1, "Expected something before the end of the line."),
|
||||||
"Tip: Use " .. code("()") .. " to call with no arguments.",
|
"Tip: Use " .. code("()") .. " to call with no arguments.",
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -347,7 +347,7 @@ function ( xyz , while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected while.
|
Unexpected while. Expected a variable name.
|
||||||
|
|
|
|
||||||
1 | function ( xyz , while
|
1 | function ( xyz , while
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
@ -483,11 +483,11 @@ xyz , xyz while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected symbol after name.
|
Unexpected while after name.
|
||||||
|
|
|
|
||||||
1 | xyz , xyz while
|
1 | xyz , xyz while
|
||||||
| ^
|
| ^
|
||||||
Did you mean to assign this or call it as a function?
|
Did you mean to assign this?
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -831,7 +831,7 @@ xyz while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected symbol after name.
|
Unexpected while after name.
|
||||||
|
|
|
|
||||||
1 | xyz while
|
1 | xyz while
|
||||||
| ^
|
| ^
|
||||||
@ -858,7 +858,7 @@ xyz while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected symbol after name.
|
Unexpected while after name.
|
||||||
|
|
|
|
||||||
1 | xyz while
|
1 | xyz while
|
||||||
| ^
|
| ^
|
||||||
@ -1056,7 +1056,7 @@ local while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected while.
|
Unexpected while. Expected a variable name.
|
||||||
|
|
|
|
||||||
1 | local while
|
1 | local while
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
@ -1272,7 +1272,7 @@ repeat --[[eof]]
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected end of file. Expected a statement.
|
Unexpected end of file. Expected a variable name.
|
||||||
|
|
|
|
||||||
2 | -- Line 1: 'until' expected near <eof> (program)
|
2 | -- Line 1: 'until' expected near <eof> (program)
|
||||||
| ^
|
| ^
|
||||||
@ -1389,7 +1389,7 @@ while
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected while.
|
Unexpected while. Expected an expression.
|
||||||
|
|
|
|
||||||
1 | while
|
1 | while
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
@ -38,6 +38,20 @@ Unexpected = in expression.
|
|||||||
Tip: Wrap the preceding expression in [ and ] to use it as a table key.
|
Tip: Wrap the preceding expression in [ and ] to use it as a table key.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
and also
|
||||||
|
|
||||||
|
```lua
|
||||||
|
return { x + 1 = 1 }
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected = in expression.
|
||||||
|
|
|
||||||
|
1 | return { x + 1 = 1 }
|
||||||
|
| ^
|
||||||
|
Tip: Wrap the preceding expression in [ and ] to use it as a table key.
|
||||||
|
```
|
||||||
|
|
||||||
Note this doesn't occur if this there's already a table key here:
|
Note this doesn't occur if this there's already a table key here:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
@ -102,6 +116,7 @@ Unexpected end of file. Are you missing a closing bracket?
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Missing commas in tables
|
## Missing commas in tables
|
||||||
|
We try to detect missing commas in tables, and print an appropriate error message.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
return { 1 2 }
|
return { 1 2 }
|
||||||
@ -129,6 +144,39 @@ Unexpected number in table.
|
|||||||
1 | return { 1, 2 3 }
|
1 | return { 1, 2 3 }
|
||||||
| ^ Are you missing a comma here?
|
| ^ Are you missing a comma here?
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This also works with table keys.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
print({ x = 1 y = 2 })
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected identifier in table.
|
||||||
|
|
|
||||||
|
1 | print({ x = 1 y = 2 })
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
1 | print({ x = 1 y = 2 })
|
||||||
|
| ^ Are you missing a comma here?
|
||||||
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
print({ ["x"] = 1 ["y"] = 2 })
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected [ in table.
|
||||||
|
|
|
||||||
|
1 | print({ ["x"] = 1 ["y"] = 2 })
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
1 | print({ ["x"] = 1 ["y"] = 2 })
|
||||||
|
| ^ Are you missing a comma here?
|
||||||
|
```
|
||||||
|
|
||||||
|
We gracefully handle the case where we are actually missing a closing brace.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
print({ 1, )
|
print({ 1, )
|
||||||
```
|
```
|
||||||
@ -172,7 +220,7 @@ local _ = 1
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected symbol after variable.
|
Unexpected local after name.
|
||||||
|
|
|
|
||||||
1 | term.clear
|
1 | term.clear
|
||||||
| ^ Expected something before the end of the line.
|
| ^ Expected something before the end of the line.
|
||||||
@ -186,7 +234,7 @@ x 1
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected symbol after name.
|
Unexpected number after name.
|
||||||
|
|
|
|
||||||
1 | x 1
|
1 | x 1
|
||||||
| ^
|
| ^
|
||||||
@ -200,13 +248,41 @@ term.clear
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected symbol after variable.
|
Unexpected end of file after name.
|
||||||
|
|
|
|
||||||
1 | term.clear
|
1 | term.clear
|
||||||
| ^ Expected something before the end of the line.
|
| ^ Expected something before the end of the line.
|
||||||
Tip: Use () to call with no arguments.
|
Tip: Use () to call with no arguments.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When we've got a list of variables, we only suggest assigning it.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
term.clear, foo
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file after name.
|
||||||
|
|
|
||||||
|
1 | term.clear, foo
|
||||||
|
| ^
|
||||||
|
Did you mean to assign this?
|
||||||
|
```
|
||||||
|
|
||||||
|
And when we've got a partial expression, we only suggest calling it.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
(a + b)
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file after name.
|
||||||
|
|
|
||||||
|
1 | (a + b)
|
||||||
|
| ^ Expected something before the end of the line.
|
||||||
|
Tip: Use () to call with no arguments.
|
||||||
|
```
|
||||||
|
|
||||||
## If statements
|
## If statements
|
||||||
For if statements, we say when we expected the `then` keyword.
|
For if statements, we say when we expected the `then` keyword.
|
||||||
|
|
||||||
@ -425,7 +501,7 @@ goto 2
|
|||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
Unexpected symbol after name.
|
Unexpected number after name.
|
||||||
|
|
|
|
||||||
1 | goto 2
|
1 | goto 2
|
||||||
| ^
|
| ^
|
||||||
@ -460,6 +536,31 @@ Unexpected end of file.
|
|||||||
| ^
|
| ^
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Missing function arguments
|
||||||
|
We provide an error message for missing arguments in function definitions:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
function f
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file. Expected ( to start function arguments.
|
||||||
|
|
|
||||||
|
1 | function f
|
||||||
|
| ^
|
||||||
|
```
|
||||||
|
|
||||||
|
```lua
|
||||||
|
return function
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
Unexpected end of file. Expected ( to start function arguments.
|
||||||
|
|
|
||||||
|
1 | return function
|
||||||
|
| ^
|
||||||
|
```
|
||||||
|
|
||||||
# Function calls
|
# Function calls
|
||||||
|
|
||||||
## Additional commas
|
## Additional commas
|
||||||
|
Loading…
x
Reference in New Issue
Block a user