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

33 lines
589 B
Go

package main
import (
"fmt"
"go/ast"
)
func parseTypeExpr(loc string, s ast.Expr, ln bool) {
switch s := s.(type) {
case *ast.ArrayType:
if s.Len == nil {
fmt.Print("slice of ")
} else {
fmt.Print("array of ")
}
parseTypeExpr(loc, s.Elt, false)
case *ast.ChanType:
fmt.Print("chan of ")
parseTypeExpr(loc, s.Value, false)
case *ast.Ident:
fmt.Print(s)
case *ast.MapType:
fmt.Print("map of ")
parseTypeExpr(loc, s.Value, false)
fmt.Print(" by ")
parseTypeExpr(loc, s.Key, false)
default:
fmt.Printf("type: %#v\n", s)
}
if ln {
fmt.Println()
}
}