parse.go 405 B

123456789101112131415161718192021222324
  1. package main
  2. import (
  3. "fmt"
  4. "go/ast"
  5. )
  6. func parseFile(f *ast.File) {
  7. loc := f.Name.String()
  8. for _, d := range f.Decls {
  9. switch d := d.(type) {
  10. case *ast.GenDecl:
  11. parseGenDecl(loc, d)
  12. case *ast.FuncDecl:
  13. parseFuncDecl(loc, d)
  14. default:
  15. fmt.Printf("Unknown decl type in %s: %T\n", loc, d)
  16. }
  17. }
  18. }
  19. func parseTypeSpec(loc string, s *ast.TypeSpec) {
  20. fmt.Printf("%s/typeSpec\n", loc)
  21. }