Add Loc preserving version of Ordered_set_lang.Make

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-22 18:30:31 +02:00
parent 50eacb0690
commit 093cefc58b
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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