diff options
author | Simon Wachter <svvac@users.noreply.github.com> | 2022-08-23 13:02:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-23 13:02:55 +0200 |
commit | e892b7b3830f44bc8ab62e993bf07f7bf03d0029 (patch) | |
tree | 4ce3ae7b82ed8d1223a0953cf1a4df44c607bb98 | |
parent | df4709ddf6d1ed524adae9373ecb762b9db11814 (diff) | |
download | rneovim-e892b7b3830f44bc8ab62e993bf07f7bf03d0029.tar.gz rneovim-e892b7b3830f44bc8ab62e993bf07f7bf03d0029.tar.bz2 rneovim-e892b7b3830f44bc8ab62e993bf07f7bf03d0029.zip |
fix(inspect): escape identifiers that are lua keywords (#19898)
A lua keyword is not a valid table identifier
-rw-r--r-- | runtime/lua/vim/inspect.lua | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/runtime/lua/vim/inspect.lua b/runtime/lua/vim/inspect.lua index 0a53fb203b..c232f69590 100644 --- a/runtime/lua/vim/inspect.lua +++ b/runtime/lua/vim/inspect.lua @@ -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 |