Exemple #1
0
func printType(node ast.Node) {
	switch node.(type) {
	case *ast.Tuple:
		t := node.(*ast.Tuple)
		fmt.Printf("( ")
		for _, node := range t.Nodes {
			printType(node)
		}
		fmt.Printf(") ")
	default:
		fmt.Printf("%v ", node.Type())
	}
}
Exemple #2
0
func parseBinds(node ast.Node) ast.Binds {
	fmt.Println("#parseBinds")
	if node.Type() != const_.TUPLE {
		panic("let: bad syntax")
	}

	nodes := node.(*ast.Tuple).Nodes
	binds := ast.NewBinds(nil)
	for _, bind := range nodes {
		if bind.Type() != const_.TUPLE {
			panic("let: bad syntax")
		}
		t := bind.(*ast.Tuple)
		if len(t.Nodes) != 2 && t.Nodes[0].Type() != const_.IDENT {
			panic("let: bad syntax")
		}
		binds.Bindings = append(
			binds.Bindings, *ast.NewBind(t.Nodes[0].(*ast.Ident).Name, parseNode(t.Nodes[1])))
	}
	return *binds
}