diff --git a/inspect.lua b/inspect.lua index 956c5b1..a9b8c1f 100644 --- a/inspect.lua +++ b/inspect.lua @@ -94,30 +94,10 @@ local function escape(str) "%c", shortControlCharEscapes)) end -local luaKeywords = { - ['and'] = true, - ['break'] = true, - ['do'] = true, - ['else'] = true, - ['elseif'] = true, - ['end'] = true, - ['false'] = true, - ['for'] = true, - ['function'] = true, - ['goto'] = true, - ['if'] = true, - ['in'] = true, - ['local'] = true, - ['nil'] = true, - ['not'] = true, - ['or'] = true, - ['repeat'] = true, - ['return'] = true, - ['then'] = true, - ['true'] = true, - ['until'] = true, - ['while'] = true, -} +local luaKeywords = {} +for k in ([[ and break do else elseif end false for function goto if + in local nil not or repeat return then true until while +]]):gmatch('%w') do luaKeywords[k] = true end local function isIdentifier(str) return type(str) == "string" and diff --git a/inspect.tl b/inspect.tl index 2229a3b..1ae99fe 100644 --- a/inspect.tl +++ b/inspect.tl @@ -94,30 +94,12 @@ local function escape(str: string): string "%c", shortControlCharEscapes)) end -local luaKeywords: {string:boolean} = { - ['and'] = true, - ['break'] = true, - ['do'] = true, - ['else'] = true, - ['elseif'] = true, - ['end'] = true, - ['false'] = true, - ['for'] = true, - ['function'] = true, - ['goto'] = true, - ['if'] = true, - ['in'] = true, - ['local'] = true, - ['nil'] = true, - ['not'] = true, - ['or'] = true, - ['repeat'] = true, - ['return'] = true, - ['then'] = true, - ['true'] = true, - ['until'] = true, - ['while'] = true, -} +local luaKeywords: {string:boolean} = {} +for k in ([[ and break do else elseif end false for function goto if + in local nil not or repeat return then true until while +]]):gmatch('%w') do + luaKeywords[k] = true +end local function isIdentifier(str: any): boolean return str is string