Make the types of expanders uniform everywhere

No labels, and consistent parameter order

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-13 11:51:33 +02:00
parent 0db9356692
commit 62e7684f3b
6 changed files with 16 additions and 20 deletions

View File

@ -83,7 +83,7 @@ module Unexpanded : sig
: t
-> dir:Path.t
-> map_exe:(Path.t -> Path.t)
-> f:(String_with_vars.Var.t -> Syntax.Version.t -> Value.t list option)
-> f:(Value.t list option String_with_vars.expander)
-> Unresolved.t
end
@ -91,7 +91,7 @@ module Unexpanded : sig
: t
-> dir:Path.t
-> map_exe:(Path.t -> Path.t)
-> f:(String_with_vars.Var.t -> Syntax.Version.t -> Value.t list option)
-> f:(Value.t list option String_with_vars.expander)
-> Partial.t
end

View File

@ -187,7 +187,7 @@ module Map = struct
Syntax.Error.deleted_in (String_with_vars.Var.loc pform)
Stanza.syntax syntax_version ~what:(describe pform) ?repl
let expand t ~syntax_version ~pform =
let expand t pform syntax_version =
match String_with_vars.Var.payload pform with
| None ->
Option.map (expand t.vars ~syntax_version ~pform) ~f:(fun x ->

View File

@ -48,11 +48,7 @@ module Map : sig
val input_file : Path.t -> t
val expand
: t
-> syntax_version:Syntax.Version.t
-> pform:String_with_vars.Var.t
-> Expansion.t option
val expand : t -> Expansion.t option String_with_vars.expander
val empty : t
end

View File

@ -264,6 +264,8 @@ let partial_expand
end
| _ -> loop [] [] template.parts
type 'a expander = Var.t -> Syntax.Version.t -> 'a
let expand t ~mode ~dir ~f =
match
partial_expand t ~mode ~dir ~f:(fun var syntax_version ->

View File

@ -64,16 +64,18 @@ module Var : sig
val describe : t -> string
end
type 'a expander = Var.t -> Syntax.Version.t -> 'a
val expand
: t
-> mode:'a Mode.t
-> dir:Path.t
-> f:(Var.t -> Syntax.Version.t -> Value.t list option)
-> f:(Value.t list option expander)
-> 'a
val partial_expand
: t
-> mode:'a Mode.t
-> dir:Path.t
-> f:(Var.t -> Syntax.Version.t -> Value.t list option)
-> f:(Value.t list option expander)
-> 'a Partial.t

View File

@ -97,8 +97,8 @@ let expand_ocaml_config t pform name =
let expand_vars t ~mode ~scope ~dir ?(bindings=Pform.Map.empty) s =
String_with_vars.expand ~mode ~dir s ~f:(fun pform syntax_version ->
(match Pform.Map.expand bindings ~syntax_version ~pform with
| None -> Pform.Map.expand t.pforms ~syntax_version ~pform
(match Pform.Map.expand bindings pform syntax_version with
| None -> Pform.Map.expand t.pforms pform syntax_version
| Some _ as x -> x)
|> Option.map ~f:(function
| Pform.Expansion.Var (Values l) -> l
@ -591,9 +591,7 @@ module Expander : sig
-> targets_written_by_user:targets
-> map_exe:(Path.t -> Path.t)
-> bindings:Pform.Map.t
-> String_with_vars.Var.t
-> Syntax.Version.t
-> Value.t list option
-> Value.t list option String_with_vars.expander
val with_expander : (expander -> 'a) -> 'a * Resolved_forms.t
end = struct
@ -643,9 +641,7 @@ end = struct
-> targets_written_by_user:targets
-> map_exe:(Path.t -> Path.t)
-> bindings:Pform.Map.t
-> String_with_vars.Var.t
-> Syntax.Version.t
-> Value.t list option
-> Value.t list option String_with_vars.expander
let path_exp path = [Value.Path path]
let str_exp str = [Value.String str]
@ -663,7 +659,7 @@ end = struct
let loc = String_with_vars.Var.loc pform in
let key = String_with_vars.Var.full_name pform in
let res =
Pform.Map.expand bindings ~syntax_version ~pform
Pform.Map.expand bindings pform syntax_version
|> Option.bind ~f:(function
| Pform.Expansion.Var (Values l) -> Some l
| Macro (Ocaml_config, s) -> Some (expand_ocaml_config sctx pform s)
@ -819,7 +815,7 @@ module Action = struct
match String.Map.find dynamic_expansions key with
| Some _ as opt -> opt
| None ->
Option.map (Pform.Map.expand bindings ~syntax_version ~pform) ~f:(function
Option.map (Pform.Map.expand bindings pform syntax_version) ~f:(function
| Var Named_local ->
begin match Jbuild.Bindings.find deps_written_by_user key with
| None ->