def calls

bolt@1.27.0.0 · src/rules/pedantic/fuel.bend:141

import bolt@1.27.0.0/src/rules/pedantic/fuel.bend as Fuel
import Base
import bolt@1.27.0.0/src/lazy/lazy.bend as Lazy
import bolt@1.27.0.0/src/finding.bend as F
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

141# every call at any depth of a chain, but the def's own (self)
142def calls(nn: Tree.Node, +fs: List<&2, Fuel>, +self: String, +path: String) -> List<&2, F.Finding>:
143  match nn:
144    case Tree.NCons{Tree.Leaf{Lex.Tok{k, +t, l, c}}, Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, +kids, _}, rest}}:
145      +more = List.concat(&2, F.Finding, [calls(kids, fs, self, path), calls(rest, fs, self, path)])
146      +hit = Bool.and(Bool.and(Lex.is_name(k), String.eq(o, "(")), Bool.not(String.eq(t, self)))
147      Lazy.stop(List<&2, F.Finding>, Bool.not(hit), more,
148        _u => List.append(&2, F.Finding, call(fs, t, Calls.args(kids), path), more))
149    case Tree.NCons{Tree.Group{open, kids, close}, rest}:
150      List.concat(&2, F.Finding, [calls(kids, fs, self, path), calls(rest, fs, self, path)])
151    case Tree.NCons{Tree.Stmt{kind, kids, body}, rest}:
152      List.concat(&2, F.Finding, [calls(kids, fs, self, path), calls(body, fs, self, path),
153        calls(rest, fs, self, path)])
154    case Tree.NCons{h, rest}:
155      calls(rest, fs, self, path)
156    case other:
157      Nil{}

Uses (15)

Used by (1)