def reads

bolt@1.27.0.0 · src/rules/suspicious/thunk.bend:38

import bolt@1.27.0.0/src/rules/suspicious/thunk.bend as Thunk
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

38# does a name leaf under the node read the parameter: its text, or its text
39# then a dot?
40def reads(nn: Tree.Node, +pp: String) -> Bool:
41  match nn:
42    case Tree.Leaf{Lex.Tok{k, +t, _l, _c}}:
43      Bool.and(Lex.is_name(k), Bool.or(String.eq(t, pp), String.starts_with(t, pp ++ ".")))
44    case Tree.Group{_o, kids, _cl}:
45      reads(kids, pp)
46    case Tree.Stmt{_k, kids, body}:
47      +a = reads(kids, pp)
48      +b = reads(body, pp)
49      Bool.or(a, b)
50    case Tree.NCons{h, t}:
51      +a = reads(h, pp)
52      +b = reads(t, pp)
53      Bool.or(a, b)
54    case Tree.NNil{}:
55      False{}

Uses (10)

Used by (1)