def wf.go

emerging-ezjson@1.3.0.0 · src/value.bend:357

import emerging-ezjson@1.3.0.0/src/value.bend as Value
import Base
import emerging-ezjson@1.3.0.0/src/lazy.bend as Lazy

357# whether a value, or a chain of cells, has the shape the parser and the
358# builders give: arrays and objects are chains of cells ending in JNil, no
359# cell stands where a value belongs, and a number's text is a JSON number
360def wf.go(val: Json, shape: Shape) -> Bool:
361  match val shape:
362    case JNull{} WVal{}:
363      True{}
364    case JBool{_} WVal{}:
365      True{}
366    case JNum{raw} WVal{}:
367      num.ok(raw)
368    case JStr{_} WVal{}:
369      True{}
370    case JSpan{_, _} WVal{}:
371      True{}
372    case JArr{items} WVal{}:
373      wf.go(items, WArr{})
374    case JObj{pairs} WVal{}:
375      wf.go(pairs, WObj{})
376    case JNil{} WArr{}:
377      True{}
378    case JCons{hd, tl} WArr{}:
379      Lazy.stop(Bool, Bool.not(wf.go(hd, WVal{})), False{}, _u => wf.go(tl, WArr{}))
380    case JNil{} WObj{}:
381      True{}
382    case JPair{_, vv, rr} WObj{}:
383      Lazy.stop(Bool, Bool.not(wf.go(vv, WVal{})), False{}, _u => wf.go(rr, WObj{}))
384    case JBind{_, _, vv, rr} WObj{}:
385      Lazy.stop(Bool, Bool.not(wf.go(vv, WVal{})), False{}, _u => wf.go(rr, WObj{}))
386    case _ _:
387      False{}

Uses (6)

Used by (1)