8000 feature: add [not] to blang by rgrinberg · Pull Request #5610 · ocaml/dune · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feature: add [not] to blang #5610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
3.2.0 (Unreleased)
-----------------

- Add `not` to boolean expressions (#5610, fix #5503, @rgrinberg)

- Allow to specify `--prefix` via the environment variable
`DUNE_INSTALL_PREFIX` (#5589, @vapourismo)

Expand Down
1 change: 1 addition & 0 deletions doc/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Dune can evaluate. Here's a semi-formal specification of the language:
expr := (and <expr>+)
| (or <expr>+)
| (<op> <template> <template>)
| (not <expr>)
| <template>

After an expression is evaluated, it must be exactly the string ``true`` or
Expand Down
6 changes: 6 additions & 0 deletions src/dune_rules/blang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ end

type t =
| Const of bool
| Not of t
| Expr of String_with_vars.t
| And of t list
| Or of t list
Expand All @@ -50,6 +51,7 @@ let rec eval t ~dir ~f =
[ Pp.text "This value must be either true or false" ])
| And xs -> Memo.List.map xs ~f:(eval ~f ~dir) >>| List.for_all ~f:Fun.id
| Or xs -> Memo.List.map xs ~f:(eval ~f ~dir) >>| List.exists ~f:Fun.id
| Not t -> eval t ~f ~dir >>| not
| Compare (op, x, y) ->
let+ x = String_with_vars.expand x ~mode:Many ~dir ~f
and+ y = String_with_vars.expand y ~mode:Many ~dir ~f in
Expand All @@ -59,6 +61,7 @@ let rec to_dyn =
let open Dyn in
function
| Const b -> variant "Const" [ bool b ]
| Not t -> variant "Not" [ to_dyn t ]
| Expr e -> variant "Expr" [ String_with_vars.to_dyn e ]
| And t -> variant "And" (List.map ~f:to_dyn t)
| Or t -> variant "Or" (List.map ~f:to_dyn t)
Expand All @@ -83,6 +86,9 @@ let decode_gen decode_string =
sum ~force_parens:true
(("or", repeat t >>| fun x -> Or x)
:: ("and", repeat t >>| fun x -> And x)
:: ( "not"
, Dune_lang.Syntax.since Stanza.syntax (3, 2) >>> t >>| fun x ->
Not x )
:: ops)
<|> let+ v = decode_string in
Expr v)
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/blang.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end

type t =
| Const of bool
| Not of t
| Expr of String_with_vars.t
| And of t list
| Or of t list
Expand Down
17 changes: 17 additions & 0 deletions test/blackbox-tests/test-cases/enabled_if-exec.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,20 @@ For dune >= 2.7 context_name allowed
$ dune exec ./foo.exe --root var_context_name
Entering directory 'var_context_name'
bar

For dune >= 3.2, negating expressions is allowed
$ mkdir negated
$ cat > negated/dune-project <<EOF
> (lang dune 3.2)
> EOF
$ cat > negated/dune <<EOF
> (executable
> (name foo)
> (enabled_if (not false)))
> EOF
$ cat > negated/foo.ml <<EOF
> print_endline "runs";;
> EOF
$ dune exec ./foo.exe --root negated
Entering directory 'negated'
runs
0