[erlang-questions] json_to_term EEP

Richard A. O'Keefe ok@REDACTED
Mon Aug 4 04:34:44 CEST 2008


On 2 Aug 2008, at 6:20 am, Chris Anderson wrote:
> Just checked through the Yecc documentation - it looks like the
> example code I posted has both a DVM and a SAX-like API. It's nice
> that the same code base can serve both purposes. Now to make it fast!
>
> from the Yecc docs: http://www.erlang.org/doc/man/yecc.html
>
> ====
>
> It is also possible to make the parser ask for more input tokens when
> needed if the following call format is used:
>
> myparser:parse_and_scan({Function, Args})
> myparser:parse_and_scan({Mod, Tokenizer, Args})
>
> The tokenizer Function is either a fun or a tuple {Mod, Tokenizer}.
>
> The call apply(Function, Args) or apply({Mod, Tokenizer}, Args) is
> executed whenever a new token is needed. This, for example, makes it
> possible to parse from a file, token by token.

This is not a SAX-like API.  A SAX-like API is one where you do NOT
get a data structure as *output*, but instead get a stream of
parsing events.  Taking Yecc as an example, imagine all your Erlang
code being ripped out of a Yecc file, and having to put it inside a
giant receive.  The interface you are talking about is all about
the INPUT of the parser, not the output.  And even then it is the
opposite of a SAX-like API, because it is a "pull" interface (the
token consumer tells the token producer "give me another token"),
whereas SAX is a "push" interface ("here is another event, like it
or not").

It is agreed that any network system is likely to receive data in
chunks so that a JSON->Erlang converter that can accept input in
chunks might be useful.









More information about the erlang-questions mailing list