ocaml-dune / csexp

Minimal support for Canonical S-expressions
MIT License
27 stars 7 forks source link

New parsing functor #8

Closed ghost closed 4 years ago

ghost commented 4 years ago

Following the issue raised here, this PR proposes a new parsing API where end of input conditions are explicit:

    (** [read_char source] reads a single character from the input. Returns
        [None] if the end of input has been reached..*)
    val read_char : t -> char option Monad.t

    (** [read_string source size] reads exactly [size] bytes from [source] and
        return them as a string. Returns [None] if there are less than [size]
        characters available in the input. *)
    val read_string : t -> int -> string option Monad.t

This allows to react to end-of-input conditions without swallowing other kind of IO errors.

ghost commented 4 years ago

/cc @rgrinberg @mefyl

ghost commented 4 years ago

Yeah, that's what I'm thinking. I'm just trying the other approach with the "feed" API to compare.

ghost commented 4 years ago

I wrote another alternative in #9. I prefer the other one, so I'm closing this one.