def calls

bolt@1.27.0.0 · src/rules/calls.bend:119

import bolt@1.27.0.0/src/rules/calls.bend as Calls
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

119# is there a call of the name, `name(..)`, anywhere under the node?
120def calls(nn: Tree.Node, +name: String) -> Bool:
121  match nn:
122    case Tree.NCons{Tree.Leaf{Lex.Tok{k, +t, l, c}}, Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, kids, _}, rest}}:
123      +a = calls(kids, name)
124      +b = calls(rest, name)
125      Bool.or(Bool.and(String.eq(o, "("), String.eq(t, name)), Bool.or(a, b))
126    case Tree.Group{open, kids, close}:
127      calls(kids, name)
128    case Tree.Stmt{kind, kids, body}:
129      +a = calls(kids, name)
130      +b = calls(body, name)
131      Bool.or(a, b)
132    case Tree.NCons{h, t}:
133      +a = calls(h, name)
134      +b = calls(t, name)
135      Bool.or(a, b)
136    case other:
137      False{}

Uses (7)

Used by (4)