robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
dce8bdd247
master
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 ) 15syn_fd : write ( s ) 16if s : find ( '\n' ) then 17lld . line_length =# ( s : gsub ( '.*\n' , '' )) 18else 19lld . line_length =lld . line_length + # s 20end 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 ) 29if not prev_cmd then 30return cmd : sub ( 1 , 1 ) .. '[' .. cmd : sub ( 2 ) .. ']' 31else 32local shift =1 33while cmd : sub ( shift , shift ) == prev_cmd : sub ( shift , shift ) do 34shift =shift + 1 35end 36if cmd : sub ( 1 , shift ) == 'def' then 37shift =shift + 1 38end 39if shift >= # cmd then 40return cmd 41else 42return cmd : sub ( 1 , shift ) .. '[' .. cmd : sub ( shift + 1 ) .. ']' 43end 44end 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 ) 50return ( 51cmd == 'augroup' 52or cmd == 'autocmd' 53or cmd == 'doautocmd' 54or cmd == 'doautoall' 55or cmd == 'global' 56or 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 65if lld . line_length > 850 then 66w ( vimcmd_end .. '\n' .. vimcmd_start ) 67end 68local cmd =cmd_desc . command 69if cmd : match ( '%w' ) and cmd ~= 'z' and not is_special_cased_cmd ( cmd ) then 70w ( ' ' .. cmd_kw ( prev_cmd , cmd )) 71end 72if cmd == 'delete' then 73-- Add special abbreviations of :delete 74w ( ' ' .. cmd_kw ( 'd' , 'dl' )) 75w ( ' ' .. cmd_kw ( 'del' , 'dell' )) 76w ( ' ' .. cmd_kw ( 'dele' , 'delel' )) 77w ( ' ' .. cmd_kw ( 'delet' , 'deletl' )) 78w ( ' ' .. cmd_kw ( 'delete' , 'deletel' )) 79w ( ' ' .. cmd_kw ( 'd' , 'dp' )) 80w ( ' ' .. cmd_kw ( 'de' , 'dep' )) 81w ( ' ' .. cmd_kw ( 'del' , 'delp' )) 82w ( ' ' .. cmd_kw ( 'dele' , 'delep' )) 83w ( ' ' .. cmd_kw ( 'delet' , 'deletp' )) 84w ( ' ' .. cmd_kw ( 'delete' , 'deletep' )) 85end 86prev_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 94if not opt_desc . immutable then 95if lld . line_length > 850 then 96w ( vimopt_end .. '\n' .. vimopt_start ) 97end 98w ( ' ' .. opt_desc . full_name ) 99if opt_desc . abbreviation then 100w ( ' ' .. opt_desc . abbreviation ) 101end 102if opt_desc . type == 'boolean' then 103w ( ' inv' .. opt_desc . full_name ) 104w ( ' no' .. opt_desc . full_name ) 105if opt_desc . abbreviation then 106w ( ' inv' .. opt_desc . abbreviation ) 107w ( ' no' .. opt_desc . abbreviation ) 108end 109end 110end 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 117if not opt_desc . immutable then 118if lld . line_length > 850 then 119w ( '\n' .. vimoptvar_start ) 120end 121w ( ' ' .. opt_desc . full_name ) 122if opt_desc . abbreviation then 123w ( ' ' .. opt_desc . abbreviation ) 124end 125end 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). 135if au ~= 'User' and not auevents . nvim_specific [ au ] then 136if lld . line_length > 850 then 137w ( vimau_end .. '\n' .. vimau_start ) 138end 139w ( ' ' .. au ) 140end 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 148if lld . line_length > 850 then 149w ( nvimau_end .. '\n' .. nvimau_start ) 150end 151w ( ' ' .. 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 160if name then 161if lld . line_length > 850 then 162w ( '\n' .. vimfun_start ) 163end 164w ( ' ' .. name ) 165end 166end 167 168local vimvvar_start ='syn keyword vimVimVarName contained ' 169w ( '\n\n' .. vimvvar_start ) 170for name , _ in vim . spairs ( vvars . vars ) do 171if lld . line_length > 850 then 172w ( '\n' .. vimvvar_start ) 173end 174w ( ' ' .. name ) 175end 176 177w ( '\n' ) 178syn_fd : close ()