On Wed, Mar 11, 2020 at 3:22 AM Amirouche Boubekki <xxxxxx@gmail.com> wrote:

The point is to make it possible for some one that does want to rely
on the trampoline code and have fast parser without re-implementing
the tokenizer.

> Exactly how do values get added to the internal representation of an object or array?

Like the fold procedure, values get added to the internal
representation of an object or array in `proc`. The associated object
or array are finalized in resp. object-end or array-end.

Right, so the state objects have to be shared between the five procedures (unlike fold, vector-fold, etc. where there is only one state object and one procedure).

I suggest a different approach:  json-fold itself keeps track of the current state object.  This is intially #f.  All five procedures accept this as an argument.  In addition, start-object and start-array return a new state object that becomes the one that json-fold is tracking.  It is the responsibility of these procedures to connect the new state object to the old state object in whatever way is appropriate (if you are flattening the JSON they could be the same object).   Finally, end-object and end-array return the previous state object.

Does this make sense?  I think this design would be easier to write code for, but I admit I have not tried it.

John Cowan          http://vrici.lojban.org/~cowan        xxxxxx@ccil.org
Here lies the Christian, judge, and poet Peter,
Who broke the laws of God and man and metre.