Support incremental decoding
Supporting incremental decoding (at least for json) would help to improve decoding efficiency when dealing with streaming.
Incremental parsers are able to evaluate that a prefix of a given encoded input is "ok so far".
For example, a naive definition of an incremental parser could be:
type 'a incremental_parser = string -> 'a parsed
and 'a parsed =
| Done of { decoded: 'a; remaining: string }
(** Has succeed to parse an ['a] at some point with a prefix
of the given input.
Returns also the remaining (suffix) part of the input that
was not used to parse the ['a]. This remaining part can be
used to parse the next entry from a stream for example. *)
| Partial of 'a incremental_parser
(** Has parsed the given input but:
- could not evaluate in an ['a] (because input was incomplete)
- could not invalidate the parsing (because no syntaxe error
has been found yet).
The input is ok so far. Waits for the next entry to continue
the parsing. *)
| Failure of { input: string; message: string }
(** At some point, a syntaxe error has been encountered.
This can be improved with a proper error type intead
of the message... *)
Edited by Nicolas Raymond