Apply is a general purpose iterator method that operates on any AST node. It is not used as the primary AST traversal function because it is less readable and easy to reason about than manually implementing traversal for each node. Nevertheless, it is a useful facility for operations that might only
(fn func(interfaces.Node) error)
| 1666 | // Nevertheless, it is a useful facility for operations that might only apply to |
| 1667 | // a select number of node types, since they won't need extra noop iterators... |
| 1668 | func (obj *StmtResField) Apply(fn func(interfaces.Node) error) error { |
| 1669 | if obj.Condition != nil { |
| 1670 | if err := obj.Condition.Apply(fn); err != nil { |
| 1671 | return err |
| 1672 | } |
| 1673 | } |
| 1674 | if err := obj.Value.Apply(fn); err != nil { |
| 1675 | return err |
| 1676 | } |
| 1677 | return fn(obj) |
| 1678 | } |
| 1679 | |
| 1680 | // Init initializes this branch of the AST, and returns an error if it fails to |
| 1681 | // validate. |