Add a list constructor to Dep_conf.t

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-03 23:41:56 +07:00
parent e9027b4b11
commit 4be37dd140
3 changed files with 29 additions and 17 deletions

View File

@ -241,25 +241,30 @@ module Dep_conf = struct
| Source_tree of String_with_vars.t
| Package of String_with_vars.t
| Universe
| List of t list
let t =
let t =
let sw = String_with_vars.t in
sum
[ "file" , (sw >>| fun x -> File x)
; "alias" , (sw >>| fun x -> Alias x)
; "alias_rec" , (sw >>| fun x -> Alias_rec x)
; "glob_files" , (sw >>| fun x -> Glob_files x)
; "package" , (sw >>| fun x -> Package x)
; "universe" , return Universe
; "files_recursively_in",
(Syntax.renamed_in Stanza.syntax (1, 0) ~to_:"source_tree"
>>= fun () ->
sw >>| fun x -> Source_tree x)
; "source_tree",
(Syntax.since Stanza.syntax (1, 0) >>= fun () ->
sw >>| fun x -> Source_tree x)
]
fix (fun t ->
sum
[ "file" , (sw >>| fun x -> File x)
; "alias" , (sw >>| fun x -> Alias x)
; "alias_rec" , (sw >>| fun x -> Alias_rec x)
; "glob_files" , (sw >>| fun x -> Glob_files x)
; "package" , (sw >>| fun x -> Package x)
; "universe" , return Universe
; "files_recursively_in",
(Syntax.renamed_in Stanza.syntax (1, 0) ~to_:"source_tree"
>>= fun () ->
sw >>| fun x -> Source_tree x)
; "source_tree",
(Syntax.since Stanza.syntax (1, 0) >>= fun () ->
sw >>| fun x -> Source_tree x)
; "list",
(Syntax.since Stanza.syntax (1, 0) >>= fun () ->
(repeat t) >>| fun x -> List x)
])
in
peek_exn >>= function
| Template _ | Atom _ | Quoted_string _ ->
@ -267,7 +272,7 @@ module Dep_conf = struct
| List _ -> t
open Sexp
let sexp_of_t = function
let rec sexp_of_t = function
| File t ->
List [Sexp.unsafe_atom_of_string "file" ; String_with_vars.sexp_of_t t]
| Alias t ->
@ -286,6 +291,9 @@ module Dep_conf = struct
String_with_vars.sexp_of_t t]
| Universe ->
Sexp.unsafe_atom_of_string "universe"
| List ts ->
List (Sexp.unsafe_atom_of_string "list"
:: (List.map ~f:sexp_of_t ts))
end
module Preprocess = struct

View File

@ -90,6 +90,7 @@ module Dep_conf : sig
| Source_tree of String_with_vars.t
| Package of String_with_vars.t
| Universe
| List of t list
val t : t Sexp.Of_sexp.t
val sexp_of_t : t -> Sexp.t

View File

@ -487,7 +487,7 @@ module Deps = struct
let loc = String_with_vars.loc s in
Alias.of_user_written_path ~loc ((expand_vars_path t ~scope ~dir s))
let dep t ~scope ~dir = function
let rec dep t ~scope ~dir = function
| File s ->
let path = expand_vars_path t ~scope ~dir s in
Build.path path
@ -521,6 +521,9 @@ module Deps = struct
| Universe ->
Build.path Build_system.universe_file
>>^ fun () -> []
| List ts ->
Build.all (List.map ~f:(dep t ~scope ~dir) ts)
>>^ List.concat
let interpret t ~scope ~dir l =
Build.all (List.map l ~f:(dep t ~scope ~dir))