From d3427b7215aa9ab068fa453d1ef06c2c5b2f6f15 Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 7 Nov 2025 10:25:14 +0100 Subject: [PATCH] refactor: luaKeywords is now created from a string --- inspect.lua | 28 ++++------------------------ inspect.tl | 30 ++++++------------------------ 2 files changed, 10 insertions(+), 48 deletions(-) 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