aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-11-24 10:40:56 +0000
committerLewis Russell <me@lewisr.dev>2024-11-25 17:34:02 +0000
commit8d55cc218cfed54136677398ca76c45987b15f29 (patch)
tree1e827a7725571d0423b6ba9887534120ef398fa6 /src/nvim/generators
parent99e7323aa386865035ad79483a7da0c5b106464f (diff)
downloadrneovim-8d55cc218cfed54136677398ca76c45987b15f29.tar.gz
rneovim-8d55cc218cfed54136677398ca76c45987b15f29.tar.bz2
rneovim-8d55cc218cfed54136677398ca76c45987b15f29.zip
feat(keysets): teach Union and LuaRefOf
Diffstat (limited to 'src/nvim/generators')
-rw-r--r--src/nvim/generators/c_grammar.lua36
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua10
2 files changed, 40 insertions, 6 deletions
diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua
index ed6e30ea10..a0a9c86789 100644
--- a/src/nvim/generators/c_grammar.lua
+++ b/src/nvim/generators/c_grammar.lua
@@ -3,7 +3,7 @@ local lpeg = vim.lpeg
-- lpeg grammar for building api metadata from a set of header files. It
-- ignores comments and preprocessor commands and parses a very small subset
-- of C prototypes with a limited set of types
-local P, R, S = lpeg.P, lpeg.R, lpeg.S
+local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V
local C, Ct, Cc, Cg = lpeg.C, lpeg.Ct, lpeg.Cc, lpeg.Cg
--- @param pat vim.lpeg.Pattern
@@ -35,9 +35,39 @@ local cdoc_comment = P('///') * opt(Ct(Cg(rep(space) * rep(not_nl), 'comment')))
local c_preproc = P('#') * rep(not_nl)
local dllexport = P('DLLEXPORT') * rep1(ws)
-local typed_container = ((P('ArrayOf(') + P('DictOf(') + P('Dict(')) * rep1(any - P(')')) * P(')'))
+--- @param x vim.lpeg.Pattern
+local function comma1(x)
+ return x * rep(fill * P(',') * fill * x)
+end
+
+-- Define the grammar
+
+local basic_id = letter * rep(alpha)
+
+local str = P('"') * rep(any - P('"')) * P('"')
+
+--- @param x vim.lpeg.Pattern
+local function paren(x)
+ return P('(') * fill * x * fill * P(')')
+end
+
+-- stylua: ignore start
+local typed_container = P({
+ 'S',
+ ID = V('S') + basic_id,
+ S = (
+ (P('Union') * paren(comma1(V('ID'))))
+ + (P('ArrayOf') * paren(basic_id * opt(P(',') * fill * rep1(num))))
+ + (P('DictOf') * paren(basic_id))
+ + (P('LuaRefOf') * paren(
+ paren(comma1((V('ID') + str) * rep1(ws) * opt(P('*')) * basic_id))
+ * opt(P(',') * fill * opt(P('*')) * V('ID'))
+ ))
+ + (P('Dict') * paren(basic_id))),
+})
+-- stylua: ignore end
-local c_id = (typed_container + (letter * rep(alpha)))
+local c_id = typed_container + basic_id
local c_void = P('void')
local c_param_type = (
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index a78f746fee..402382acd2 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -347,12 +347,16 @@ for _, k in ipairs(keysets) do
local function typename(type)
if type == 'HLGroupID' then
return 'kObjectTypeInteger'
+ elseif not type or vim.startswith(type, 'Union') then
+ return 'kObjectTypeNil'
+ elseif vim.startswith(type, 'LuaRefOf') then
+ return 'kObjectTypeLuaRef'
elseif type == 'StringArray' then
return 'kUnpackTypeStringArray'
- elseif type ~= nil then
- return 'kObjectType' .. type
+ elseif vim.startswith(type, 'ArrayOf') then
+ return 'kObjectTypeArray'
else
- return 'kObjectTypeNil'
+ return 'kObjectType' .. type
end
end