22
33" TODO more loose pattern?
44function ! s: get_parse_lines (lines ) abort
5- let from = index (a: lines , ' } functions[] =' )
5+ let from = match (a: lines , ' \vstatic\s+funcentry_T\s+global_functions\[]\s+\ =' )
66 if from == # -1
77 throw ' cannot parse functions'
88 endif
99 " find next '{'
1010 let from = index (a: lines , ' {' , from + 1 )
1111 let to = index (a: lines , ' };' , from + 1 )
12- return map ( range ( from + 1 , to - 1 ), {_, i - > a: lines [ i ] })
12+ return a: lines [ from + 1 : to - 1 ]
1313endfunction
1414
1515function ! s: parse (evalfunc_c) abort
@@ -18,14 +18,16 @@ function! s:parse(evalfunc_c) abort
1818 " { 'name': string, 'min_argc': integer, 'max_argc': integer }
1919 let funcs = []
2020
21+ " TODO: f_retfunc, f_func (currently vim9script is unstable)
2122 for line in s: get_parse_lines (lines )
22- let m = matchlist (line , ' \v\{\s*"(\w+)"\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*\w+\s*\} ' )
23+ let m = matchlist (line , ' \v\{\s*"(\w+)"\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*( \w+) ' )
2324 if ! empty (m )
24- let [name, min_argc, max_argc] = m [1 :3 ]
25+ let [name, min_argc, max_argc, argtype ] = m [1 :4 ]
2526 call add (funcs, {
2627 \ ' name' : name,
2728 \ ' min_argc' : min_argc + 0 ,
2829 \ ' max_argc' : max_argc + 0 ,
30+ \ ' argtype' : argtype,
2931 \} )
3032 endif
3133 endfor
@@ -37,20 +39,16 @@ function! s:diff(existing, latest) abort
3739 for func in a: existing
3840 let existing_names[func .name] = v: true
3941 endfor
40- let new_funcs = []
41- for func in filter (copy (a: latest ), {_, f - > ! has_key (existing_names, f .name)})
42- let new_funcs = add (new_funcs, func )
43- endfor
44- return new_funcs
42+ return filter (copy (a: latest ), {_, f - > ! has_key (existing_names, f .name)})
4543endfunction
4644
4745function ! s: gen_viml (new_funcs) abort
4846 let lines = []
4947 for f in a: new_funcs
5048 " output items in this key order
5149 let lines = add (lines ,
52- \ printf (' \ {'' name'' : %s, '' min_argc'' : %s, '' max_argc'' : %s},' ,
53- \ string (f .name), string (f .min_argc), string (f .max_argc)))
50+ \ printf (' \ {'' name'' : %s, '' min_argc'' : %s, '' max_argc'' : %s, '' argtype '' : %s },' ,
51+ \ string (f .name), string (f .min_argc), string (f .max_argc), string ( f .argtype) ))
5452 endfor
5553 return join (lines , " \n " )
5654endfunction
0 commit comments