Use if_list

Signed-off-by: Etienne Millon <me@emillon.org>
This commit is contained in:
Etienne Millon 2018-07-31 13:12:50 +02:00 committed by Etienne Millon
parent 6ed0b1b498
commit f553a84af0
3 changed files with 27 additions and 26 deletions

View File

@ -368,12 +368,13 @@ module Unexpanded = struct
include Make_ast(String_with_vars)(String_with_vars)(String_with_vars)(Uast) include Make_ast(String_with_vars)(String_with_vars)(String_with_vars)(Uast)
let t = let t =
let open Sexp.Of_sexp in if_list
peek_exn >>= function ~then_:t
| Template _ | Atom _ | Quoted_string _ as sexp -> ~else_:
of_sexp_errorf (Sexp.Ast.loc sexp) (loc >>| fun loc ->
"if you meant for this to be executed with bash, write (bash \"...\") instead" of_sexp_errorf
| List _ -> t loc
"if you meant for this to be executed with bash, write (bash \"...\") instead")
let check_mkdir loc path = let check_mkdir loc path =
if not (Path.is_managed path) then if not (Path.is_managed path) then

View File

@ -327,10 +327,9 @@ module Dep_conf = struct
Source_tree x) Source_tree x)
] ]
in in
peek_exn >>= function if_list
| Template _ | Atom _ | Quoted_string _ -> ~then_:t
String_with_vars.t >>| fun x -> File x ~else_:(String_with_vars.t >>| fun x -> File x)
| List _ -> t
open Sexp open Sexp
let sexp_of_t = function let sexp_of_t = function
@ -1032,12 +1031,13 @@ module Executables = struct
Sexp.Of_sexp.enum simple_representations Sexp.Of_sexp.enum simple_representations
let t = let t =
peek_exn >>= function if_list
| List _ -> ~then_:
enter (let%map mode = Mode_conf.t (enter
and kind = Binary_kind.t in (let%map mode = Mode_conf.t
{ mode; kind }) and kind = Binary_kind.t in
| _ -> simple { mode; kind }))
~else_:simple
let simple_sexp_of_t link_mode = let simple_sexp_of_t link_mode =
let is_ok (_, candidate) = let is_ok (_, candidate) =

View File

@ -602,17 +602,17 @@ let of_string ?error_loc s =
make_local_path (Local.of_string s ?error_loc) make_local_path (Local.of_string s ?error_loc)
let t = let t =
Sexp.Of_sexp.( let open Sexp.Of_sexp in
peek_exn >>= function if_list
| Template _ | Atom _ | Quoted_string _ -> ~then_:
(sum
[ "In_build_dir" , Local.t >>| in_build_dir
; "In_source_tree", Local.t >>| in_source_tree
; "External" , External.t >>| external_
])
~else_:
(* necessary for old build dirs *) (* necessary for old build dirs *)
plain_string (fun ~loc:_ s -> of_string s) (plain_string (fun ~loc:_ s -> of_string s))
| List _ ->
sum
[ "In_build_dir" , Local.t >>| in_build_dir
; "In_source_tree", Local.t >>| in_source_tree
; "External" , External.t >>| external_
])
let sexp_of_t t = let sexp_of_t t =
let constr f x y = Sexp.To_sexp.(pair string f) (x, y) in let constr f x y = Sexp.To_sexp.(pair string f) (x, y) in