From 3b400bccbbf6471d47506924675ecbeb4407f851 Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 22 Jan 2024 03:35:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B8=D1=81=D1=82=D0=BA=D0=B0:=20Decl=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=87=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/decl.go | 18 ++++++++++++++++++ pkg/service/service.go | 27 --------------------------- pkg/service/spec.go | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 pkg/service/decl.go diff --git a/pkg/service/decl.go b/pkg/service/decl.go new file mode 100644 index 0000000..8101073 --- /dev/null +++ b/pkg/service/decl.go @@ -0,0 +1,18 @@ +package service + +import ( + "go/ast" +) + +func handleDecl(id int, decl ast.Decl, dst chan<- string, done chan<- bool) { + code := "" + switch d := decl.(type) { + case *ast.FuncDecl: + code += handleFuncDecl(d) + case *ast.GenDecl: + code += handleGenDecl(d) + } + dst <- code + close(dst) + done <- true +} diff --git a/pkg/service/service.go b/pkg/service/service.go index 9b5138c..5f2afe1 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -2,7 +2,6 @@ package service import ( "fmt" - "go/ast" "go/parser" "go/token" "io" @@ -152,29 +151,3 @@ func (s *defaultService) printGoHelperDeclarations() { } s.out.Write([]byte("\n")) } - -func handleDecl(id int, decl ast.Decl, dst chan<- string, done chan<- bool) { - code := "" - switch d := decl.(type) { - case *ast.FuncDecl: - code += handleFuncDecl(d) - case *ast.GenDecl: - code += handleGenDecl(d) - } - dst <- code - close(dst) - done <- true -} - -func handleGenDecl(decl ast.Decl) string { - gd := decl.(*ast.GenDecl) - code := "" - switch gd.Tok { - case token.CONST: - code += "const " - case token.VAR: - code += "" - } - code += handleSpecs(gd.Specs) - return code -} diff --git a/pkg/service/spec.go b/pkg/service/spec.go index c559d97..2057a79 100644 --- a/pkg/service/spec.go +++ b/pkg/service/spec.go @@ -2,8 +2,22 @@ package service import ( "go/ast" + "go/token" ) +func handleGenDecl(decl ast.Decl) string { + gd := decl.(*ast.GenDecl) + code := "" + switch gd.Tok { + case token.CONST: + code += "const " + case token.VAR: + code += "" + } + code += handleSpecs(gd.Specs) + return code +} + func handleSpecs(specs []ast.Spec) string { code := "" for _, spec := range specs {