Add Loc preserving version of Ordered_set_lang.Make
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
50eacb0690
commit
093cefc58b
|
@ -204,6 +204,26 @@ module Make(Key : Key)(Value : Value with type key = Key.t) = struct
|
||||||
Unordered.eval t ~parse ~standard
|
Unordered.eval t ~parse ~standard
|
||||||
end
|
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 =
|
let standard =
|
||||||
{ ast = Ast.Standard
|
{ ast = Ast.Standard
|
||||||
; loc = None
|
; loc = None
|
||||||
|
|
|
@ -46,6 +46,23 @@ module Make(Key : Key)(Value : Value with type key = Key.t)
|
||||||
: S with type value = Value.t
|
: S with type value = Value.t
|
||||||
and type 'a map = 'a Key.Map.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 standard : t
|
||||||
val is_standard : t -> bool
|
val is_standard : t -> bool
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue