def hits

bolt@1.27.0.0 · src/rules/pedantic/rewalk.bend:323

import bolt@1.27.0.0/src/rules/pedantic/rewalk.bend as Rewalk
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

323# reads of the name. hot: this chain is a collection argument. live/left: commas
324# count toward that argument. skip: ignore names until `=` (the left of a let)
325def hits(nn: Tree.Node, +name: String, +hot: Bool, +left: Nat, +live: Bool, +skip: Bool) -> Hit:
326  match nn:
327    case Tree.NCons{Tree.Leaf{Lex.Tok{Lex.TEq{}, t, l, c}}, rest}:
328      hits(rest, name, hot, left, live, False{})
329    case Tree.NCons{Tree.Leaf{Lex.Tok{Lex.TComma{}, t, l, c}}, rest}:
330      hits(rest, name, step_hot(hot, left, live), step_left(left, live), live, skip)
331    case Tree.NCons{Tree.Leaf{Lex.Tok{k, +t, l, c}}, Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, +kids, _}, rest}}:
332      +brack = String.eq(o, "[")
333      +call = String.eq(o, "(")
334      +here = hit_keep(skip, here_hit(brack, call, t, name, hot))
335      +inn = hits(kids, name, pick_hot(skip, brack, call, hot), pick_left(skip, brack, call, t),
336        pick_live(skip, brack, call, t), skip)
337      +aft = hits(rest, name, hot, left, live, skip)
338      either(here, either(inn, aft))
339    case Tree.NCons{Tree.Leaf{Lex.Tok{Lex.TName{}, +t, l, c}}, rest}:
340      either(hit_keep(skip, name_hit(String.eq(t, name), hot)), hits(rest, name, hot, left, live, skip))
341    case Tree.NCons{Tree.Leaf{tok}, rest}:
342      hits(rest, name, hot, left, live, skip)
343    case Tree.NCons{Tree.Group{open, +kids, close}, rest}:
344      either(hits(kids, name, hot, 0n, False{}, skip), hits(rest, name, hot, left, live, skip))
345    case Tree.NCons{Tree.Stmt{kind, +kids, body}, rest}:
346      +eq = has_eq(kids)
347      +inn = hits(kids, name, False{}, 0n, False{}, eq)
348      +bod = hits(body, name, False{}, 0n, False{}, False{})
349      +aft = hits(rest, name, hot, left, live, skip)
350      either(inn, either(bod, aft))
351    case Tree.NCons{h, rest}:
352      hits(rest, name, hot, left, live, skip)
353    case other:
354      none_hit()

Uses (19)

Used by (1)