def gather

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

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

558# every expensive call, wide unless the call is indexed on the spot; its
559# arguments are their text and which let of each name they read
560def gather(nn: Tree.Node, +self: String, +lp: List<&2, String>, +bs: List<&2, Bind>) -> List<&2, Site>:
561  match nn:
562    case Tree.NCons{Tree.Leaf{Lex.Tok{k, +t, +l, +c}}, Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, +kids, _}, +rest}}:
563      +args = Tree.show(kids) ++ stamp(names(kids, []), bs, l, c)
564      +here = open_site(String.eq(o, "("), indexed(rest), t, args, l, c,
565        U32.from_nat(String.length(t)), self, lp)
566      List.concat(&2, Site, [here, gather(kids, self, lp, bs), gather(rest, self, lp, bs)])
567    case Tree.NCons{Tree.Group{open, +kids, close}, rest}:
568      List.concat(&2, Site, [gather(kids, self, lp, bs), gather(rest, self, lp, bs)])
569    case Tree.NCons{Tree.Stmt{Tree.SCase{}, +kids, body}, rest}:
570      List.concat(&2, Site, [gather(kids, self, lp, bs), gather(rest, self, lp, bs)])
571    case Tree.NCons{Tree.Stmt{kind, +kids, body}, rest}:
572      List.concat(&2, Site, [gather(kids, self, lp, bs), gather(body, self, lp, bs), gather(rest, self, lp, bs)])
573    case Tree.NCons{h, rest}:
574      gather(rest, self, lp, bs)
575    case other:
576      Nil{}

Uses (17)

Used by (1)