Beispiel #1
0
func parseQQList(node ast.Node, dep int) ast.Node {
	switch t := node.(type) {
	case *ast.Ident:
		return ast.NewSymbol(t.Name)

	case *ast.Tuple:
		switch t.Nodes[0].Type() {
		case const_.QUASIQUOTE:
			ret := ast.NewList([]ast.Node{ast.NewSymbol("quasiquote")})
			ret.Nodes = append(ret.Nodes, parseQQList(t.Nodes[1], dep+1))
			return ret

		case const_.UNQUOTE:
			if dep == 0 {
				return parseNode(t.Nodes[1])
			} else {
				ret := ast.NewList([]ast.Node{ast.NewSymbol("unquote")})
				ret.Nodes = append(ret.Nodes, parseQQList(t.Nodes[1], dep-1))
				return ret
			}

		default:
			var items []ast.Node
			for _, node := range t.Nodes {
				items = append(items, parseQQList(node, dep))
			}
			return ast.NewList(items)
		}

	default:
		return parseNode(node)
	}

	return nil
}
Beispiel #2
0
func parseList(node *ast.Tuple) ast.Node {
	fmt.Println("#parseList")
	nNode := len(node.Nodes)
	if nNode == 0 {
		return ast.NewList(make([]ast.Node, 0))
	}
	var nodes []ast.Node
	for _, node := range node.Nodes[1:] {
		nodes = append(nodes, parseNode(node))
	}
	return ast.NewList(nodes)
}