Simplify Var.t definition
Remove all gatd's and the extra record type Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
972406a0dc
commit
73cc3b1e7c
|
@ -34,31 +34,6 @@ module Env_node = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
module Var = struct
|
module Var = struct
|
||||||
module Opt = struct
|
|
||||||
type with_value
|
|
||||||
type no_value
|
|
||||||
|
|
||||||
type (_, _) t =
|
|
||||||
| None0 : (no_value , _) t
|
|
||||||
| Some0 : 'a -> (with_value, 'a) t
|
|
||||||
|
|
||||||
let some
|
|
||||||
: 'a. (with_value, 'a) t -> 'a option
|
|
||||||
= fun (Some0 x) -> Some x
|
|
||||||
|
|
||||||
let discard
|
|
||||||
: (no_value, _) t -> unit
|
|
||||||
= fun None0 -> ()
|
|
||||||
end
|
|
||||||
|
|
||||||
module Info = struct
|
|
||||||
type _ t =
|
|
||||||
| Nothing : Opt.with_value t
|
|
||||||
| Since : Syntax.Version.t -> Opt.with_value t
|
|
||||||
| Deleted_in : Syntax.Version.t -> Opt.with_value t
|
|
||||||
| Renamed_in : Syntax.Version.t * string -> Opt.no_value t
|
|
||||||
end
|
|
||||||
|
|
||||||
module Kind = struct
|
module Kind = struct
|
||||||
type t =
|
type t =
|
||||||
| Values of Value.t list
|
| Values of Value.t list
|
||||||
|
@ -90,35 +65,19 @@ module Var = struct
|
||||||
| Path_no_dep
|
| Path_no_dep
|
||||||
end
|
end
|
||||||
|
|
||||||
type ('a, 'b) t' =
|
type 'a t =
|
||||||
{ kind: ('a, 'b) Opt.t
|
| Nothing of 'a
|
||||||
; info: 'a Info.t
|
| Since of 'a * Syntax.Version.t
|
||||||
}
|
| Deleted_in of 'a * Syntax.Version.t
|
||||||
|
| Renamed_in of Syntax.Version.t * string
|
||||||
type _ t = V : ('a, 'b) t' -> 'b t
|
|
||||||
|
|
||||||
module Map = struct
|
module Map = struct
|
||||||
type nonrec 'a t = 'a t String.Map.t
|
type nonrec 'a t = 'a t String.Map.t
|
||||||
|
|
||||||
let values v =
|
let values v = Nothing (Kind.Values v)
|
||||||
V { kind = Some0 (Kind.Values v)
|
let renamed_in ~new_name ~version = Renamed_in (version, new_name)
|
||||||
; info = Info.Nothing
|
let deleted_in ~version kind = Deleted_in (kind, version)
|
||||||
}
|
let since ~version v = Since (v, version)
|
||||||
|
|
||||||
let renamed_in ~new_name ~version =
|
|
||||||
V { kind = None0
|
|
||||||
; info = Info.Renamed_in (version, new_name)
|
|
||||||
}
|
|
||||||
|
|
||||||
let deleted_in ~version kind =
|
|
||||||
V { kind = Some0 kind
|
|
||||||
; info = Info.Deleted_in version
|
|
||||||
}
|
|
||||||
|
|
||||||
let since ~version v =
|
|
||||||
V { kind = Some0 v
|
|
||||||
; info = Info.Since version
|
|
||||||
}
|
|
||||||
|
|
||||||
let static_vars =
|
let static_vars =
|
||||||
[ "first-dep", since ~version:(1, 0) Kind.First_dep
|
[ "first-dep", since ~version:(1, 0) Kind.First_dep
|
||||||
|
@ -133,11 +92,7 @@ module Var = struct
|
||||||
]
|
]
|
||||||
|
|
||||||
let forms =
|
let forms =
|
||||||
let form kind =
|
let form kind = Nothing kind in
|
||||||
V { info = Info.Nothing
|
|
||||||
; kind = Some0 kind
|
|
||||||
}
|
|
||||||
in
|
|
||||||
let open Form in
|
let open Form in
|
||||||
[ "exe", form Exe
|
[ "exe", form Exe
|
||||||
; "bin", form Bin
|
; "bin", form Bin
|
||||||
|
@ -231,12 +186,11 @@ module Var = struct
|
||||||
| Single v -> v
|
| Single v -> v
|
||||||
| Pair (v, _) -> v
|
| Pair (v, _) -> v
|
||||||
in
|
in
|
||||||
let f (V { kind; info}) =
|
Option.bind (String.Map.find t name) ~f:(function
|
||||||
match info with
|
| Nothing v -> Some v
|
||||||
| Info.Nothing -> Opt.some kind
|
| Since (v, min_version) ->
|
||||||
| Info.Since min_version ->
|
|
||||||
if syntax_version >= min_version then
|
if syntax_version >= min_version then
|
||||||
Opt.some kind
|
Some v
|
||||||
else
|
else
|
||||||
String_with_vars.Var.fail var ~f:(fun var ->
|
String_with_vars.Var.fail var ~f:(fun var ->
|
||||||
sprintf "Variable %s is available in since version %s. \
|
sprintf "Variable %s is available in since version %s. \
|
||||||
|
@ -244,8 +198,7 @@ module Var = struct
|
||||||
var
|
var
|
||||||
(Syntax.Version.to_string min_version)
|
(Syntax.Version.to_string min_version)
|
||||||
(Syntax.Version.to_string syntax_version))
|
(Syntax.Version.to_string syntax_version))
|
||||||
| Info.Renamed_in (in_version, new_name) -> begin
|
| Renamed_in (in_version, new_name) -> begin
|
||||||
Opt.discard kind;
|
|
||||||
if syntax_version >= in_version then
|
if syntax_version >= in_version then
|
||||||
String_with_vars.Var.fail var ~f:(fun old_name ->
|
String_with_vars.Var.fail var ~f:(fun old_name ->
|
||||||
sprintf "Variable %s has been renamed to %s since %s"
|
sprintf "Variable %s has been renamed to %s since %s"
|
||||||
|
@ -256,18 +209,16 @@ module Var = struct
|
||||||
expand t ~syntax_version:in_version
|
expand t ~syntax_version:in_version
|
||||||
~var:(String_with_vars.Var.rename var ~new_name)
|
~var:(String_with_vars.Var.rename var ~new_name)
|
||||||
end
|
end
|
||||||
| Info.Deleted_in in_version ->
|
| Deleted_in (v, in_version) ->
|
||||||
if syntax_version < in_version then
|
if syntax_version < in_version then
|
||||||
Opt.some kind
|
Some v
|
||||||
else
|
else
|
||||||
String_with_vars.Var.fail var ~f:(fun var ->
|
String_with_vars.Var.fail var ~f:(fun var ->
|
||||||
sprintf "Variable %s has been deleted in version %s. \
|
sprintf "Variable %s has been deleted in version %s. \
|
||||||
Current version is: %s"
|
Current version is: %s"
|
||||||
var
|
var
|
||||||
(Syntax.Version.to_string in_version)
|
(Syntax.Version.to_string in_version)
|
||||||
(Syntax.Version.to_string syntax_version))
|
(Syntax.Version.to_string syntax_version)))
|
||||||
in
|
|
||||||
Option.bind (String.Map.find t name) ~f
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue