def tagdir.handle

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

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

1304def tagdir.handle(w: Taken, +st: Sc, +b: Nat, +at: T.Mark) -> Step:
1305  match w:
1306    case Taken{+word, +k}:
1307      +rest = String.drop(sc.s(st), b)
1308      +closed = Char.is_eq(peek(rest, 1n+k), '!')
1309      +hlen = Nat.add(1n+k, Bool.pick(Nat, closed, 1n, 0n))
1310      +handle = String.take(rest, hlen)
1311      +b2 = blanks(String.drop(rest, hlen))
1312      +ok = Bool.and(Char.is_eq(peek(rest, 0n), '!'), Bool.or(closed, Nat.is_eq(k, 0n)))
1313      when(Step, Bool.or(Nat.is_eq(b, 0n), Bool.not(ok)), u => fail(st, "did not find expected '!' while scanning a %TAG directive", at),
1314        u => when(Step, Nat.is_eq(b2, 0n), u => fail(st, "did not find expected whitespace while scanning a %TAG directive", at),
1315          u => tagdir.prefix(tag.chars(String.drop(rest, Nat.add(hlen, b2)), True{}, 0n), st, handle, Nat.add(b, Nat.add(hlen, b2)), at)))

Uses (23)

Used by (1)