Apply traverses a syntax tree recursively, starting with root, and calling pre and post for each node as described below. Apply returns the syntax tree, possibly modified. If pre is not nil, it is called for each node before the node's children are traversed (pre-order). If pre returns false, no ch
(root ast.Node, pre, post ApplyFunc)
| 40 | // respective node's struct definition. A package's files are |
| 41 | // traversed in the filenames' alphabetical order. |
| 42 | func Apply(root ast.Node, pre, post ApplyFunc) (result ast.Node) { |
| 43 | parent := &struct{ ast.Node }{root} |
| 44 | defer func() { |
| 45 | if r := recover(); r != nil && r != abort { |
| 46 | panic(r) |
| 47 | } |
| 48 | result = parent.Node |
| 49 | }() |
| 50 | a := &application{pre: pre, post: post} |
| 51 | a.apply(parent, "Node", nil, root) |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | var abort = new(int) // singleton, to signal termination of Apply |
| 56 |