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)
let t =
let open Sexp.Of_sexp in
peek_exn >>= function
| Template _ | Atom _ | Quoted_string _ as sexp ->
of_sexp_errorf (Sexp.Ast.loc sexp)
"if you meant for this to be executed with bash, write (bash \"...\") instead"
| List _ -> t
if_list
~then_:t
~else_:
(loc >>| fun loc ->
of_sexp_errorf
loc
"if you meant for this to be executed with bash, write (bash \"...\") instead")
let check_mkdir loc path =
if not (Path.is_managed path) then

View File

@ -327,10 +327,9 @@ module Dep_conf = struct
Source_tree x)
]
in
peek_exn >>= function
| Template _ | Atom _ | Quoted_string _ ->
String_with_vars.t >>| fun x -> File x
| List _ -> t
if_list
~then_:t
~else_:(String_with_vars.t >>| fun x -> File x)
open Sexp
let sexp_of_t = function
@ -1032,12 +1031,13 @@ module Executables = struct
Sexp.Of_sexp.enum simple_representations
let t =
peek_exn >>= function
| List _ ->
enter (let%map mode = Mode_conf.t
and kind = Binary_kind.t in
{ mode; kind })
| _ -> simple
if_list
~then_:
(enter
(let%map mode = Mode_conf.t
and kind = Binary_kind.t in
{ mode; kind }))
~else_:simple
let simple_sexp_of_t link_mode =
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)
let t =
Sexp.Of_sexp.(
peek_exn >>= function
| Template _ | Atom _ | Quoted_string _ ->
let open Sexp.Of_sexp in
if_list
~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 *)
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_
])
(plain_string (fun ~loc:_ s -> of_string s))
let sexp_of_t t =
let constr f x y = Sexp.To_sexp.(pair string f) (x, y) in