Skip to content

Commit cd27075

Browse files
committed
make VimlParser vital module
1 parent 3dc8498 commit cd27075

File tree

6 files changed

+379
-21
lines changed

6 files changed

+379
-21
lines changed

autoload/vimlparser.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
let s:VimLParser = vital#vimlparser#import('VimlParser')
2+
3+
function! vimlparser#import()
4+
return s:VimLParser.import()
5+
endfunction
6+
7+
" @brief Read input as VimScript and return stringified AST.
8+
" @param input Input filename or string of VimScript.
9+
" @return Stringified AST.
10+
function! vimlparser#test(input, ...)
11+
try
12+
if a:0 > 0
13+
let l:neovim = a:1
14+
else
15+
let l:neovim = 0
16+
endif
17+
let i = type(a:input) == 1 && filereadable(a:input) ? readfile(a:input) : split(a:input, "\n")
18+
let r = s:StringReader.new(i)
19+
let p = s:VimLParser.new(l:neovim)
20+
let c = s:Compiler.new()
21+
echo join(c.compile(p.parse(r)), "\n")
22+
catch
23+
echoerr substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
24+
endtry
25+
endfunction
26+

autoload/vital.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function! vital#of(name) abort
2+
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital', 1)
3+
let file = split(files, "\n")
4+
if empty(file)
5+
throw 'vital: version file not found: ' . a:name
6+
endif
7+
let ver = readfile(file[0], 'b')
8+
if empty(ver)
9+
throw 'vital: invalid version file: ' . a:name
10+
endif
11+
return vital#_{substitute(ver[0], '\W', '', 'g')}#new()
12+
endfunction

autoload/vital/__vimlparser__/VimlParser.vim

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,10 @@
44
"
55
" License: This file is placed in the public domain.
66

7-
function! vimlparser#import()
7+
function! s:import() abort
88
return s:
99
endfunction
1010

11-
" @brief Read input as VimScript and return stringified AST.
12-
" @param input Input filename or string of VimScript.
13-
" @return Stringified AST.
14-
function! vimlparser#test(input, ...)
15-
try
16-
if a:0 > 0
17-
let l:neovim = a:1
18-
else
19-
let l:neovim = 0
20-
endif
21-
let i = type(a:input) == 1 && filereadable(a:input) ? readfile(a:input) : split(a:input, "\n")
22-
let r = s:StringReader.new(i)
23-
let p = s:VimLParser.new(l:neovim)
24-
let c = s:Compiler.new()
25-
echo join(c.compile(p.parse(r)), "\n")
26-
catch
27-
echoerr substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
28-
endtry
29-
endfunction
30-
3111
function! s:numtoname(num)
3212
let sig = printf("function('%s')", a:num)
3313
for k in keys(s:)

autoload/vital/_vimlparser.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let s:_plugin_name = expand('<sfile>:t:r')
2+
3+
function! vital#{s:_plugin_name}#new() abort
4+
return vital#{s:_plugin_name[1:]}#new()
5+
endfunction
6+
7+
function! vital#{s:_plugin_name}#function(funcname) abort
8+
silent! return function(a:funcname)
9+
endfunction

0 commit comments

Comments
 (0)