Skip to content

Commit 58c7675

Browse files
authored
Merge pull request #62 from vim-jp/scriptish
scriptish
2 parents c9cba9f + d49696d commit 58c7675

File tree

7 files changed

+75
-18
lines changed

7 files changed

+75
-18
lines changed

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
VIM_COMPILER:=vim -N --cmd 'set rtp+=.' -c q -u
21
COMPILED_FILES:=js/vimlparser.js py/vimlparser.py
32

43
all: $(COMPILED_FILES)
54

65
js/vimlparser.js: autoload/vimlparser.vim js/jscompiler.vim js/vimlfunc.js
7-
$(VIM_COMPILER) js/jscompiler.vim
6+
scripts/jscompile.sh $< $@
87

98
py/vimlparser.py: autoload/vimlparser.vim py/pycompiler.vim py/vimlfunc.py
10-
$(VIM_COMPILER) py/pycompiler.vim
9+
scripts/pycompile.sh $< $@
1110

1211
clean_compiled:
1312
$(RM) $(COMPILED_FILES)

js/jscompiler.vim

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,12 @@ endfunction
841841

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

844-
function! s:test()
845-
let vimfile = 'autoload/vimlparser.vim'
846-
let jsfile = 'js/vimlparser.js'
847-
let vimlfunc = 'js/vimlfunc.js'
844+
let s:script_dir = expand('<sfile>:h')
845+
function! s:convert(in, out) abort
846+
let vimlfunc = fnamemodify(s:script_dir . '/vimlfunc.js', ':p')
848847
let head = readfile(vimlfunc)
849848
try
850-
let r = s:StringReader.new(readfile(vimfile))
849+
let r = s:StringReader.new(readfile(a:in))
851850
let p = s:VimLParser.new()
852851
let c = s:JavascriptCompiler.new()
853852
let lines = c.compile(p.parse(r))
@@ -864,9 +863,9 @@ function! s:test()
864863
\ ' };',
865864
\ '}',
866865
\ ]
867-
call writefile(head + lines + tail, jsfile)
866+
call writefile(head + lines + tail, a:out)
868867
catch
869-
echoerr substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
868+
throw substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
870869
endtry
871870
endfunction
872871

@@ -884,4 +883,30 @@ function! s:numtoname(num)
884883
return a:num
885884
endfunction
886885

887-
call s:test()
886+
function! s:parse_args() abort
887+
let v = [
888+
\ fnamemodify(s:script_dir . '/../autoload/vimlparser.vim', ':p'),
889+
\ fnamemodify(s:script_dir . '/vimlparser.js', ':p')
890+
\]
891+
let args = argv()[1:]
892+
%argdel
893+
if len(args) != 0
894+
if len(args) != 2
895+
throw 'invalid argument: ' . string(args)
896+
endif
897+
let v = args
898+
endif
899+
return v
900+
endfunction:
901+
902+
function! s:main() abort
903+
try
904+
let args = s:parse_args()
905+
call s:convert(args[0], args[1])
906+
catch
907+
call writefile([v:exception], has('win32') ? 'conout$' : '/dev/stderr')
908+
cquit
909+
endtry
910+
endfunction
911+
912+
call s:main()

py/pycompiler.vim

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,12 @@ endfunction
821821

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

824-
function! s:test()
825-
let vimfile = 'autoload/vimlparser.vim'
826-
let pyfile = 'py/vimlparser.py'
827-
let vimlfunc = 'py/vimlfunc.py'
824+
let s:script_dir = expand('<sfile>:h')
825+
function! s:convert(in, out)
826+
let vimlfunc = fnamemodify(s:script_dir . '/vimlfunc.py', ':p')
828827
let head = readfile(vimlfunc)
829828
try
830-
let r = s:StringReader.new(readfile(vimfile))
829+
let r = s:StringReader.new(readfile(a:in))
831830
let p = s:VimLParser.new()
832831
let c = s:PythonCompiler.new()
833832
let lines = c.compile(p.parse(r))
@@ -836,7 +835,7 @@ function! s:test()
836835
\ 'if __name__ == ''__main__'':',
837836
\ ' main()',
838837
\ ]
839-
call writefile(head + lines + tail, pyfile)
838+
call writefile(head + lines + tail, a:out)
840839
catch
841840
echoerr substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
842841
endtry
@@ -856,4 +855,30 @@ function! s:numtoname(num)
856855
return a:num
857856
endfunction
858857

859-
call s:test()
858+
function! s:parse_args() abort
859+
let v = [
860+
\ fnamemodify(s:script_dir . '/../autoload/vimlparser.vim', ':p'),
861+
\ fnamemodify(s:script_dir . '/vimlparser.py', ':p')
862+
\]
863+
let args = argv()[1:]
864+
%argdel
865+
if len(args) != 0
866+
if len(args) != 2
867+
throw 'invalid argument: ' . string(args)
868+
endif
869+
let v = args
870+
endif
871+
return v
872+
endfunction:
873+
874+
function! s:main() abort
875+
try
876+
let args = s:parse_args()
877+
call s:convert(args[0], args[1])
878+
catch
879+
call writefile([v:exception], has('win32') ? 'conout$' : '/dev/stderr')
880+
cquit
881+
endtry
882+
endfunction
883+
884+
call s:main()

scripts/jscompile.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
vim -E -s -N --cmd "set rtp+=." -c "exe 'so' argv()[0]" -c q -- js/jscompiler.vim %*

scripts/jscompile.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
vim -E -s -N --cmd 'set rtp+=.' -c 'exe "so" argv()[0]' -c q -- js/jscompiler.vim $*

scripts/pycompile.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
vim -E -s -N --cmd "set rtp+=." -c "exe 'so' argv()[0]" -c q -- py/pycompiler.vim %*

scripts/pycompile.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
vim -E -s -N --cmd 'set rtp+=.' -c 'exe "so" argv()[0]' -c q -- py/pycompiler.vim $*

0 commit comments

Comments
 (0)