From 3c15e3d041819628b1428adf116fc7ca35db9ce1 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Tue, 19 Jun 2018 15:38:50 +0100 Subject: [PATCH] Add Sexp.kind Signed-off-by: Jeremie Dimino --- src/stdune/sexp.ml | 10 ++++++++++ src/stdune/sexp.mli | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/src/stdune/sexp.ml b/src/stdune/sexp.ml index 0f6f27c3..69dad943 100644 --- a/src/stdune/sexp.ml +++ b/src/stdune/sexp.ml @@ -508,6 +508,16 @@ module Of_sexp = struct (x, []) let record t = enter (fields t) + + type kind = + | Values of Loc.t * string option + | Fields of Loc.t * string option + + let kind : type k. k context -> k -> kind * k + = fun ctx state -> + match ctx with + | Values (loc, cstr, _) -> (Values (loc, cstr), state) + | Fields (loc, cstr, _) -> (Fields (loc, cstr), state) end module type Sexpable = sig diff --git a/src/stdune/sexp.mli b/src/stdune/sexp.mli index 312b2bae..643e2aa9 100644 --- a/src/stdune/sexp.mli +++ b/src/stdune/sexp.mli @@ -118,6 +118,14 @@ module Of_sexp : sig S-expressions to parse *) val eos : (bool, _) parser + (** What is currently being parsed. The second argument is the atom + at the beginnig of the list when inside a [sum ...] or [field + ...]. *) + type kind = + | Values of Loc.t * string option + | Fields of Loc.t * string option + val kind : (kind, _) parser + (** [repeat t] use [t] to consume all remaning elements of the input until the end of sequence is reached. *) val repeat : 'a t -> 'a list t