def css.cut
gralha-css-style@0.1.0.1 · css.bend:36
import gralha-css-style@0.1.0.1/css.bend as Css
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
36def css.cut(+s: String, +end: U32, +depth: U32, +quote: U32, +escaped: Bool, +acc: String) -> U.Scan:
37 match s:
38 case SNil{}: U.Scan{U.rev(acc, ""), ""}
39 case SCon{Chr{ch}, tail}:
40 +c = ch
41 +t = tail
42 +quoted = Bool.not(U32.is_eq(quote, 0))
43 +opening = U32.is_eq(c, 40) || U32.is_eq(c, 91) || U32.is_eq(c, 123)
44 +closing = U32.is_eq(c, 41) || U32.is_eq(c, 93) || U32.is_eq(c, 125)
45 U.branch(U.Scan, Bool.not(escaped) && Bool.not(quoted) && U32.is_eq(depth, 0) && css.stop(c, end),
46 _ => U.Scan{U.rev(acc, ""), s},
47 _ => U.branch(U.Scan, Bool.not(escaped) && Bool.not(quoted) && U.prefix(s, "/*"),
48 _ => css.cut(U.through(t, "*/"), end, depth, quote, False{}, acc),
49 _ => css.cut(t, end,
50 U.choose(U32, quoted || escaped, depth, U.choose(U32, opening, U32.inc(depth), U.choose(U32, closing && U32.is_gt(depth, 0), (depth - 1 : U32), depth))),
51 U.choose(U32, escaped, quote, U.choose(U32, quoted, U.choose(U32, U32.is_eq(c, quote), 0, quote), U.choose(U32, U32.is_eq(c, 34) || U32.is_eq(c, 39), c, 0))),
52 Bool.not(escaped) && U32.is_eq(c, 92), SCon{Chr{c}, acc})))