def walk

bolt@1.27.0.0 · src/rules/pedantic/strict.bend:89

import bolt@1.27.0.0/src/rules/pedantic/strict.bend as Strict
import Base
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

89# the self-calls in operands: outer is whether the enclosing group is an
90# operand, hot whether the current comma segment is; a `=>` starts a lambda
91# body, hot only by its own `&&`/`||`. A leaf is read by its kind in `leaf`,
92# once the cell after it is known
93def walk(nn: Tree.Node, +name: String, +path: String, +outer: Bool, +hot: Bool) -> List<&2, F.Finding>:
94  match nn:
95    case Tree.NCons{Tree.Leaf{Lex.Tok{k, +t, +l, +c}}, +rest}:
96      match rest:
97        case Tree.NCons{Tree.Group{Lex.Tok{_, +o, _, _}, +kids, _}, r2}:
98          leaf(k, _u => walk(rest, name, path, outer, Bool.or(outer, seg_op(rest))),
99            _v => walk(rest, name, path, outer, seg_op(rest)),
100            _w => call(t, l, c, o, name, path, hot,
101              walk(kids, name, path, inner(hot, o, t), Bool.or(inner(hot, o, t), seg_op(kids))),
102              walk(r2, name, path, outer, hot)))
103        case _r:
104          leaf(k, _u => walk(rest, name, path, outer, Bool.or(outer, seg_op(rest))),
105            _v => walk(rest, name, path, outer, seg_op(rest)), _w => walk(rest, name, path, outer, hot))
106    case Tree.NCons{Tree.Group{open, +kids, close}, rest}:
107      List.concat(&2, F.Finding, [walk(kids, name, path, hot, Bool.or(hot, seg_op(kids))),
108        walk(rest, name, path, outer, hot)])
109    case Tree.NCons{Tree.Stmt{kind, +kids, body}, rest}:
110      List.concat(&2, F.Finding, [walk(kids, name, path, False{}, seg_op(kids)),
111        walk(body, name, path, False{}, False{}),
112        walk(rest, name, path, outer, hot)])
113    case Tree.NCons{h, rest}:
114      walk(rest, name, path, outer, hot)
115    case other:
116      Nil{}

Uses (12)

Used by (1)