-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This field controls whether the alias/test will be run or not. Boolean expressions are defined using the Blang.t type. This type represents simple boolean expressions that become useful when we allow to interpolate variables into them. Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
- Loading branch information
Showing
14 changed files
with
269 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
open! Stdune | ||
|
||
module Op = struct | ||
type t = | ||
| Eq | ||
| Gt | ||
| Gte | ||
| Lte | ||
| Lt | ||
| Neq | ||
|
||
let eval t (x : Ordering.t) = | ||
match t, x with | ||
| (Eq | Gte | Lte) , Eq | ||
| (Lt | Lte) , Lt | ||
| (Gt | Gte) , Gt -> true | ||
| _, _ -> false | ||
end | ||
|
||
type 'a t = | ||
| Expr of 'a | ||
| And of 'a t list | ||
| Or of 'a t list | ||
| Compare of Op.t * 'a * 'a | ||
|
||
type 'a expander = | ||
{ f : 'value. mode:'value String_with_vars.Mode.t | ||
-> 'a | ||
-> Loc.t * 'value | ||
} | ||
|
||
let rec eval_bool t ~dir ~(f : 'a expander) = | ||
match t with | ||
| Expr a -> | ||
begin match f.f ~mode:Single a with | ||
| _, String "true" -> true | ||
| _, String "false" -> false | ||
| loc, _ -> Loc.fail loc "This value must be either true or false" | ||
end | ||
| And xs -> List.for_all ~f:(eval_bool ~f ~dir) xs | ||
| Or xs -> List.exists ~f:(eval_bool ~f ~dir) xs | ||
| Compare (op, x, y) -> | ||
let ((_, x), (_, y)) = (f.f ~mode:Many x, f.f ~mode:Many y) in | ||
Value.L.compare_vals ~dir x y | ||
|> Op.eval op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
open Stdune | ||
|
||
module Op : sig | ||
type t = | ||
| Eq | ||
| Gt | ||
| Gte | ||
| Lte | ||
| Lt | ||
| Neq | ||
end | ||
|
||
type 'a t = | ||
| Expr of 'a | ||
| And of 'a t list | ||
| Or of 'a t list | ||
| Compare of Op.t * 'a * 'a | ||
|
||
type 'a expander = | ||
{ f : 'value. mode:'value String_with_vars.Mode.t | ||
-> 'a | ||
-> Loc.t * 'value | ||
} | ||
|
||
val eval_bool : 'a t -> dir:Path.t -> f:'a expander -> bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type t = bool | ||
|
||
let compare x y = | ||
match x, y with | ||
| true, true | ||
| false, false -> Ordering.Eq | ||
| true, false -> Gt | ||
| false, true -> Lt | ||
|
||
let to_string = string_of_bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type t = bool | ||
|
||
val compare : t -> t -> Ordering.t | ||
|
||
val to_string : t -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.