def bs.breaks

yaml-for-bend@0.1.1.0 · scan.bend:1021

import yaml-for-bend@0.1.1.0/scan.bend as Scan
import Base
import yaml-for-bend@0.1.1.0/token.bend as T

1021# Blank lines and the indentation before content. The first content line
1022# sets the indentation when the header didn't; no blank line before it may
1023# be deeper. A tab may start content but not indentation. A last line of
1024# spaces with no break after it still counts as a line.
1025def bs.breaks(+cur: Cur, +acc: String, +ind: Nat, +max: Nat, +lead: Bool, +lblank: Bool, +brks: Nat, +pind: Nat, +start: T.Mark) -> Bs:
1026  +c = peek(cur.s(cur), 0n)
1027  +col = cur.col(cur)
1028  +inside = Bool.or(Nat.is_eq(ind, 0n), Nat.is_lt(1n+col, ind))
1029  +first = Bool.and(Nat.is_eq(ind, 0n), Nat.is_ge(col, pind))
1030  +partial = Bool.and(Nat.is_gt(col, 0n), Nat.is_gt(T.mark.line(cur.at(cur)), T.mark.line(start)))
1031  Bool.pick(Bs, Bool.and(Char.is_eq(c, ' '), inside), Bs{adv(cur), acc, ind, max, lead, lblank, brks, Breaks{}},
1032    Bool.pick(Bs, is_break(c), Bs{adv(cur), acc, ind, Nat.max(col, max), lead, lblank, 1n+brks, Breaks{}},
1033      Bool.pick(Bs, is_end(c), Bs{cur, acc, ind, max, lead, lblank, Bool.pick(Nat, partial, 1n+brks, brks), LineStart{}},
1034        Bool.pick(Bs, Bool.and(Bool.and(Char.is_eq(c, '\t'), inside), Bool.not(first)),
1035          BsBad{T.Error{"found a tab character where an indentation space is expected while scanning a block scalar", start, T.Syntax{}}},
1036          Bool.pick(Bs, Bool.and(first, Nat.is_gt(max, col)),
1037            BsBad{T.Error{"found a leading blank line with more spaces than the first content line while scanning a block scalar", start, T.Syntax{}}},
1038            Bs{cur, acc, Bool.pick(Nat, Nat.is_eq(ind, 0n), 1n+Nat.max(col, pind), ind), max, lead, lblank, brks, LineStart{}})))))

Uses (28)

Used by (1)