mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 01:10:30 +00:00
Nicer lexer error for "!"
This commit is contained in:
parent
209b1ddbf9
commit
5af3e15dd5
@ -284,6 +284,23 @@ function errors.wrong_ne(start_pos, end_pos)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[- `!` was used instead of `not`.
|
||||||
|
|
||||||
|
@tparam number start_pos The start position of the token.
|
||||||
|
@tparam number end_pos The end position of the token.
|
||||||
|
@return The resulting parse error.
|
||||||
|
]]
|
||||||
|
function errors.wrong_not(start_pos, end_pos)
|
||||||
|
expect(1, start_pos, "number")
|
||||||
|
expect(2, end_pos, "number")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"Unexpected character.",
|
||||||
|
annotate(start_pos, end_pos),
|
||||||
|
"Tip: Replace this with " .. code("not") .. " to negate a boolean.",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
--[[- An unexpected character was used.
|
--[[- An unexpected character was used.
|
||||||
|
|
||||||
@tparam number pos The position of this character.
|
@tparam number pos The position of this character.
|
||||||
|
@ -327,6 +327,9 @@ local function lex_token(context, str, pos)
|
|||||||
elseif contents == "!=" or contents == "<>" then
|
elseif contents == "!=" or contents == "<>" then
|
||||||
context.report(errors.wrong_ne, pos, end_pos)
|
context.report(errors.wrong_ne, pos, end_pos)
|
||||||
return tokens.NE, end_pos
|
return tokens.NE, end_pos
|
||||||
|
elseif contents == "!" then
|
||||||
|
context.report(errors.wrong_not, pos, end_pos)
|
||||||
|
return tokens.NOT, end_pos
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -265,6 +265,7 @@ if a != b then end
|
|||||||
if a ~= b then end
|
if a ~= b then end
|
||||||
if a && b then end
|
if a && b then end
|
||||||
if a || b then end
|
if a || b then end
|
||||||
|
if ! a then end
|
||||||
```
|
```
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
@ -307,6 +308,16 @@ Tip: Replace this with or to check if either value is true.
|
|||||||
4:9-4:9 IDENT b
|
4:9-4:9 IDENT b
|
||||||
4:11-4:14 THEN then
|
4:11-4:14 THEN then
|
||||||
4:16-4:18 END end
|
4:16-4:18 END end
|
||||||
|
5:1-5:2 IF if
|
||||||
|
Unexpected character.
|
||||||
|
|
|
||||||
|
5 | if ! a then end
|
||||||
|
| ^
|
||||||
|
Tip: Replace this with not to negate a boolean.
|
||||||
|
5:4-5:4 NOT !
|
||||||
|
5:6-5:6 IDENT a
|
||||||
|
5:8-5:11 THEN then
|
||||||
|
5:13-5:15 END end
|
||||||
```
|
```
|
||||||
|
|
||||||
For entirely unknown glyphs we should just give up and return an `ERROR` token.
|
For entirely unknown glyphs we should just give up and return an `ERROR` token.
|
||||||
|
Loading…
Reference in New Issue
Block a user