Skip to content

Commit 5783913

Browse files
committed
Merge remote-tracking branch 'origin/master' into const
2 parents ca72685 + 5965112 commit 5783913

9 files changed

+578
-10
lines changed

autoload/vimlparser.vim

Lines changed: 475 additions & 0 deletions
Large diffs are not rendered by default.

js/jscompiler.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ function s:JavascriptCompiler.compile_op2(node, op)
839839
endfunction
840840

841841

842-
let s:viml_builtin_functions = ['abs', 'acos', 'add', 'and', 'append', 'append', 'argc', 'argidx', 'argv', 'argv', 'asin', 'atan', 'atan2', 'browse', 'browsedir', 'bufexists', 'buflisted', 'bufloaded', 'bufname', 'bufnr', 'bufwinnr', 'byte2line', 'byteidx', 'call', 'ceil', 'changenr', 'char2nr', 'cindent', 'clearmatches', 'col', 'complete', 'complete_add', 'complete_check', 'confirm', 'copy', 'cos', 'cosh', 'count', 'cscope_connection', 'cursor', 'cursor', 'deepcopy', 'delete', 'did_filetype', 'diff_filler', 'diff_hlID', 'empty', 'escape', 'eval', 'eventhandler', 'executable', 'exists', 'extend', 'exp', 'expand', 'feedkeys', 'filereadable', 'filewritable', 'filter', 'finddir', 'findfile', 'float2nr', 'floor', 'fmod', 'fnameescape', 'fnamemodify', 'foldclosed', 'foldclosedend', 'foldlevel', 'foldtext', 'foldtextresult', 'foreground', 'function', 'garbagecollect', 'get', 'get', 'getbufline', 'getbufvar', 'getchar', 'getcharmod', 'getcmdline', 'getcmdpos', 'getcmdtype', 'getcwd', 'getfperm', 'getfsize', 'getfontname', 'getftime', 'getftype', 'getline', 'getline', 'getloclist', 'getmatches', 'getpid', 'getpos', 'getqflist', 'getreg', 'getregtype', 'gettabvar', 'gettabwinvar', 'getwinposx', 'getwinposy', 'getwinvar', 'glob', 'globpath', 'has', 'has_key', 'haslocaldir', 'hasmapto', 'histadd', 'histdel', 'histget', 'histnr', 'hlexists', 'hlID', 'hostname', 'iconv', 'indent', 'index', 'input', 'inputdialog', 'inputlist', 'inputrestore', 'inputsave', 'inputsecret', 'insert', 'invert', 'isdirectory', 'islocked', 'items', 'join', 'keys', 'len', 'libcall', 'libcallnr', 'line', 'line2byte', 'lispindent', 'localtime', 'log', 'log10', 'luaeval', 'map', 'maparg', 'mapcheck', 'match', 'matchadd', 'matcharg', 'matchdelete', 'matchend', 'matchlist', 'matchstr', 'max', 'min', 'mkdir', 'mode', 'mzeval', 'nextnonblank', 'nr2char', 'or', 'pathshorten', 'pow', 'prevnonblank', 'printf', 'pumvisible', 'pyeval', 'py3eval', 'range', 'readfile', 'reltime', 'reltimestr', 'remote_expr', 'remote_foreground', 'remote_peek', 'remote_read', 'remote_send', 'remove', 'remove', 'rename', 'repeat', 'resolve', 'reverse', 'round', 'screencol', 'screenrow', 'search', 'searchdecl', 'searchpair', 'searchpairpos', 'searchpos', 'server2client', 'serverlist', 'setbufvar', 'setcmdpos', 'setline', 'setloclist', 'setmatches', 'setpos', 'setqflist', 'setreg', 'settabvar', 'settabwinvar', 'setwinvar', 'sha256', 'shellescape', 'shiftwidth', 'simplify', 'sin', 'sinh', 'sort', 'soundfold', 'spellbadword', 'spellsuggest', 'split', 'sqrt', 'str2float', 'str2nr', 'strchars', 'strdisplaywidth', 'strftime', 'stridx', 'string', 'strlen', 'strpart', 'strridx', 'strtrans', 'strwidth', 'submatch', 'substitute', 'synID', 'synIDattr', 'synIDtrans', 'synconcealed', 'synstack', 'system', 'tabpagebuflist', 'tabpagenr', 'tabpagewinnr', 'taglist', 'tagfiles', 'tempname', 'tan', 'tanh', 'tolower', 'toupper', 'tr', 'trunc', 'type', 'undofile', 'undotree', 'values', 'virtcol', 'visualmode', 'wildmenumode', 'winbufnr', 'wincol', 'winheight', 'winline', 'winnr', 'winrestcmd', 'winrestview', 'winsaveview', 'winwidth', 'writefile', 'xor']
842+
let s:viml_builtin_functions = map(copy(s:VimLParser.builtin_functions), 'v:val.name')
843843

844844
let s:script_dir = expand('<sfile>:h')
845845
function! s:convert(in, out) abort

js/vimlparser.js

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

py/pycompiler.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@ function s:PythonCompiler.compile_op2(node, op)
822822
return printf('%s %s %s', left, a:op, right)
823823
endfunction
824824

825-
let s:viml_builtin_functions = ['abs', 'acos', 'add', 'and', 'append', 'append', 'argc', 'argidx', 'argv', 'argv', 'asin', 'atan', 'atan2', 'browse', 'browsedir', 'bufexists', 'buflisted', 'bufloaded', 'bufname', 'bufnr', 'bufwinnr', 'byte2line', 'byteidx', 'call', 'ceil', 'changenr', 'char2nr', 'cindent', 'clearmatches', 'col', 'complete', 'complete_add', 'complete_check', 'confirm', 'copy', 'cos', 'cosh', 'count', 'cscope_connection', 'cursor', 'cursor', 'deepcopy', 'delete', 'did_filetype', 'diff_filler', 'diff_hlID', 'empty', 'escape', 'eval', 'eventhandler', 'executable', 'exists', 'extend', 'exp', 'expand', 'feedkeys', 'filereadable', 'filewritable', 'filter', 'finddir', 'findfile', 'float2nr', 'floor', 'fmod', 'fnameescape', 'fnamemodify', 'foldclosed', 'foldclosedend', 'foldlevel', 'foldtext', 'foldtextresult', 'foreground', 'function', 'garbagecollect', 'get', 'get', 'getbufline', 'getbufvar', 'getchar', 'getcharmod', 'getcmdline', 'getcmdpos', 'getcmdtype', 'getcwd', 'getfperm', 'getfsize', 'getfontname', 'getftime', 'getftype', 'getline', 'getline', 'getloclist', 'getmatches', 'getpid', 'getpos', 'getqflist', 'getreg', 'getregtype', 'gettabvar', 'gettabwinvar', 'getwinposx', 'getwinposy', 'getwinvar', 'glob', 'globpath', 'has', 'has_key', 'haslocaldir', 'hasmapto', 'histadd', 'histdel', 'histget', 'histnr', 'hlexists', 'hlID', 'hostname', 'iconv', 'indent', 'index', 'input', 'inputdialog', 'inputlist', 'inputrestore', 'inputsave', 'inputsecret', 'insert', 'invert', 'isdirectory', 'islocked', 'items', 'join', 'keys', 'len', 'libcall', 'libcallnr', 'line', 'line2byte', 'lispindent', 'localtime', 'log', 'log10', 'luaeval', 'map', 'maparg', 'mapcheck', 'match', 'matchadd', 'matcharg', 'matchdelete', 'matchend', 'matchlist', 'matchstr', 'max', 'min', 'mkdir', 'mode', 'mzeval', 'nextnonblank', 'nr2char', 'or', 'pathshorten', 'pow', 'prevnonblank', 'printf', 'pumvisible', 'pyeval', 'py3eval', 'range', 'readfile', 'reltime', 'reltimestr', 'remote_expr', 'remote_foreground', 'remote_peek', 'remote_read', 'remote_send', 'remove', 'remove', 'rename', 'repeat', 'resolve', 'reverse', 'round', 'screencol', 'screenrow', 'search', 'searchdecl', 'searchpair', 'searchpairpos', 'searchpos', 'server2client', 'serverlist', 'setbufvar', 'setcmdpos', 'setline', 'setloclist', 'setmatches', 'setpos', 'setqflist', 'setreg', 'settabvar', 'settabwinvar', 'setwinvar', 'sha256', 'shellescape', 'shiftwidth', 'simplify', 'sin', 'sinh', 'sort', 'soundfold', 'spellbadword', 'spellsuggest', 'split', 'sqrt', 'str2float', 'str2nr', 'strchars', 'strdisplaywidth', 'strftime', 'stridx', 'string', 'strlen', 'strpart', 'strridx', 'strtrans', 'strwidth', 'submatch', 'substitute', 'synID', 'synIDattr', 'synIDtrans', 'synconcealed', 'synstack', 'system', 'tabpagebuflist', 'tabpagenr', 'tabpagewinnr', 'taglist', 'tagfiles', 'tempname', 'tan', 'tanh', 'tolower', 'toupper', 'tr', 'trunc', 'type', 'undofile', 'undotree', 'values', 'virtcol', 'visualmode', 'wildmenumode', 'winbufnr', 'wincol', 'winheight', 'winline', 'winnr', 'winrestcmd', 'winrestview', 'winsaveview', 'winwidth', 'writefile', 'xor']
825+
826+
let s:viml_builtin_functions = map(copy(s:VimLParser.builtin_functions), 'v:val.name')
826827

827828
let s:script_dir = expand('<sfile>:h')
828829
function! s:convert(in, out)

py/vimlparser.py

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

scripts/update_builtin_commands.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ fi
88
vim -u NONE -i NONE -n -N -e -s \
99
--cmd "let &rtp .= ',' . getcwd()" \
1010
--cmd "source scripts/update_builtin_commands.vim" \
11-
--cmd "call VimLParserNewCmds('$1')" \
12-
--cmd "qall!"
11+
--cmd "call VimLParserNewCmds(expand('$1'))" \
12+
--cmd "qall!" 2>&1
1313
echo

scripts/update_builtin_commands.vim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function! s:Trie.remove(s) abort
7272
return v:true
7373
endfunction
7474

75-
function! s:gen(ex_cmds_h) abort
75+
function! s:parse(ex_cmds_h) abort
7676
let lines = readfile(a:ex_cmds_h)
7777

7878
" { 'name': string, 'flags': string, 'minlen': int, 'parser': string}
@@ -100,14 +100,14 @@ function! s:gen(ex_cmds_h) abort
100100
return cmds
101101
endfunction
102102

103-
function! s:gen_new_builtin(existing, latest) abort
103+
function! s:diff(existing, latest) abort
104104
let existing_names = {}
105105
for cmd in a:existing
106106
let existing_names[cmd.name] = v:true
107107
endfor
108108
let newcmds = []
109109
for cmd in filter(copy(a:latest), {_, c -> !has_key(existing_names, c.name)})
110-
let newcmds = add(newcmds, extend(cmd, {'parser': 'parse_cmd_common'}))
110+
let newcmds = add(newcmds, cmd)
111111
endfor
112112
return newcmds
113113
endfunction
@@ -125,8 +125,9 @@ endfunction
125125
" ex_cmds_h: path to vim/src/ex_cmds.h
126126
function! VimLParserNewCmds(ex_cmds_h) abort
127127
let vimlparser = vimlparser#import()
128-
let latest = s:gen(a:ex_cmds_h)
129-
let new_cmds = s:gen_new_builtin(vimlparser#import().VimLParser.builtin_commands, latest)
128+
let latest = s:parse(a:ex_cmds_h)
129+
let new_cmds = s:diff(vimlparser#import().VimLParser.builtin_commands, latest)
130+
call map(new_cmds, {_,cmd -> extend(cmd, {'parser': 'parse_cmd_common'})})
130131
let generated_text = s:gen_viml(new_cmds)
131132
if generated_text ==# ''
132133
verbose echo 's:VimLParser.builtin_commands in autoload/vimlparser.vim is up-to-date.'
@@ -135,4 +136,3 @@ function! VimLParserNewCmds(ex_cmds_h) abort
135136
verbose echo generated_text
136137
endif
137138
endfunction
138-
" call s:vimlparser_new_cmds('/home/haya14busa/src/github.com/vim/vim/src/ex_cmds.h')

scripts/update_builtin_functions.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
if [ $# -ne 1 ]; then
4+
echo "USAGE: ./scripts/update_builtin_functions.sh /path/to/vim/src/evalfunc.c"
5+
exit 1
6+
fi
7+
8+
vim -u NONE -i NONE -n -N -e -s \
9+
--cmd "let &rtp .= ',' . getcwd()" \
10+
--cmd "source scripts/update_builtin_functions.vim" \
11+
--cmd "call VimLParserNewFuncs(expand('$1'))" \
12+
--cmd "qall!" 2>&1
13+
echo

scripts/update_builtin_functions.vim

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
" create builtin function table
2+
3+
" TODO more loose pattern?
4+
function! s:get_parse_lines(lines) abort
5+
let from = index(a:lines, '} functions[] =')
6+
if from ==# -1
7+
throw 'cannot parse functions'
8+
endif
9+
" find next '{'
10+
let from = index(a:lines, '{', from + 1)
11+
let to = index(a:lines, '};', from + 1)
12+
return map(range(from + 1, to - 1), {_,i -> a:lines[i] })
13+
endfunction
14+
15+
function! s:parse(evalfunc_c) abort
16+
let lines = readfile(a:evalfunc_c)
17+
18+
" { 'name': string, 'min_argc': integer, 'max_argc': integer }
19+
let funcs = []
20+
21+
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+
if !empty(m)
24+
let [name, min_argc, max_argc] = m[1:3]
25+
call add(funcs, {
26+
\ 'name': name,
27+
\ 'min_argc': min_argc + 0,
28+
\ 'max_argc': max_argc + 0,
29+
\})
30+
endif
31+
endfor
32+
return funcs
33+
endfunction
34+
35+
function! s:diff(existing, latest) abort
36+
let existing_names = {}
37+
for func in a:existing
38+
let existing_names[func.name] = v:true
39+
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
45+
endfunction
46+
47+
function! s:gen_viml(new_funcs) abort
48+
let lines = []
49+
for f in a:new_funcs
50+
" output items in this key order
51+
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)))
54+
endfor
55+
return join(lines, "\n")
56+
endfunction
57+
58+
" -- main
59+
60+
" evalfunc_c: path to vim/src/evalfunc.c
61+
function! VimLParserNewFuncs(evalfunc_c) abort
62+
try
63+
let vimlparser = vimlparser#import()
64+
let latest = s:parse(a:evalfunc_c)
65+
let new_funcs = s:diff(vimlparser#import().VimLParser.builtin_functions, latest)
66+
let generated_text = s:gen_viml(new_funcs)
67+
if generated_text ==# ''
68+
verbose echo 's:VimLParser.builtin_functions in autoload/vimlparser.vim is up-to-date.'
69+
else
70+
verbose echo "Append following lines to s:VimLParser.builtin_functions in autoload/vimlparser.vim\n"
71+
verbose echo generated_text
72+
endif
73+
catch
74+
" :echoerr doesn't show output
75+
verbose echo '[ERROR]' v:exception 'at' v:throwpoint
76+
endtry
77+
endfunction

0 commit comments

Comments
 (0)