Improve options for parser engine

This commit is contained in:
Karl Yngve Lervåg 2016-03-20 13:11:40 +01:00
parent 19368d7173
commit ef2dcd0044

View File

@ -30,18 +30,20 @@ function! vimtex#parser#tex(file, ...) " {{{1
return [] return []
endif endif
let l:detailed = a:0 > 0 ? a:1 : 1 return s:parser(a:file, {
let l:recurse = a:0 > 1 ? a:2 : 1 \ 'detailed' : a:0 > 0 ? a:1 : 1,
\ 'input_re' : s:input_line_tex,
return s:parser(a:file, l:detailed, l:recurse, s:input_line_tex, \ 'input_parser' : 's:input_line_parser_tex',
\ 's:input_line_parser_tex') \ })
endfunction endfunction
" }}}1 " }}}1
function! vimtex#parser#aux(file, ...) " {{{1 function! vimtex#parser#aux(file, ...) " {{{1
let l:detailed = a:0 > 0 ? a:1 : 0 return s:parser(a:file, {
return s:parser(a:file, l:detailed, 1, s:input_line_aux, \ 'detailed' : a:0 > 0 ? a:1 : 0,
\ 's:input_line_parser_aux') \ 'input_re' : s:input_line_aux,
\ 'input_parser' : 's:input_line_parser_aux',
\ })
endfunction endfunction
" }}}1 " }}}1
@ -49,25 +51,23 @@ endfunction
" "
" Define the main parser function " Define the main parser function
" "
function! s:parser(file, detailed, recursive, re, re_parser) " {{{1 function! s:parser(file, opts) " {{{1
if !filereadable(a:file) if !filereadable(a:file)
return [] return []
endif endif
let l:parsed = [] let l:parsed = []
let l:lnum = 0 let l:lnum = 0
for l:line in readfile(a:file) for l:line in readfile(a:file)
let l:lnum += 1 let l:lnum += 1
if l:line =~# a:re if l:line =~# a:opts.input_re
let l:file = function(a:re_parser)(l:line, a:file) let l:file = call(a:opts.input_parser, [l:line, a:file])
call extend(l:parsed, s:parser(l:file, a:detailed, a:recursive, call extend(l:parsed, s:parser(l:file, a:opts))
\ a:re, a:re_parser))
continue continue
endif endif
if a:detailed if get(a:opts, 'detailed', 0)
call add(l:parsed, [a:file, l:lnum, l:line]) call add(l:parsed, [a:file, l:lnum, l:line])
else else
call add(l:parsed, l:line) call add(l:parsed, l:line)