def lead

bend-toon-codec@0.1.0.0 · src/dline.bend:27

import bend-toon-codec@0.1.0.0/src/dline.bend as Dline
import Base

27# Count the leading spaces and tabs. `live` is true until the first other
28# character; the recursion runs to the end of the line but only counts
29# while live.
30def lead(+s: String, +sp: U32, +tabs: U32, +live: Bool) -> Ld:
31  match s:
32    case SNil{}:
33      Ld{sp, tabs, s}
34    case SCon{Chr{c}, t}:
35      lead.pick(live && (U32.is_eq(c, 32) || U32.is_eq(c, 9)), s, sp, tabs,
36        lead(t, (sp + inc(live && U32.is_eq(c, 32)) : U32), (tabs + inc(live && U32.is_eq(c, 9)) : U32), live && (U32.is_eq(c, 32) || U32.is_eq(c, 9))))

Uses (11)

Used by (1)