From be56b0474dd5c470dd831c52930cd098d1a6f763 Mon Sep 17 00:00:00 2001 From: Eugene Chernyshov Date: Sun, 20 Dec 2020 20:59:34 +0200 Subject: [PATCH 1/5] added multiline type definitions --- goblin.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/goblin.go b/goblin.go index 0ef10ef..cdaf220 100644 --- a/goblin.go +++ b/goblin.go @@ -610,13 +610,12 @@ func DumpGenDecl(decl *ast.GenDecl, fset *token.FileSet) map[string]interface{} results := make([]interface{}, len(decl.Specs)) switch decl.Tok { case token.TYPE: - if len(decl.Specs) != 1 { - pos := fset.PositionFor(decl.Pos(), true) - Perish(pos, "syntax_error", "unexpected number of tokens ("+string(len(decl.Specs))+") in type alias (expected 1)") + if len(decl.Specs) == 1 { + return DumpTypeAlias(decl.Specs[0].(*ast.TypeSpec), fset) + } + for i, v := range decl.Specs { + results[i] = DumpTypeAlias(v.(*ast.TypeSpec), fset) } - // EARLY RETURN - return DumpTypeAlias(decl.Specs[0].(*ast.TypeSpec), fset) - case token.IMPORT: prettyToken = "import" for i, v := range decl.Specs { From 18c4792c485514f0c4d08f914437a5a3e87f684b Mon Sep 17 00:00:00 2001 From: Eugene Chernyshov Date: Sun, 20 Dec 2020 21:00:01 +0200 Subject: [PATCH 2/5] added ellipsis for function parameters --- goblin.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/goblin.go b/goblin.go index cdaf220..469338c 100644 --- a/goblin.go +++ b/goblin.go @@ -157,6 +157,14 @@ func AttemptExprAsType(e ast.Expr, fset *token.FileSet) map[string]interface{} { } } + if n, ok := e.(*ast.Ellipsis); ok { + return map[string]interface{}{ + "kind": "type", + "type": "ellipsis", + "element": DumpExprAsType(n.Elt, fset), + "position": DumpPosition(fset.Position(e.Pos())), + } + } if n, ok := e.(*ast.InterfaceType); ok { return map[string]interface{}{ "kind": "type", From 1f5a72af8795130f9a0f98385517f58cb4cfdc02 Mon Sep 17 00:00:00 2001 From: Eugene Chernyshov Date: Sun, 20 Dec 2020 21:55:19 +0200 Subject: [PATCH 3/5] type switch support --- goblin.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/goblin.go b/goblin.go index 469338c..66247ea 100644 --- a/goblin.go +++ b/goblin.go @@ -159,10 +159,10 @@ func AttemptExprAsType(e ast.Expr, fset *token.FileSet) map[string]interface{} { if n, ok := e.(*ast.Ellipsis); ok { return map[string]interface{}{ - "kind": "type", - "type": "ellipsis", - "element": DumpExprAsType(n.Elt, fset), - "position": DumpPosition(fset.Position(e.Pos())), + "kind": "type", + "type": "ellipsis", + "element": DumpExprAsType(n.Elt, fset), + "position": DumpPosition(fset.Position(e.Pos())), } } if n, ok := e.(*ast.InterfaceType); ok { @@ -379,11 +379,15 @@ func DumpExpr(e ast.Expr, fset *token.FileSet) map[string]interface{} { } if n, ok := e.(*ast.TypeAssertExpr); ok { + var asserted interface{} = nil + if n.Type != nil { + asserted = DumpExprAsType(n.Type, fset) + } return map[string]interface{}{ "kind": "expression", "type": "type-assert", "target": DumpExpr(n.X, fset), - "asserted": DumpExprAsType(n.Type, fset), + "asserted": asserted, "position": DumpPosition(fset.Position(e.Pos())), } } From bf8db1ed9db7c572e98f524b706af9c276bbf8fd Mon Sep 17 00:00:00 2001 From: Eugene Chernyshov Date: Sun, 20 Dec 2020 22:01:23 +0200 Subject: [PATCH 4/5] remove print --- goblin.go | 1 + 1 file changed, 1 insertion(+) diff --git a/goblin.go b/goblin.go index 66247ea..0a78b0b 100644 --- a/goblin.go +++ b/goblin.go @@ -379,6 +379,7 @@ func DumpExpr(e ast.Expr, fset *token.FileSet) map[string]interface{} { } if n, ok := e.(*ast.TypeAssertExpr); ok { + ast.Print(fset, e) var asserted interface{} = nil if n.Type != nil { asserted = DumpExprAsType(n.Type, fset) From 4f41d3319bc12352f17d8b09cfed5d9a0e57286d Mon Sep 17 00:00:00 2001 From: Eugene Chernyshov Date: Sun, 20 Dec 2020 22:14:41 +0200 Subject: [PATCH 5/5] remove print --- goblin.go | 1 - 1 file changed, 1 deletion(-) diff --git a/goblin.go b/goblin.go index 0a78b0b..66247ea 100644 --- a/goblin.go +++ b/goblin.go @@ -379,7 +379,6 @@ func DumpExpr(e ast.Expr, fset *token.FileSet) map[string]interface{} { } if n, ok := e.(*ast.TypeAssertExpr); ok { - ast.Print(fset, e) var asserted interface{} = nil if n.Type != nil { asserted = DumpExprAsType(n.Type, fset)