robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #38117 from noib3/fix-lua-lints-in-srcdce8bdd247

master
4.8 KiB178 linesraw
1---@diagnostic disable: no-unknown
2local mpack = vim.mpack
3
4local syntax_file = arg[1]
5local funcs_file = arg[2]
6local options_file = arg[3]
7local auevents_file = arg[4]
8local ex_cmds_file = arg[5]
9local vvars_file = arg[6]
10
11local lld = {}
12local syn_fd = assert(io.open(syntax_file, 'w'))
13lld.line_length = 0
14local function w(s)
15  syn_fd:write(s)
16  if s:find('\n') then
17    lld.line_length = #(s:gsub('.*\n', ''))
18  else
19    lld.line_length = lld.line_length + #s
20  end
21end
22
23local options = loadfile(options_file)()
24local auevents = loadfile(auevents_file)()
25local ex_cmds = loadfile(ex_cmds_file)()
26local vvars = loadfile(vvars_file)()
27
28local function cmd_kw(prev_cmd, cmd)
29  if not prev_cmd then
30    return cmd:sub(1, 1) .. '[' .. cmd:sub(2) .. ']'
31  else
32    local shift = 1
33    while cmd:sub(shift, shift) == prev_cmd:sub(shift, shift) do
34      shift = shift + 1
35    end
36    if cmd:sub(1, shift) == 'def' then
37      shift = shift + 1
38    end
39    if shift >= #cmd then
40      return cmd
41    else
42      return cmd:sub(1, shift) .. '[' .. cmd:sub(shift + 1) .. ']'
43    end
44  end
45end
46
47-- Exclude these from the vimCommand keyword list, they are handled specially
48-- in syntax/vim.vim (vimAugroupKey, vimAutocmd, vimGlobal, vimSubst). #9327
49local function is_special_cased_cmd(cmd)
50  return (
51    cmd == 'augroup'
52    or cmd == 'autocmd'
53    or cmd == 'doautocmd'
54    or cmd == 'doautoall'
55    or cmd == 'global'
56    or cmd == 'substitute'
57  )
58end
59
60local vimcmd_start = 'syn keyword vimCommand contained '
61local vimcmd_end = ' nextgroup=vimBang'
62w(vimcmd_start)
63local prev_cmd = nil
64for _, cmd_desc in ipairs(ex_cmds.cmds) do
65  if lld.line_length > 850 then
66    w(vimcmd_end .. '\n' .. vimcmd_start)
67  end
68  local cmd = cmd_desc.command
69  if cmd:match('%w') and cmd ~= 'z' and not is_special_cased_cmd(cmd) then
70    w(' ' .. cmd_kw(prev_cmd, cmd))
71  end
72  if cmd == 'delete' then
73    -- Add special abbreviations of :delete
74    w(' ' .. cmd_kw('d', 'dl'))
75    w(' ' .. cmd_kw('del', 'dell'))
76    w(' ' .. cmd_kw('dele', 'delel'))
77    w(' ' .. cmd_kw('delet', 'deletl'))
78    w(' ' .. cmd_kw('delete', 'deletel'))
79    w(' ' .. cmd_kw('d', 'dp'))
80    w(' ' .. cmd_kw('de', 'dep'))
81    w(' ' .. cmd_kw('del', 'delp'))
82    w(' ' .. cmd_kw('dele', 'delep'))
83    w(' ' .. cmd_kw('delet', 'deletp'))
84    w(' ' .. cmd_kw('delete', 'deletep'))
85  end
86  prev_cmd = cmd
87end
88w(vimcmd_end .. '\n')
89
90local vimopt_start = 'syn keyword vimOption contained '
91local vimopt_end = ' skipwhite nextgroup=vimSetEqual,vimSetMod'
92w('\n' .. vimopt_start)
93for _, opt_desc in ipairs(options.options) do
94  if not opt_desc.immutable then
95    if lld.line_length > 850 then
96      w(vimopt_end .. '\n' .. vimopt_start)
97    end
98    w(' ' .. opt_desc.full_name)
99    if opt_desc.abbreviation then
100      w(' ' .. opt_desc.abbreviation)
101    end
102    if opt_desc.type == 'boolean' then
103      w(' inv' .. opt_desc.full_name)
104      w(' no' .. opt_desc.full_name)
105      if opt_desc.abbreviation then
106        w(' inv' .. opt_desc.abbreviation)
107        w(' no' .. opt_desc.abbreviation)
108      end
109    end
110  end
111end
112w(vimopt_end .. '\n')
113
114local vimoptvar_start = 'syn keyword vimOptionVarName contained '
115w('\n' .. vimoptvar_start)
116for _, opt_desc in ipairs(options.options) do
117  if not opt_desc.immutable then
118    if lld.line_length > 850 then
119      w('\n' .. vimoptvar_start)
120    end
121    w(' ' .. opt_desc.full_name)
122    if opt_desc.abbreviation then
123      w(' ' .. opt_desc.abbreviation)
124    end
125  end
126end
127
128w('\n\nsyn case ignore')
129local vimau_start = 'syn keyword vimAutoEvent contained '
130local vimau_end = ' skipwhite nextgroup=vimAutoEventSep,@vimAutocmdPattern'
131w('\n\n' .. vimau_start)
132for au, _ in vim.spairs(vim.tbl_extend('error', auevents.events, auevents.aliases)) do
133  -- "User" requires a user defined argument event.
134  -- (Separately specified in vim.vim).
135  if au ~= 'User' and not auevents.nvim_specific[au] then
136    if lld.line_length > 850 then
137      w(vimau_end .. '\n' .. vimau_start)
138    end
139    w(' ' .. au)
140  end
141end
142w(vimau_end .. '\n')
143
144local nvimau_start = 'syn keyword nvimAutoEvent contained '
145local nvimau_end = vimau_end
146w('\n' .. nvimau_start)
147for au, _ in vim.spairs(auevents.nvim_specific) do
148  if lld.line_length > 850 then
149    w(nvimau_end .. '\n' .. nvimau_start)
150  end
151  w(' ' .. au)
152end
153w(nvimau_end .. '\n')
154
155w('\nsyn case match')
156local vimfun_start = 'syn keyword vimFuncName contained '
157w('\n\n' .. vimfun_start)
158local funcs = mpack.decode(io.open(funcs_file, 'rb'):read('*all'))
159for _, name in ipairs(funcs) do
160  if name then
161    if lld.line_length > 850 then
162      w('\n' .. vimfun_start)
163    end
164    w(' ' .. name)
165  end
166end
167
168local vimvvar_start = 'syn keyword vimVimVarName contained '
169w('\n\n' .. vimvvar_start)
170for name, _ in vim.spairs(vvars.vars) do
171  if lld.line_length > 850 then
172    w('\n' .. vimvvar_start)
173  end
174  w(' ' .. name)
175end
176
177w('\n')
178syn_fd:close()