Explorer

definy.json-parse-value

description
Parse a JSON value at index (spaces before it are skipped)
type
Fn(source: Record{text: String, bytes: List<Number>}, index: Number) -> Union{#ok(Record{value: @definy.json, next: Number}), #error(String)}
expression
fn(source$0, index$1) =>
  let start$2 = @definy.text-skip(source: $0, index: $1);
  let byte$3 = @definy.text-byte-at(source: $0, index: $2);
  match @core.equal(left: $3, right: 34) {
    true =>
      match @definy.text-parse-string(source: $0, index: $2) {
        #error(message$4) =>
          #error($4),
        #ok(parsed$5) =>
          #ok({value: #string<@definy.json>($5.value), next: $5.next})
      },
    false =>
      match @core.equal(left: $3, right: 91) {
        true =>
          let inner$6 = @definy.text-skip(source: $0, index: @core.plus(left: $2, right: 1));
          match @core.equal(left: @definy.text-byte-at(source: $0, index: $6), right: 93) {
            true =>
              #ok({value: #array<@definy.json>([]), next: @core.plus(left: $6, right: 1)}),
            false =>
              match @definy.json-parse-array-rest(source: $0, index: $6, acc: []) {
                #error(message$7) =>
                  #error($7),
                #ok(items$8) =>
                  #ok({value: #array<@definy.json>($8.value), next: $8.next})
              }
          },
        false =>
          match @core.equal(left: $3, right: 123) {
            true =>
              let inner$9 = @definy.text-skip(source: $0, index: @core.plus(left: $2, right: 1));
              match @core.equal(left: @definy.text-byte-at(source: $0, index: $9), right: 125) {
                true =>
                  #ok({value: #object<@definy.json>([]), next: @core.plus(left: $9, right: 1)}),
                false =>
                  match @definy.json-parse-object-rest(source: $0, index: $9, acc: []) {
                    #error(message$10) =>
                      #error($10),
                    #ok(fields$11) =>
                      #ok({value: #object<@definy.json>($11.value), next: $11.next})
                  }
              },
            false =>
              @definy.json-parse-scalar(source: $0, index: $2)
          }
      }
  }
visibility
public
definy.json-parse-value (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: R3jp1Y7vPnecj5HGrLTK53ytTVeG6lCSSs2Ns-y-uRU
content hash: toTIil6NLbQCOuzswfAbtQjULH6-Tdj5ycT_FK2SD1M