MatchDescendants takes a NavigableExpr and ExprMatcher and produces a list of NavigableExpr values matching the input criteria in post-order (bottom up).
(expr NavigableExpr, matcher ExprMatcher)
| 104 | // MatchDescendants takes a NavigableExpr and ExprMatcher and produces a list of NavigableExpr values |
| 105 | // matching the input criteria in post-order (bottom up). |
| 106 | func MatchDescendants(expr NavigableExpr, matcher ExprMatcher) []NavigableExpr { |
| 107 | matches := []NavigableExpr{} |
| 108 | navVisitor := &baseVisitor{ |
| 109 | visitExpr: func(e Expr) { |
| 110 | nav := e.(NavigableExpr) |
| 111 | if matcher(nav) { |
| 112 | matches = append(matches, nav) |
| 113 | } |
| 114 | }, |
| 115 | } |
| 116 | visit(expr, navVisitor, postOrder, 0, 0) |
| 117 | return matches |
| 118 | } |
| 119 | |
| 120 | // MatchSubset applies an ExprMatcher to a list of NavigableExpr values and their descendants, producing a |
| 121 | // subset of NavigableExpr values which match. |