From bae8f4105540c548ece3f387c5e58583ad119116 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 5 Nov 2019 19:06:36 +0900 Subject: [PATCH] Use Syntax.deleted_in for error Signed-off-by: Rudi Grinberg --- src/dune/dune_file.ml | 19 +++++++------------ src/dune_lang/syntax.ml | 4 ++-- src/dune_lang/syntax.mli | 6 +++++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/dune/dune_file.ml b/src/dune/dune_file.ml index 558af727230f..a8bcb6cf2407 100644 --- a/src/dune/dune_file.ml +++ b/src/dune/dune_file.ml @@ -1993,18 +1993,13 @@ module Alias_conf = struct and+ package = field_o "package" Pkg.decode and+ action = field_o "action" - (let* syntax_version = Dune_lang.Syntax.get_exn Stanza.syntax - and+ loc = loc in - let deleted_in_version = (2, 0) in - if syntax_version < deleted_in_version then - located Action_dune_lang.decode - else - let what = "action field" in - let repl = - [ Pp.text "Use a rule stanza with the alias field instead" ] - in - Dune_lang.Syntax.Error.deleted_in loc Stanza.syntax - deleted_in_version ~what ~repl) + (let repl = + [ Pp.text "Use a rule stanza with the alias field instead" ] + in + let* () = + Dune_lang.Syntax.deleted_in ~repl Stanza.syntax (2, 0) + in + located Action_dune_lang.decode) and+ loc = loc and+ locks = field "locks" (repeat String_with_vars.decode) ~default:[] and+ deps = diff --git a/src/dune_lang/syntax.ml b/src/dune_lang/syntax.ml index 600be43d8f6c..850a977659c6 100644 --- a/src/dune_lang/syntax.ml +++ b/src/dune_lang/syntax.ml @@ -170,14 +170,14 @@ let desc () = | Values (loc, Some s) -> (loc, sprintf "'%s'" s) | Fields (loc, Some s) -> (loc, sprintf "Field '%s'" s) -let deleted_in ?(extra_info = "") t ver = +let deleted_in ?(extra_info = "") ?repl t ver = let open Version.Infix in let* current_ver = get_exn t in if current_ver < ver then return () else let* loc, what = desc () in - Error.deleted_in ~extra_info loc t ver ~what + Error.deleted_in ?repl ~extra_info loc t ver ~what let deprecated_in ?(extra_info = "") t ver = let open Version.Infix in diff --git a/src/dune_lang/syntax.mli b/src/dune_lang/syntax.mli index b83edfa116bf..895587bbb7ff 100644 --- a/src/dune_lang/syntax.mli +++ b/src/dune_lang/syntax.mli @@ -78,7 +78,11 @@ val greatest_supported_version : t -> Version.t (** Indicate the field/constructor being parsed was deleted in the given version *) val deleted_in : - ?extra_info:string -> t -> Version.t -> (unit, _) Decoder.parser + ?extra_info:string + -> ?repl:User_message.Style.t Pp.t list + -> t + -> Version.t + -> (unit, _) Decoder.parser (** Indicate the field/constructor being parsed was deprecated in the given version *)