Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reserved words #3201

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/entities/gmod_wire_expression2/base/tokenizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
AddCSLuaFile()

local Trace, Warning, Error = E2Lib.Debug.Trace, E2Lib.Debug.Warning, E2Lib.Debug.Error
local ReservedWord = E2Lib.ReservedWord

local tonumber = tonumber
local string_find, string_gsub, string_sub = string.find, string.gsub, string.sub
Expand Down Expand Up @@ -269,6 +270,7 @@
elseif match == "false" then
return Token.new(TokenVariant.Boolean, false)
elseif string_sub(match, 1, 1) ~= "#" then
if ReservedWord[match] then self:Warning("'".. match .. "' is a reserved identifier and may break your code in the future") end
return Token.new(TokenVariant.LowerIdent, match)
end
end
Expand Down Expand Up @@ -315,7 +317,7 @@
esc = escapes[char]
elseif char == "u" then
self:SkipChar()
if self:At() ~= "{" then err = "Unicode escape must begin with {" goto _err end

Check warning on line 320 in lua/entities/gmod_wire_expression2/base/tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.

esc = self:ConsumePatternMulti("^%b{}")

Expand All @@ -328,7 +330,7 @@
if illegal then
err = "Unicode escape must contain hexadecimal digits"
col = col + illegal + 1
goto _err

Check warning on line 333 in lua/entities/gmod_wire_expression2/base/tokenizer.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
end
local num = tonumber(esc, 16)
if not num then
Expand Down
53 changes: 53 additions & 0 deletions lua/entities/gmod_wire_expression2/core/e2lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@
function E2Lib.isOwner(self, entity)
local owner = E2Lib.getOwner(self, entity)
if not IsValid(owner) then return false end

Check warning on line 477 in lua/entities/gmod_wire_expression2/core/e2lib.lua

View workflow job for this annotation

GitHub Actions / lint

"Trailing whitespace"

Trailing whitespace
return E2Lib.isFriend(owner, self.player)
end
end
Expand Down Expand Up @@ -653,6 +653,59 @@

E2Lib.Keyword = Keyword

--- A list of every word that we might use in the future
E2Lib.ReservedWord = {
abstract = true,
as = true,
await = true,
async = true,
class = true,
constructor = true,
debugger = true,
declare = true,
default = true,
delete = true,
enum = true,
export = true,
extends = true,
["false"] = true,
finally = true,
from = true,
implements = true,
import = true,
["in"] = true,
instanceof = true,
interface = true,
match = true,
macro = true,
mod = true,
module = true,
mut = true,
namespace = true,
new = true,
null = true,
of = true,
package = true,
private = true,
protected =true,
public = true,
require = true,
static = true,
struct = true,
super = true,
this = true,
throw = true,
throws = true,
["true"] = true,
type = true,
typeof = true,
undefined = true,
union = true,
use = true,
yield = true,
var = true,
}

---@type table<string, Keyword>
E2Lib.KeywordLookup = {}

Expand Down
Loading