@@ -8,9 +8,13 @@ function! vimlparser#import()
8
8
return s:
9
9
endfunction
10
10
11
- function ! vimlparser#test (filename)
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 )
12
15
try
13
- let r = s: StringReader .new (readfile (a: filename ))
16
+ let i = type (a: input ) == 1 && filereadable (a: input ) ? readfile (a: input ) : a: input
17
+ let r = s: StringReader .new (i )
14
18
let p = s: VimLParser .new ()
15
19
let c = s: Compiler .new ()
16
20
echo join (c .compile (p .parse (r )), " \n " )
@@ -3375,21 +3379,21 @@ function! s:StringReader.new(...)
3375
3379
endfunction
3376
3380
3377
3381
function ! s: StringReader .__init__ (lines )
3378
- let self . lines = a: lines
3382
+ let lines = type ( a: lines) == 3 ? a: lines : [ a: lines ]
3379
3383
let self .buf = []
3380
3384
let self .pos = []
3381
3385
let lnum = 0
3382
- while lnum < len (a: lines )
3386
+ while lnum < len (lines )
3383
3387
let col = 0
3384
- for c in split (a: lines [lnum], ' \zs' )
3388
+ for c in split (lines [lnum], ' \zs' )
3385
3389
call add (self .buf , c )
3386
3390
call add (self .pos, [lnum + 1 , col + 1 ])
3387
3391
let col += len (c )
3388
3392
endfor
3389
- while lnum + 1 < len (a: lines ) && a: lines [lnum + 1 ] = ~# ' ^\s*\\'
3393
+ while lnum + 1 < len (lines ) && lines [lnum + 1 ] = ~# ' ^\s*\\'
3390
3394
let skip = 1
3391
3395
let col = 0
3392
- for c in split (a: lines [lnum + 1 ], ' \zs' )
3396
+ for c in split (lines [lnum + 1 ], ' \zs' )
3393
3397
if skip
3394
3398
if c == ' \'
3395
3399
let skip = 0
0 commit comments