Skip to content
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

Add vspec support #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 30 additions & 1 deletion autoload/vimlparser.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ function! vimlparser#test(input, ...) abort
else
let l:neovim = 0
endif
if a:0 > 1
let l:vspec = a:2
else
let l:vspec = 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 p = s:VimLParser.new(l:neovim, l:vspec)
let c = s:Compiler.new()
echo join(c.compile(p.parse(r)), "\n")
catch
Expand Down Expand Up @@ -441,6 +446,12 @@ function! s:VimLParser.__init__(...) abort
let self.neovim = 0
endif

if len(a:000) > 1
let self.vspec = a:000[1]
else
let self.vspec = 0
endif

let self.find_command_cache = {}
endfunction

Expand Down Expand Up @@ -978,6 +989,16 @@ function! s:VimLParser.find_command() abort
endfor
endif

if self.vspec
for x in self.vspec_additional_commands
if x.name ==# name
unlet cmd
let cmd = x
break
endif
endfor
endif

" FIXME: user defined command
if (cmd is# s:NIL || cmd.name ==# 'Print') && name =~# '^[A-Z]'
let name .= self.reader.read_alnum()
Expand Down Expand Up @@ -2157,6 +2178,14 @@ let s:VimLParser.neovim_removed_commands = [
\ {'name': 'tearoff', 'minlen':2, 'flags': 'NEEDARG|EXTRA|TRLBAR|NOTRLCOM|CMDWIN', 'parser': 'parse_cmd_common'},
\ {'name': 'gvim', 'minlen':2, 'flags': 'BANG|FILES|EDITCMD|ARGOPT|TRLBAR|CMDWIN', 'parser': 'parse_cmd_common'}]

let s:VimLParser.vspec_additional_commands = [
\ {'name': 'describe', 'flags': '', 'parser': 'parse_cmd_common'},
\ {'name': 'end', 'flags': '', 'parser': 'parse_cmd_common'},
\ {'name': 'it', 'flags': '', 'parser': 'parse_cmd_common'},
\ {'name': 'before', 'flags': '', 'parser': 'parse_cmd_common'},
\ {'name': 'after', 'flags': '', 'parser': 'parse_cmd_common'},
\ {'name': 'context', 'flags': '', 'parser': 'parse_cmd_common'}]

" To find new builtin_commands, run the below script.
" $ scripts/update_builtin_commands.sh /path/to/vim/src/ex_cmds.h
let s:VimLParser.builtin_commands = [
Expand Down
19 changes: 6 additions & 13 deletions js/vimlfunc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
//!/usr/bin/env nodejs
// usage: nodejs vimlparser.js [--neovim] foo.vim
// usage: nodejs vimlparser.js [--neovim] [--vspec] foo.vim

var fs = require('fs');
var util = require('util');

function main() {
var neovim = false;
var fpath = ''
var args = process.argv;
if (args.length == 4) {
if (args[2] == '--neovim') {
neovim = true;
}
fpath = args[3];
} else if (args.length == 3) {
neovim = false;
fpath = args[2]
}
var options = args.slice(1, -1);
var neovim = options.indexOf('--neovim') > -1;
var vspec = options.indexOf('--vspec') > -1;
var fpath = args[args.length - 1]
var r = new StringReader(viml_readfile(fpath));
var p = new VimLParser(neovim);
var p = new VimLParser(neovim, vspec);
var c = new Compiler();
try {
var lines = c.compile(p.parse(r));
Expand Down
97 changes: 54 additions & 43 deletions js/vimlparser.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions py/vimlfunc.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/usr/bin/env python3
# usage: python3 vimlparser.py [--neovim] foo.vim
# usage: python3 vimlparser.py [--neovim] [--vspec] foo.vim

import sys
import re


def main():
use_neovim = sys.argv[1] == "--neovim"
options = sys.argv[1:-1]

use_neovim = "--neovim" in options
use_vspec = "--vspec" in options

r = StringReader(viml_readfile(sys.argv[-1]))
p = VimLParser(use_neovim)
p = VimLParser(use_neovim, use_vspec)
c = Compiler()
try:
for line in c.compile(p.parse(r)):
Expand Down
20 changes: 17 additions & 3 deletions py/vimlparser.py

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion test/run.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ function! s:run()
let r = s:vimlparser.StringReader.new(src)
if vimfile =~# 'test_neo'
let l:neovim = 1
let l:vspec = 0
elseif vimfile =~# 'test_vspec'
let l:neovim = 0
let l:vspec = 1
else
let l:neovim = 0
let l:vspec = 0
endif
let p = s:vimlparser.VimLParser.new(l:neovim)
let p = s:vimlparser.VimLParser.new(l:neovim, l:vspec)
let c = s:vimlparser.Compiler.new()
try
let out = c.compile(p.parse(r))
Expand Down
8 changes: 5 additions & 3 deletions test/run_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ test_file() {
return
fi

local neovim=""
local syntax=""
if [[ $vimfile =~ "test_neo" ]]; then
neovim="--neovim"
syntax="--neovim"
elif [[ $vimfile =~ "test_vspec" ]]; then
syntax="--vspec"
fi

rm -f ${outfile}

${vimlparser} ${neovim} ${vimfile} &> ${outfile}
${vimlparser} ${syntax} ${vimfile} &> ${outfile}

diffout=$(diff -u ${outfile} ${okfile})
if [ -n "$diffout" ]; then
Expand Down
16 changes: 16 additions & 0 deletions test/test_vspec.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(excmd "describe 'test set name'")
(excmd "before")
(excmd "BeforeCommand")
(excmd "end")
(excmd "after")
(excmd "AfterCommand")
(excmd "end")
(excmd "it 'test name'")
(excmd "Expect 1 == 1")
(excmd "end")
(excmd "context 'context name'")
(excmd "it 'context test name'")
(excmd "Expect 2 == 2")
(excmd "end")
(excmd "end")
(excmd "end")
19 changes: 19 additions & 0 deletions test/test_vspec.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe 'test set name'
before
BeforeCommand
end

after
AfterCommand
end

it 'test name'
Expect 1 == 1
end

context 'context name'
it 'context test name'
Expect 2 == 2
end
end
end