Module Parsexp.Eager

Same as Parser but gives back a s-expression as soon as they are found in the input.

For instance you can use this function to parse a stream and stop at the first s-expression:


        exception Got_sexp of Sexp.t

        let fetch_sexp stream =
          let module P = Parsexp.Sexp_parsing.Eager in
          let rec hot_loop state stream stack =
            match Stream.peek stream with
            | None -> P.feed_eoi state stack
            | Some char ->
              let stack = P.feed state char stack in
              Stream.junk stream;
              hot_loop state stream stack
          in
          let got_sexp state sexp =
            raise_notrace (Got_sexp sexp)
          in
          let count = Stream.count stream in
          let state = P.State.create ~f:got_sexp ~no_sexp_is_error:true in
          match hot_loop state stream P.Stack.empty with
          | () -> assert false
          | exception (Got_sexp sexp) ->
            (* This test is true if the s-expression includes the last character passed to
               the parser *)
            if P.State.offset state > Stream.count stream - count then Stream.junk stream;
            sexp
      
type parsed_value = Base.Sexp.t

Values produces by the parser

module State : sig ... end
module Stack : Parsexp__.Parsexp_intf.Parser_stack
val feed : State.t ‑> Base.char ‑> Stack.t ‑> Stack.t
val feed_eoi : State.t ‑> Stack.t ‑> Base.unit
val feed_string : State.t ‑> Base.string ‑> Stack.t ‑> Stack.t
val feed_substring : State.t ‑> Base.string ‑> pos:Base.int ‑> len:Base.int ‑> Stack.t ‑> Stack.t
module Lexbuf_consumer : sig ... end