Skip to content

Commit

Permalink
Merge pull request #15 from haya14busa/go-closure
Browse files Browse the repository at this point in the history
Support :func-closure
  • Loading branch information
haya14busa authored Sep 19, 2016
2 parents 54c0748 + 7e4844b commit a41844f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 18 deletions.
7 changes: 4 additions & 3 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ type Function struct {
}

type FuncAttr struct {
Range bool
Abort bool
Dict bool
Range bool
Abort bool
Dict bool
Closure bool
}

func (f *Function) Pos() Pos { return f.Func }
Expand Down
6 changes: 4 additions & 2 deletions autoload/vimlparser.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1344,14 +1344,14 @@ function! s:VimLParser.parse_cmd_function()
return
endif

" :function[!] {name}([arguments]) [range] [abort] [dict]
" :function[!] {name}([arguments]) [range] [abort] [dict] [closure]
let node = s:Node(s:NODE_FUNCTION)
let node.pos = self.ea.cmdpos
let node.body = []
let node.ea = self.ea
let node.left = left
let node.rlist = []
let node.attr = {'range': 0, 'abort': 0, 'dict': 0}
let node.attr = {'range': 0, 'abort': 0, 'dict': 0, 'closure': 0}
let node.endfunction = s:NIL
call self.reader.getn(1)
let tokenizer = s:ExprTokenizer.new(self.reader)
Expand Down Expand Up @@ -1415,6 +1415,8 @@ function! s:VimLParser.parse_cmd_function()
let node.attr.abort = s:TRUE
elseif key ==# 'dict'
let node.attr.dict = s:TRUE
elseif key ==# 'closure'
let node.attr.closure = s:TRUE
else
throw s:Err(printf('unexpected token: %s', key), epos)
endif
Expand Down
14 changes: 8 additions & 6 deletions go/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,21 @@ func NewExportNode(n *VimNode) *ExportNode {
}

type ExportFuncAttr struct {
Range bool
Abort bool
Dict bool
Range bool
Abort bool
Dict bool
Closure bool
}

func NewExportFuncAttr(attr *FuncAttr) *ExportFuncAttr {
if attr == nil {
return nil
}
return &ExportFuncAttr{
Range: attr.range_,
Abort: attr.abort,
Dict: attr.dict,
Range: attr.range_,
Abort: attr.abort,
Dict: attr.dict,
Closure: attr.closure,
}
}

Expand Down
7 changes: 4 additions & 3 deletions go/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ type VimNode struct {
}

type FuncAttr struct {
range_ bool
abort bool
dict bool
range_ bool
abort bool
dict bool
closure bool
}

type lhs struct {
Expand Down
4 changes: 3 additions & 1 deletion go/vimlparser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions internal/exporter/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ func NewNode(n *internal.ExportNode) ast.Node {
attr := ast.FuncAttr{}
if n.Attr != nil {
attr = ast.FuncAttr{
Range: n.Attr.Range,
Abort: n.Attr.Abort,
Dict: n.Attr.Dict,
Range: n.Attr.Range,
Abort: n.Attr.Abort,
Dict: n.Attr.Dict,
Closure: n.Attr.Closure,
}
}
return &ast.Function{
Expand Down
2 changes: 2 additions & 0 deletions test/test_funcattr.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(function (F))
(function (F))
5 changes: 5 additions & 0 deletions test/test_funcattr.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function! F() abort
endfunction

function! F() dict abort range closure
endfunction

0 comments on commit a41844f

Please sign in to comment.