Explorer

definy.json-parse-array-rest

description
Parse the items of a JSON array after '[' up to ']'
type
Fn(source: Record{text: String, bytes: List<Number>}, index: Number, acc: List<@definy.json>) -> Union{#ok(Record{value: List<@definy.json>, next: Number}), #error(String)}
expression
fn(source$0, index$1, acc$2) =>
  match @definy.json-parse-value(source: $0, index: $1) {
    #error(message$3) =>
      #error($3),
    #ok(item$4) =>
      let items$5 = @core.list-append(list: $2, item: $4.value);
      let next$6 = @definy.text-skip(source: $0, index: $4.next);
      let byte$7 = @definy.text-byte-at(source: $0, index: $6);
      match @core.equal(left: $7, right: 44) {
        true =>
          @definy.json-parse-array-rest(source: $0, index: @core.plus(left: $6, right: 1), acc: $5),
        false =>
          match @core.equal(left: $7, right: 93) {
            true =>
              #ok({value: $5, next: @core.plus(left: $6, right: 1)}),
            false =>
              #error(@definy.text-error(message: "expected ',' or ']'", index: $6))
          }
      }
  }
visibility
public
definy.json-parse-array-rest (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: t4Mw2rlfko0IVpmuUmsRyo2wZQSoLsKgzh_DhtrFuiM
content hash: q2RXD_1aA6uhkov_UbNnPbr-aHaDYB-rYzMd3DvPs68