go__parsing_demo/02-basic_tree_walk/decl.go
Frédéric G. MARAND 3d784fdb6f
WIP
2023-04-04 11:06:18 +02:00

33 lines
550 B
Go

package main
import (
"fmt"
"go/ast"
)
func parseFuncDecl(loc string, d *ast.FuncDecl) {
loc += "." + d.Name.String()
// fmt.Printf("%s()\n", loc)
if d.Body == nil {
fmt.Println("nil func body")
return
}
for _, s := range d.Body.List {
parseStmt(loc, s)
}
}
func parseGenDecl(loc string, d *ast.GenDecl) {
loc += "/gendecl"
for _, s := range d.Specs {
switch s := s.(type) {
case *ast.TypeSpec:
parseTypeSpec(loc, s)
case *ast.ImportSpec, *ast.ValueSpec:
// rien
default:
fmt.Printf("%s/(%T)\n", loc, s)
}
}
}