Skip to content

Commit d3427b7

Browse files
committed
refactor: luaKeywords is now created from a string
1 parent 22a22ce commit d3427b7

File tree

2 files changed

+10
-48
lines changed

2 files changed

+10
-48
lines changed

inspect.lua

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,10 @@ local function escape(str)
9494
"%c", shortControlCharEscapes))
9595
end
9696

97-
local luaKeywords = {
98-
['and'] = true,
99-
['break'] = true,
100-
['do'] = true,
101-
['else'] = true,
102-
['elseif'] = true,
103-
['end'] = true,
104-
['false'] = true,
105-
['for'] = true,
106-
['function'] = true,
107-
['goto'] = true,
108-
['if'] = true,
109-
['in'] = true,
110-
['local'] = true,
111-
['nil'] = true,
112-
['not'] = true,
113-
['or'] = true,
114-
['repeat'] = true,
115-
['return'] = true,
116-
['then'] = true,
117-
['true'] = true,
118-
['until'] = true,
119-
['while'] = true,
120-
}
97+
local luaKeywords = {}
98+
for k in ([[ and break do else elseif end false for function goto if
99+
in local nil not or repeat return then true until while
100+
]]):gmatch('%w') do luaKeywords[k] = true end
121101

122102
local function isIdentifier(str)
123103
return type(str) == "string" and

inspect.tl

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,12 @@ local function escape(str: string): string
9494
"%c", shortControlCharEscapes))
9595
end
9696

97-
local luaKeywords: {string:boolean} = {
98-
['and'] = true,
99-
['break'] = true,
100-
['do'] = true,
101-
['else'] = true,
102-
['elseif'] = true,
103-
['end'] = true,
104-
['false'] = true,
105-
['for'] = true,
106-
['function'] = true,
107-
['goto'] = true,
108-
['if'] = true,
109-
['in'] = true,
110-
['local'] = true,
111-
['nil'] = true,
112-
['not'] = true,
113-
['or'] = true,
114-
['repeat'] = true,
115-
['return'] = true,
116-
['then'] = true,
117-
['true'] = true,
118-
['until'] = true,
119-
['while'] = true,
120-
}
97+
local luaKeywords: {string:boolean} = {}
98+
for k in ([[ and break do else elseif end false for function goto if
99+
in local nil not or repeat return then true until while
100+
]]):gmatch('%w') do
101+
luaKeywords[k] = true
102+
end
121103

122104
local function isIdentifier(str: any): boolean
123105
return str is string

0 commit comments

Comments
 (0)