Skip to content

Commit

Permalink
Add reserved words (#3201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Denneisk authored Dec 10, 2024
1 parent 6a9bc3c commit 254aa69
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
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 @@ function Tokenizer:Next()
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
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 @@ -653,6 +653,59 @@ local Keyword = {

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

0 comments on commit 254aa69

Please sign in to comment.