mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
fix(inspect): escape identifiers that are lua keywords (#19898)
A lua keyword is not a valid table identifier
This commit is contained in:
parent
df4709ddf6
commit
e892b7b383
@ -89,8 +89,38 @@ local function escape(str)
|
||||
)
|
||||
end
|
||||
|
||||
-- List of lua keywords
|
||||
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 function isIdentifier(str)
|
||||
return type(str) == 'string' and not not str:match('^[_%a][_%a%d]*$')
|
||||
return type(str) == 'string'
|
||||
-- identifier must start with a letter and underscore, and be followed by letters, numbers, and underscores
|
||||
and not not str:match('^[_%a][_%a%d]*$')
|
||||
-- lua keywords are not valid identifiers
|
||||
and not luaKeywords[str]
|
||||
end
|
||||
|
||||
local flr = math.floor
|
||||
|
Loading…
Reference in New Issue
Block a user