mirror of
https://github.com/TangentFoxy/inspect.lua.git
synced 2025-07-28 02:52:18 +00:00
escape table keys that map to lua keywords (#59)
This commit is contained in:
29
inspect.tl
29
inspect.tl
@@ -87,8 +87,35 @@ 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 function isIdentifier(str: any): boolean
|
||||
return str is string and not not str:match("^[_%a][_%a%d]*$")
|
||||
return str is string
|
||||
and not not str:match("^[_%a][_%a%d]*$")
|
||||
and not luaKeywords[str]
|
||||
end
|
||||
|
||||
local flr = math.floor
|
||||
|
Reference in New Issue
Block a user