From 2d1765285af2f42579fb03b6654138427ae0fb5f Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Tue, 19 Jun 2018 14:50:51 +0100 Subject: [PATCH] Add Sexp.Of_sexp.capture Signed-off-by: Jeremie Dimino --- src/stdune/sexp.ml | 6 ++++++ src/stdune/sexp.mli | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/stdune/sexp.ml b/src/stdune/sexp.ml index 2f31ed7a..0f6f27c3 100644 --- a/src/stdune/sexp.ml +++ b/src/stdune/sexp.ml @@ -199,6 +199,12 @@ module Of_sexp = struct let ctx = Values (Ast.loc sexp, None, context) in result ctx (t ctx [sexp]) + let capture ctx state = + let f t = + result ctx (t ctx state) + in + (f, []) + let end_of_list (Values (loc, cstr, _)) = match cstr with | None -> diff --git a/src/stdune/sexp.mli b/src/stdune/sexp.mli index 095c1e1f..312b2bae 100644 --- a/src/stdune/sexp.mli +++ b/src/stdune/sexp.mli @@ -122,6 +122,9 @@ module Of_sexp : sig until the end of sequence is reached. *) val repeat : 'a t -> 'a list t + (** Capture the rest of the input for later parsing *) + val capture : ('a t -> 'a) t + (** [enter t] expect the next element of the input to be a list and parse its contents with [t]. *) val enter : 'a t -> 'a t