def val

cswap-bend-cli@0.1.0.0 · json.bend:196

import cswap-bend-cli@0.1.0.0/json.bend as Json
import Base
import cswap-bend-cli@0.1.0.0/json/scan.bend as Scan

196# One def for values, array items and object fields: `plan` says which step
197# this is. `fuel` bounds the work (3 * tokens + 5). An item's tokens are those
198# up to the next comma or closer at depth 0.
199def val(fuel: Nat, pl: Plan) -> Result<&2, &2, String, Json>:
200  match fuel pl:
201    case 0n _:
202      Fail{"nesting too deep"}
203    case 1n++p PRes{r}:
204      r
205    case 1n++p PArr{+t}:
206      wrap.arr(Scan.closed_by(t, 22), val(p, plan(MAFirst{}, body(t))))
207    case 1n++p PObj{+t}:
208      wrap.obj(Scan.closed_by(t, 21), val(p, plan(MOFirst{}, body(t))))
209    case 1n++p PItems{f, r}:
210      item.cons(val(p, plan(MVal{}, f)), val(p, plan(MAAfter{}, r)))
211    case 1n++p PFields{k, vt, r}:
212      field.cons(k, val(p, plan(MVal{}, vt)), val(p, plan(MOAfter{}, r)))
213    case 1n++p PNext{m, t}:
214      val(p, plan(m, t))

Uses (13)

Used by (1)