Temporarily remove (foreach ...)
Currently (foreach ...) is too general and variables can be used anywhere inside S-expressions. We need to sort out how we are going to handle meta-programming first as this might impact how we implement (foreach ...). In any case, it's better not to have it in 1.0.0.
This commit is contained in:
parent
9eb215055e
commit
f713c7ab98
|
@ -841,57 +841,6 @@ module Alias_conf = struct
|
|||
})
|
||||
end
|
||||
|
||||
module Foreach = struct
|
||||
let rec pattern = function
|
||||
| List (_, l) -> Sexp.List (List.map l ~f:pattern)
|
||||
| Atom (loc, s) ->
|
||||
match String_with_vars.of_string ~loc s |> String_with_vars.just_a_var with
|
||||
| None ->
|
||||
Loc.fail loc "atom of the form ${...} expected"
|
||||
| Some v -> Atom v
|
||||
|
||||
let pattern sexp = (Sexp.Ast.loc sexp, pattern sexp)
|
||||
|
||||
let values = list (fun x -> x)
|
||||
|
||||
let rec pattern_match env (patt : Sexp.t) (value : Sexp.Ast.t) =
|
||||
match patt with
|
||||
| Atom p -> begin
|
||||
match value with
|
||||
| List (loc, _) -> Loc.fail loc "atom expected"
|
||||
| Atom (_, s) -> (p, s) :: env
|
||||
end
|
||||
| List p ->
|
||||
match value with
|
||||
| Atom (loc, _) -> Loc.fail loc "list expected"
|
||||
| List (loc, l) ->
|
||||
if List.length l <> List.length p then
|
||||
Loc.fail loc "list of length %d expected" (List.length p)
|
||||
else
|
||||
List.fold_left2 p l ~init:env ~f:pattern_match
|
||||
|
||||
let rec expand_sexp f = function
|
||||
| List (loc, l) -> List (loc, expand_sexps f l)
|
||||
| Atom (loc, s) ->
|
||||
Atom (loc,
|
||||
String_with_vars.of_string ~loc s
|
||||
|> String_with_vars.expand ~f)
|
||||
|
||||
and expand_sexps f = function
|
||||
| [] -> []
|
||||
| sexp :: sexps -> expand_sexp f sexp :: expand_sexps f sexps
|
||||
|
||||
let expand (loc, pat) vals sexps =
|
||||
List.concat_map vals ~f:(fun value ->
|
||||
let env =
|
||||
match String_map.of_alist (pattern_match [] pat value) with
|
||||
| Ok env -> env
|
||||
| Error (dup, _, _) ->
|
||||
Loc.fail loc "variable %s appears twice in this pattern" dup
|
||||
in
|
||||
expand_sexps (fun _loc v -> String_map.find v env) sexps)
|
||||
end
|
||||
|
||||
module Stanza = struct
|
||||
type t =
|
||||
| Library of Library.t
|
||||
|
@ -908,7 +857,7 @@ module Stanza = struct
|
|||
| None -> [Executables exe]
|
||||
| Some i -> [Executables exe; Install i]
|
||||
|
||||
let rec v1 pkgs =
|
||||
let v1 pkgs =
|
||||
sum
|
||||
[ cstr "library" (Library.v1 pkgs @> nil) (fun x -> [Library x])
|
||||
; cstr "executable" (Executables.v1_single pkgs @> nil) execs
|
||||
|
@ -919,10 +868,6 @@ module Stanza = struct
|
|||
; cstr "menhir" (Menhir.v1 @> nil) (fun x -> rules (Menhir.v1_to_rule x))
|
||||
; cstr "install" (Install_conf.v1 pkgs @> nil) (fun x -> [Install x])
|
||||
; cstr "alias" (Alias_conf.v1 pkgs @> nil) (fun x -> [Alias x])
|
||||
; cstr_rest "foreach" (Foreach.pattern @> Foreach.values @> nil) (fun x -> x)
|
||||
(fun pat vals sexps ->
|
||||
let sexps = Foreach.expand pat vals sexps in
|
||||
List.concat_map sexps ~f:(v1 pkgs))
|
||||
(* Just for validation and error messages *)
|
||||
; cstr "jbuild_version" (Jbuild_version.t @> nil) (fun _ -> [])
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue