JSON.scan_string_machine: def of qasim-bend-kit@0.1.0.2 Import: import qasim-bend-kit@0.1.0.2/libs/JSON.bend as JSON Lines 415-484 of qasim-bend-kit@0.1.0.2/libs/JSON.bend: https://jend.leeeet.dev/read.txt?path=qasim-bend-kit@0.1.0.2/libs/JSON.bend&start_line=415&end_line=484 import Base def scan_string_machine(fuel: Nat, state: StringScanState) -> Result<&1, &1, Error, StringScan>: match fuel: case 0n: Fail{Error{}} case 1n+p: match state: case ScanText{input, reversed}: match input: case SNil{}: Fail{Error{}} case SCon{+h, +t}: match h: case '"': Done{StringScan{String.reverse(reversed), t}} case '\\': match t: case SNil{}: Fail{Error{}} case SCon{e, et}: match e: case '"': scan_string_machine(p, ScanText{et, SCon{'"', reversed}}) case '\\': scan_string_machine(p, ScanText{et, SCon{'\\', reversed}}) case '/': scan_string_machine(p, ScanText{et, SCon{'/', reversed}}) case 'b': scan_string_machine(p, ScanText{et, SCon{'\u{8}', reversed}}) case 'f': scan_string_machine(p, ScanText{et, SCon{'\u{c}', reversed}}) case 'n': scan_string_machine(p, ScanText{et, SCon{'\n', reversed}}) case 'r': scan_string_machine(p, ScanText{et, SCon{'\r', reversed}}) case 't': scan_string_machine(p, ScanText{et, SCon{'\t', reversed}}) case 'u': scan_string_machine(p, ScanUnicode{scan_hex(4n, et, 0), reversed}) case _: Fail{Error{}} case _: scan_string_machine(p, ScanControl{h, t, reversed, is_control(h)}) case ScanControl{character, rest, reversed, control}: match control: case True{}: Fail{Error{}} case False{}: scan_string_machine(p, ScanText{rest, SCon{character, reversed}}) case ScanUnicode{parsed, reversed}: match parsed: case Fail{e}: Fail{e} case Done{scan}: match scan: case HexScan{+code, +rest}: scan_string_machine(p, ScanUnicodeHigh{code, rest, reversed, U32.is_ge(code, 55296) && U32.is_le(code, 56319)}) case ScanUnicodeHigh{code, +rest, +reversed, is_high}: match rest: case SCon{'\\', SCon{'u', t}}: match is_high: case True{}: scan_string_machine(p, ScanUnicodeLow{code, rest, scan_hex(4n, t, 0), reversed}) case False{}: scan_string_machine(p, ScanText{rest, SCon{Char.from_u32(code), reversed}}) case _: scan_string_machine(p, ScanText{rest, SCon{Char.from_u32(code), reversed}}) case ScanUnicodeLow{high, original, parsed, reversed}: match parsed: case Fail{e}: scan_string_machine(p, ScanText{original, SCon{Char.from_u32(high), reversed}}) case Done{scan}: match scan: case HexScan{+low, +rest}: scan_string_machine(p, ScanUnicodeLowClass{high, low, rest, original, reversed, U32.is_ge(low, 56320) && U32.is_le(low, 57343)}) case ScanUnicodeLowClass{high, low, rest, original, reversed, valid}: match valid: case True{}: scan_string_machine(p, ScanText{rest, SCon{Char.from_u32((65536 + (high - 55296) * 1024 + (low - 56320) : U32)), reversed}}) case False{}: scan_string_machine(p, ScanText{original, SCon{Char.from_u32(high), reversed}}) Uses (22): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Char https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Char.from_u32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.reverse https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_ge https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_le https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.mul https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Word.Con https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Word.Nil https://jend.leeeet.dev/definition.txt?path=qasim-bend-kit@0.1.0.2/libs/JSON.bend&name=Error https://jend.leeeet.dev/definition.txt?path=qasim-bend-kit@0.1.0.2/libs/JSON.bend&name=HexScan https://jend.leeeet.dev/definition.txt?path=qasim-bend-kit@0.1.0.2/libs/JSON.bend&name=StringScan https://jend.leeeet.dev/definition.txt?path=qasim-bend-kit@0.1.0.2/libs/JSON.bend&name=StringScanState https://jend.leeeet.dev/definition.txt?path=qasim-bend-kit@0.1.0.2/libs/JSON.bend&name=is_control https://jend.leeeet.dev/definition.txt?path=qasim-bend-kit@0.1.0.2/libs/JSON.bend&name=scan_hex