From 093cefc58b47d07022f2cffa82e44149916c906d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 22 Jul 2018 18:30:31 +0200 Subject: [PATCH] Add Loc preserving version of Ordered_set_lang.Make Signed-off-by: Rudi Grinberg --- src/ordered_set_lang.ml | 20 ++++++++++++++++++++ src/ordered_set_lang.mli | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/ordered_set_lang.ml b/src/ordered_set_lang.ml index 393f7a76..4881b025 100644 --- a/src/ordered_set_lang.ml +++ b/src/ordered_set_lang.ml @@ -204,6 +204,26 @@ module Make(Key : Key)(Value : Value with type key = Key.t) = struct Unordered.eval t ~parse ~standard end +module Make_loc(Key : Key)(Value : Value with type key = Key.t) = struct + module No_loc = Make(Key)(struct + type t = Loc.t * Value.t + type key = Key.t + let key (_loc, s) = Value.key s + end) + + let loc_parse f ~loc s = (loc, f ~loc s) + + let eval t ~parse ~standard = + No_loc.eval t + ~parse:(loc_parse parse) + ~standard:(List.map standard ~f:(fun x -> (Loc.none, x))) + + let eval_unordered t ~parse ~standard = + No_loc.eval_unordered t + ~parse:(loc_parse parse) + ~standard:(Key.Map.map standard ~f:(fun x -> (Loc.none, x))) +end + let standard = { ast = Ast.Standard ; loc = None diff --git a/src/ordered_set_lang.mli b/src/ordered_set_lang.mli index 6ebaf74f..066ea14c 100644 --- a/src/ordered_set_lang.mli +++ b/src/ordered_set_lang.mli @@ -46,6 +46,23 @@ module Make(Key : Key)(Value : Value with type key = Key.t) : S with type value = Value.t and type 'a map = 'a Key.Map.t +(** same as [Make] but will retain the source location of the values in the + evaluated results *) +module Make_loc (Key : Key)(Value : Value with type key = Key.t) : sig + val eval + : t + -> parse:(loc:Loc.t -> string -> Value.t) + -> standard:Value.t list + -> (Loc.t * Value.t) list + + (** Same as [eval] but the result is unordered *) + val eval_unordered + : t + -> parse:(loc:Loc.t -> string -> Value.t) + -> standard:Value.t Key.Map.t + -> (Loc.t * Value.t) Key.Map.t +end + val standard : t val is_standard : t -> bool