mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 12:10:30 +00:00
Improve several comma related parse errors
- Suggest adding a comma on { 2 3 } - Suggest removing a comma on f(1, ) Closes #1341.
This commit is contained in:
parent
41c83988a1
commit
4e909bc59e
@ -364,6 +364,48 @@ function errors.table_key_equals(start_pos, end_pos)
|
||||
}
|
||||
end
|
||||
|
||||
--[[- There is a trailing comma in this list of function arguments.
|
||||
|
||||
@tparam number token The token id.
|
||||
@tparam number token_start The start position of the token.
|
||||
@tparam number token_end The end position of the token.
|
||||
@tparam number prev The start position of the previous entry.
|
||||
@treturn table The resulting parse error.
|
||||
]]
|
||||
function errors.missing_table_comma(token, token_start, token_end, prev)
|
||||
expect(1, token, "number")
|
||||
expect(2, token_start, "number")
|
||||
expect(3, token_end, "number")
|
||||
expect(4, prev, "number")
|
||||
|
||||
return {
|
||||
"Unexpected " .. token_names[token] .. " in table.",
|
||||
annotate(token_start, token_end),
|
||||
annotate(prev + 1, prev + 1, "Are you missing a comma here?"),
|
||||
}
|
||||
end
|
||||
|
||||
--[[- There is a trailing comma in this list of function arguments.
|
||||
|
||||
@tparam number comma_start The start position of the `,` token.
|
||||
@tparam number comma_end The end position of the `,` token.
|
||||
@tparam number paren_start The start position of the `)` token.
|
||||
@tparam number paren_end The end position of the `)` token.
|
||||
@treturn table The resulting parse error.
|
||||
]]
|
||||
function errors.trailing_call_comma(comma_start, comma_end, paren_start, paren_end)
|
||||
expect(1, comma_start, "number")
|
||||
expect(2, comma_end, "number")
|
||||
expect(3, paren_start, "number")
|
||||
expect(4, paren_end, "number")
|
||||
|
||||
return {
|
||||
"Unexpected " .. code(")") .. " in function call.",
|
||||
annotate(paren_start, paren_end),
|
||||
annotate(comma_start, comma_end, "Tip: Try removing this " .. code(",") .. "."),
|
||||
}
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Statement parsing errors
|
||||
--------------------------------------------------------------------------------
|
||||
|
File diff suppressed because one or more lines are too long
@ -95,6 +95,48 @@ Unexpected end of file. Are you missing a closing bracket?
|
||||
| ^ Unexpected end of file here.
|
||||
```
|
||||
|
||||
## Missing commas in tables
|
||||
|
||||
```lua
|
||||
return { 1 2 }
|
||||
```
|
||||
|
||||
```txt
|
||||
Unexpected number in table.
|
||||
|
|
||||
1 | return { 1 2 }
|
||||
| ^
|
||||
|
|
||||
1 | return { 1 2 }
|
||||
| ^ Are you missing a comma here?
|
||||
```
|
||||
```lua
|
||||
return { 1, 2 3 }
|
||||
```
|
||||
|
||||
```txt
|
||||
Unexpected number in table.
|
||||
|
|
||||
1 | return { 1, 2 3 }
|
||||
| ^
|
||||
|
|
||||
1 | return { 1, 2 3 }
|
||||
| ^ Are you missing a comma here?
|
||||
```
|
||||
```lua
|
||||
print({ 1, )
|
||||
```
|
||||
|
||||
```txt
|
||||
Unexpected ). Are you missing a closing bracket?
|
||||
|
|
||||
1 | print({ 1, )
|
||||
| ^ Brackets were opened here.
|
||||
|
|
||||
1 | print({ 1, )
|
||||
| ^ Unexpected ) here.
|
||||
```
|
||||
|
||||
# Statements
|
||||
|
||||
## Local functions with table identifiers
|
||||
@ -368,3 +410,35 @@ Unexpected end.
|
||||
| ^^^
|
||||
Your program contains more ends than needed. Check each block (if, for, function, ...) only has one end.
|
||||
```
|
||||
|
||||
# Function calls
|
||||
|
||||
## Additional commas
|
||||
We suggest the user removes additional trailing commas on function calls:
|
||||
|
||||
```lua
|
||||
f(2, )
|
||||
```
|
||||
|
||||
```txt
|
||||
Unexpected ) in function call.
|
||||
|
|
||||
1 | f(2, )
|
||||
| ^
|
||||
|
|
||||
1 | f(2, )
|
||||
| ^ Tip: Try removing this ,.
|
||||
```
|
||||
```lua
|
||||
f(2, 3, )
|
||||
```
|
||||
|
||||
```txt
|
||||
Unexpected ) in function call.
|
||||
|
|
||||
1 | f(2, 3, )
|
||||
| ^
|
||||
|
|
||||
1 | f(2, 3, )
|
||||
| ^ Tip: Try removing this ,.
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user