def until.go

gralha-text-scan@0.1.0.1 · scan.bend:65

import gralha-text-scan@0.1.0.1/scan.bend as Scan
import Base

65# Scanning loops decide each character one step ahead (`hit` says whether
66# `c`, the character before `t`, ends the scan), so the rest of the text is
67# only ever held once: a shared tail would make every step pay for the
68# sharing. The rest comes first, as the argument that shrinks.
69def until.go(t: String, hit: Bool, +c: U32, +end: U32, acc: String) -> Scan:
70  match t hit:
71    case t True{}: Scan{rev(acc, ""), t}
72    case SNil{} False{}: Scan{rev(SCon{Chr{c}, acc}, ""), ""}
73    case SCon{Chr{c2}, t2} False{}:
74      +cc = c2
75      until.go(t2, U32.is_eq(cc, end), cc, end, SCon{Chr{c}, acc})

Uses (7)

Used by (1)