I wrote:
> I was also looking for a cleaner way to express this parser, and to add
> better error reporting, while allowing flexibility for users to
> customize the Scheme representation.
I forgot to mention that another goal was to minimize heap allocations,
e.g. eliminating the allocation of intermediate lists of characters or
digits.
> (define (read-array port)
> "Read a JSON array from PORT and return the result of calling
> ARRAY-FINALIZE on the final seed produced using ARRAY-KNIL and
> ARRAY-KONS."
> (match-next* port
> (#\[ (match-next* port
> (#\] array-knil)
> (else (let ((seed (read-array-elements array-knil port)))
> (match-next* port
> (#\] (array-finalize seed)))))))))
Sorry, I forgot to apply 'array-finalize' in the empty-array case.
Here's a corrected version:
(define (read-array port)
"Read a JSON array from PORT and return the result of calling
ARRAY-FINALIZE on the final seed produced using ARRAY-KNIL and
ARRAY-KONS."
(array-finalize
(match-next* port
(#\[ (match-next* port
(#\] array-knil)
(else (let ((seed (read-array-elements array-knil port)))
(match-next* port
(#\] seed)))))))))
Mark