diff --git a/src/ordered_set_lang.ml b/src/ordered_set_lang.ml index fe5a6dc7..61c0c10b 100644 --- a/src/ordered_set_lang.ml +++ b/src/ordered_set_lang.ml @@ -19,7 +19,6 @@ type 'ast generic = type ast_expanded = (Loc.t * string, Ast.expanded) Ast.t type t = ast_expanded generic - let loc t = t.loc let parse_general sexp ~f = @@ -68,6 +67,23 @@ module type Key = sig module Map : Map.S with type key = t end +module type S = sig + type value + type 'a map + + val eval + : t + -> parse:(loc:Loc.t -> string -> value) + -> standard:value list + -> value list + + val eval_unordered + : t + -> parse:(loc:Loc.t -> string -> value) + -> standard:value map + -> value map +end + module Make(Key : Key)(Value : Value with type key = Key.t) = struct module type Named_values = sig type t @@ -129,6 +145,9 @@ module Make(Key : Key)(Value : Value with type key = Key.t) = struct | _ -> None) end) + type value = Value.t + type 'a map = 'a Key.Map.t + let eval t ~parse ~standard = if is_standard t then standard (* inline common case *) @@ -231,3 +250,13 @@ module Unexpanded = struct in { t with ast = expand t.ast } end + +module String = Make(struct + type t = string + let compare = String.compare + module Map = String_map + end)(struct + type t = string + type key = string + let key x = x + end) diff --git a/src/ordered_set_lang.mli b/src/ordered_set_lang.mli index cf975acb..5a2f4859 100644 --- a/src/ordered_set_lang.mli +++ b/src/ordered_set_lang.mli @@ -22,23 +22,30 @@ module type Key = sig module Map : Map.S with type key = t end -module Make(Key : Key)(Value : Value with type key = Key.t) : sig - (** Evaluate an ordered set. [standard] is the interpretation of [:standard] inside the - DSL. *) +module type S = sig + (** Evaluate an ordered set. [standard] is the interpretation of [:standard] + inside the DSL. *) + type value + type 'a map + val eval : t - -> parse:(loc:Loc.t -> string -> Value.t) - -> standard:Value.t list - -> Value.t list + -> parse:(loc:Loc.t -> string -> value) + -> standard:value list + -> value 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 - -> Value.t Key.Map.t + -> parse:(loc:Loc.t -> string -> value) + -> standard:value map + -> value map end +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 + val standard : t val is_standard : t -> bool @@ -63,3 +70,5 @@ module Unexpanded : sig -> f:(String_with_vars.t -> string) -> expanded end with type expanded := t + +module String : S with type value = string and type 'a map = 'a String_map.t diff --git a/src/super_context.ml b/src/super_context.ml index ca13e310..eb6f6e7b 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -669,16 +669,6 @@ module Action = struct | fail :: _ -> Build.fail fail >>> build end -module Eval_strings = Ordered_set_lang.Make(struct - type t = string - let compare = String.compare - module Map = String_map - end)(struct - type t = string - type key = string - let key x = x - end) - let expand_and_eval_set t ~scope ~dir ?extra_vars set ~standard = let open Build.O in let f = expand_vars t ~scope ~dir ?extra_vars in @@ -688,11 +678,11 @@ let expand_and_eval_set t ~scope ~dir ?extra_vars set ~standard = let set = Ordered_set_lang.Unexpanded.expand set ~files_contents:String_map.empty ~f in - Build.return (Eval_strings.eval set ~standard ~parse) + Build.return (Ordered_set_lang.String.eval set ~standard ~parse) | files -> let paths = List.map files ~f:(Path.relative dir) in Build.all (List.map paths ~f:Build.read_sexp) >>^ fun sexps -> let files_contents = List.combine files sexps |> String_map.of_list_exn in let set = Ordered_set_lang.Unexpanded.expand set ~files_contents ~f in - Eval_strings.eval set ~standard ~parse + Ordered_set_lang.String.eval set ~standard ~parse