Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move s:viml_builtin_functions to s:VimLParser.builtin_functions #125

Merged
merged 5 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
475 changes: 475 additions & 0 deletions autoload/vimlparser.vim

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/jscompiler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ function s:JavascriptCompiler.compile_op2(node, op)
endfunction


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']
let s:viml_builtin_functions = map(copy(s:VimLParser.builtin_functions), 'v:val.name')

let s:script_dir = expand('<sfile>:h')
function! s:convert(in, out) abort
Expand Down
1 change: 1 addition & 0 deletions js/vimlparser.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion py/pycompiler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ function s:PythonCompiler.compile_op2(node, op)
return printf('%s %s %s', left, a:op, right)
endfunction

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']

let s:viml_builtin_functions = map(copy(s:VimLParser.builtin_functions), 'v:val.name')

let s:script_dir = expand('<sfile>:h')
function! s:convert(in, out)
Expand Down
1 change: 1 addition & 0 deletions py/vimlparser.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions scripts/update_builtin_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ fi
vim -u NONE -i NONE -n -N -e -s \
--cmd "let &rtp .= ',' . getcwd()" \
--cmd "source scripts/update_builtin_commands.vim" \
--cmd "call VimLParserNewCmds('$1')" \
--cmd "qall!"
--cmd "call VimLParserNewCmds(expand('$1'))" \
--cmd "qall!" 2>&1
echo
12 changes: 6 additions & 6 deletions scripts/update_builtin_commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function! s:Trie.remove(s) abort
return v:true
endfunction

function! s:gen(ex_cmds_h) abort
function! s:parse(ex_cmds_h) abort
let lines = readfile(a:ex_cmds_h)

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

function! s:gen_new_builtin(existing, latest) abort
function! s:diff(existing, latest) abort
let existing_names = {}
for cmd in a:existing
let existing_names[cmd.name] = v:true
endfor
let newcmds = []
for cmd in filter(copy(a:latest), {_, c -> !has_key(existing_names, c.name)})
let newcmds = add(newcmds, extend(cmd, {'parser': 'parse_cmd_common'}))
let newcmds = add(newcmds, cmd)
endfor
return newcmds
endfunction
Expand All @@ -125,8 +125,9 @@ endfunction
" ex_cmds_h: path to vim/src/ex_cmds.h
function! VimLParserNewCmds(ex_cmds_h) abort
let vimlparser = vimlparser#import()
let latest = s:gen(a:ex_cmds_h)
let new_cmds = s:gen_new_builtin(vimlparser#import().VimLParser.builtin_commands, latest)
let latest = s:parse(a:ex_cmds_h)
let new_cmds = s:diff(vimlparser#import().VimLParser.builtin_commands, latest)
call map(new_cmds, {_,cmd -> extend(cmd, {'parser': 'parse_cmd_common'})})
let generated_text = s:gen_viml(new_cmds)
if generated_text ==# ''
verbose echo 's:VimLParser.builtin_commands in autoload/vimlparser.vim is up-to-date.'
Expand All @@ -135,4 +136,3 @@ function! VimLParserNewCmds(ex_cmds_h) abort
verbose echo generated_text
endif
endfunction
" call s:vimlparser_new_cmds('/home/haya14busa/src/github.com/vim/vim/src/ex_cmds.h')
13 changes: 13 additions & 0 deletions scripts/update_builtin_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [ $# -ne 1 ]; then
echo "USAGE: ./scripts/update_builtin_functions.sh /path/to/vim/src/evalfunc.c"
exit 1
fi

vim -u NONE -i NONE -n -N -e -s \
--cmd "let &rtp .= ',' . getcwd()" \
--cmd "source scripts/update_builtin_functions.vim" \
--cmd "call VimLParserNewFuncs(expand('$1'))" \
--cmd "qall!" 2>&1
echo
77 changes: 77 additions & 0 deletions scripts/update_builtin_functions.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
" create builtin function table

" TODO more loose pattern?
function! s:get_parse_lines(lines) abort
let from = index(a:lines, '} functions[] =')
if from ==# -1
throw 'cannot parse functions'
endif
" find next '{'
let from = index(a:lines, '{', from + 1)
let to = index(a:lines, '};', from + 1)
return map(range(from + 1, to - 1), {_,i -> a:lines[i] })
endfunction

function! s:parse(evalfunc_c) abort
let lines = readfile(a:evalfunc_c)

" { 'name': string, 'min_argc': integer, 'max_argc': integer }
let funcs = []

for line in s:get_parse_lines(lines)
let m = matchlist(line, '\v\{\s*"(\w+)"\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*\w+\s*\}')
if !empty(m)
let [name, min_argc, max_argc] = m[1:3]
call add(funcs, {
\ 'name': name,
\ 'min_argc': min_argc + 0,
\ 'max_argc': max_argc + 0,
\})
endif
endfor
return funcs
endfunction

function! s:diff(existing, latest) abort
let existing_names = {}
for func in a:existing
let existing_names[func.name] = v:true
endfor
let new_funcs = []
for func in filter(copy(a:latest), {_, f -> !has_key(existing_names, f.name)})
let new_funcs = add(new_funcs, func)
endfor
return new_funcs
endfunction

function! s:gen_viml(new_funcs) abort
let lines = []
for f in a:new_funcs
" output items in this key order
let lines = add(lines,
\ printf(' \ {''name'': %s, ''min_argc'': %s, ''max_argc'': %s},',
\ string(f.name), string(f.min_argc), string(f.max_argc)))
endfor
return join(lines, "\n")
endfunction

" -- main

" evalfunc_c: path to vim/src/evalfunc.c
function! VimLParserNewFuncs(evalfunc_c) abort
try
let vimlparser = vimlparser#import()
let latest = s:parse(a:evalfunc_c)
let new_funcs = s:diff(vimlparser#import().VimLParser.builtin_functions, latest)
let generated_text = s:gen_viml(new_funcs)
if generated_text ==# ''
verbose echo 's:VimLParser.builtin_functions in autoload/vimlparser.vim is up-to-date.'
else
verbose echo "Append following lines to s:VimLParser.builtin_functions in autoload/vimlparser.vim\n"
verbose echo generated_text
endif
catch
" :echoerr doesn't show output
verbose echo '[ERROR]' v:exception 'at' v:throwpoint
endtry
endfunction