Чистка: Decl обработчики вынесены в отдельный файл
Этот коммит содержится в:
родитель
912d0c6a29
коммит
3b400bccbb
3 изменённых файлов: 32 добавлений и 27 удалений
18
pkg/service/decl.go
Обычный файл
18
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
|
||||||
|
}
|
|
@ -2,7 +2,6 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
|
@ -152,29 +151,3 @@ func (s *defaultService) printGoHelperDeclarations() {
|
||||||
}
|
}
|
||||||
s.out.Write([]byte("\n"))
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,8 +2,22 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go/ast"
|
"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 {
|
func handleSpecs(specs []ast.Spec) string {
|
||||||
code := ""
|
code := ""
|
||||||
for _, spec := range specs {
|
for _, spec := range specs {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче