def shape
ezmcp@0.1.0.0 · src/openapi.bend:565
import ezmcp@0.1.0.0/src/openapi.bend as Openapi
import Base
import emerging-ezjson@1.2.0.0/src/value.bend as Value
565
566
567
568
569def shape(fuel: Nat, val: Value.Json, read: Read) -> Value.Json:
570 match fuel:
571 case 0n:
572 val
573 case 1n+(+less):
574 match val read:
575 case Value.JObj{pairs} ASchema{}:
576 +ps = own(members(Value.JObj{pairs}))
577 kids.put(ps, kids(ps), cs => shape(less, cs, AProps{}),
578 got => shape(less, got, ASchema{}))
579 case Value.JPair{key, +item, rest} AProps{}:
580 prop.put(prop.of(item), key, item, got => shape(less, got, ASchema{}),
581 shape(1n+less, rest, AProps{}))
582 case Value.JBind{src, +n, +item, rest} AProps{}:
583 prop.put(prop.of(item), Value.span.str(src, n, U32.is_zero(n)), item,
584 got => shape(less, got, ASchema{}), shape(1n+less, rest, AProps{}))
585 case other ASchema{}:
586 other
587 case other AProps{}:
588 Value.JNil{}