33 lines
589 B
Go
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()
|
|
}
|
|
}
|