def scan

bend-visgraph@2.0.0.0 · src/series.bend:28

import bend-visgraph@2.0.0.0/src/series.bend as Series
import Base

28# Base's String.lines recurses once per character, too deep for the JS
29# lane's stack, so this walks the text with tail calls. `h` is the character
30# before `s`, `nl` whether it is a newline, and `cur` the line before `h`,
31# last character first.
32def scan(s: String, nl: Bool, +h: Char, cur: String, +line: U32, st: Parsed) -> Parsed:
33  match s nl:
34    case SNil{} True{}:
35      step(String.reverse(cur), line, st)
36    case SNil{} False{}:
37      step(String.reverse(SCon{h, cur}), line, st)
38    case SCon{+h2, t} True{}:
39      scan(t, Char.is_eq(h2, '\n'), h2, SNil{}, (line + 1 : U32), step(String.reverse(cur), line, st))
40    case SCon{+h2, t} False{}:
41      scan(t, Char.is_eq(h2, '\n'), h2, SCon{h, cur}, line, st)

Uses (9)

Used by (1)