escape table keys that map to lua keywords (#59)

This commit is contained in:
Simon Wachter
2023-01-19 13:16:48 +01:00
committed by GitHub
parent bac593278b
commit b738a52e35
3 changed files with 63 additions and 2 deletions

View File

@@ -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