Skip to content

Create VimlParser vital-module #74

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make VimlParser vital module
  • Loading branch information
haya14busa committed Nov 24, 2017
commit cd27075b7b4eebc6ec8d3efc28207baf57b4f919
26 changes: 26 additions & 0 deletions autoload/vimlparser.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let s:VimLParser = vital#vimlparser#import('VimlParser')

function! vimlparser#import()
return s:VimLParser.import()
endfunction

" @brief Read input as VimScript and return stringified AST.
" @param input Input filename or string of VimScript.
" @return Stringified AST.
function! vimlparser#test(input, ...)
try
if a:0 > 0
let l:neovim = a:1
else
let l:neovim = 0
endif
let i = type(a:input) == 1 && filereadable(a:input) ? readfile(a:input) : split(a:input, "\n")
let r = s:StringReader.new(i)
let p = s:VimLParser.new(l:neovim)
let c = s:Compiler.new()
echo join(c.compile(p.parse(r)), "\n")
catch
echoerr substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
endtry
endfunction

12 changes: 12 additions & 0 deletions autoload/vital.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function! vital#of(name) abort
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital', 1)
let file = split(files, "\n")
if empty(file)
throw 'vital: version file not found: ' . a:name
endif
let ver = readfile(file[0], 'b')
if empty(ver)
throw 'vital: invalid version file: ' . a:name
endif
return vital#_{substitute(ver[0], '\W', '', 'g')}#new()
endfunction
22 changes: 1 addition & 21 deletions autoload/vital/__vimlparser__/VimlParser.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,10 @@
"
" License: This file is placed in the public domain.

function! vimlparser#import()
function! s:import() abort
return s:
endfunction

" @brief Read input as VimScript and return stringified AST.
" @param input Input filename or string of VimScript.
" @return Stringified AST.
function! vimlparser#test(input, ...)
try
if a:0 > 0
let l:neovim = a:1
else
let l:neovim = 0
endif
let i = type(a:input) == 1 && filereadable(a:input) ? readfile(a:input) : split(a:input, "\n")
let r = s:StringReader.new(i)
let p = s:VimLParser.new(l:neovim)
let c = s:Compiler.new()
echo join(c.compile(p.parse(r)), "\n")
catch
echoerr substitute(v:throwpoint, '\.\.\zs\d\+', '\=s:numtoname(submatch(0))', 'g') . "\n" . v:exception
endtry
endfunction

function! s:numtoname(num)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s:numtoname() is used by vimlparser#test()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done

let sig = printf("function('%s')", a:num)
for k in keys(s:)
Expand Down
9 changes: 9 additions & 0 deletions autoload/vital/_vimlparser.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let s:_plugin_name = expand('<sfile>:t:r')

function! vital#{s:_plugin_name}#new() abort
return vital#{s:_plugin_name[1:]}#new()
endfunction

function! vital#{s:_plugin_name}#function(funcname) abort
silent! return function(a:funcname)
endfunction
Loading