def depth_to

bolt@1.27.0.0 · src/syntax/tree.bend:197

import bolt@1.27.0.0/src/syntax/tree.bend as Tree
import Base
import bolt@1.27.0.0/src/lazy/lazy.bend as Lazy
import bolt@1.27.0.0/src/syntax/lex.bend as Lex

197# how many groups sit open above the one that c closes (counting it); 0 when
198# none does. A `>` closes only an angle group on top: inside `(..)`, `[..]`
199# or `{..}` it is an operator, even within `<..>`
200def depth_to(stack: List<&2, Frame>, +cc: String) -> Nat:
201  match stack:
202    case Nil{}:
203      0n
204    case Con{FGroup{Lex.Tok{k, +t, l, c2}, kids}, rest}:
205      Lazy.stop(Nat, String.eq(closer(t), cc), 1n,
206        _u => Lazy.stop(Nat, String.eq(cc, ">"), 0n, _v => depth_to.up(depth_to(rest, cc))))
207    case Con{other, rest}:
208      0n

Uses (9)

Used by (2)