def search.cheap

bolt@1.27.0.0 · src/rules/correctness/pick.bend:169

import bolt@1.27.0.0/src/rules/correctness/pick.bend as Pick
import Base
import bolt@1.27.0.0/src/syntax/lex.bend as Lex
import bolt@1.27.0.0/src/syntax/tree.bend as Tree
import bolt@1.27.0.0/src/rules/calls.bend as Calls

169# does a `Bool.pick(..)` under the node, at any depth, have the condition
170# whose text is cond?
171def search.cheap(nn: Tree.Node, +cond: String) -> Bool:
172  match nn:
173    case Tree.NCons{Tree.Leaf{Lex.Tok{_k, +t, _l, _c}}, Tree.NCons{Tree.Group{Lex.Tok{_ko, +o, _lo, _co}, +kids, _cl},
174      rest}}:
175      +here = Bool.and(Bool.and(String.eq(t, "Bool.pick"), String.eq(o, "(")),
176        String.eq(search.text(Calls.arg(Calls.args(kids), 1n)), cond))
177      +a = search.cheap(kids, cond)
178      +b = search.cheap(rest, cond)
179      Bool.or(here, Bool.or(a, b))
180    case Tree.Group{_o, kids, _cl}:
181      search.cheap(kids, cond)
182    case Tree.Stmt{_k, kids, body}:
183      +a = search.cheap(kids, cond)
184      +b = search.cheap(body, cond)
185      Bool.or(a, b)
186    case Tree.NCons{h, t}:
187      +a = search.cheap(h, cond)
188      +b = search.cheap(t, cond)
189      Bool.or(a, b)
190    case _other:
191      False{}

Uses (10)

Used by (1)