From f553a84af05c526f01f574f4a4f6fec15cdb84bd Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Tue, 31 Jul 2018 13:12:50 +0200 Subject: [PATCH] Use if_list Signed-off-by: Etienne Millon --- src/action.ml | 13 +++++++------ src/jbuild.ml | 20 ++++++++++---------- src/stdune/path.ml | 20 ++++++++++---------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/action.ml b/src/action.ml index 05f75c0b..02760aae 100644 --- a/src/action.ml +++ b/src/action.ml @@ -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 diff --git a/src/jbuild.ml b/src/jbuild.ml index 97b2466a..bc02b06c 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -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) = diff --git a/src/stdune/path.ml b/src/stdune/path.ml index 32098d7c..e7d73cdd 100644 --- a/src/stdune/path.ml +++ b/src/stdune/path.ml @@ -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