Make the set language more future proof (#930)
- forbid list starting by an atom not starting with - or : - allow to avoid the toplevel parentheses in dune files Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
parent
e886e948b7
commit
7e79e2870d
6
bin/dune
6
bin/dune
|
@ -1,13 +1,13 @@
|
||||||
(library
|
(library
|
||||||
(name main)
|
(name main)
|
||||||
(modules (main))
|
(modules main)
|
||||||
(libraries unix dune cmdliner))
|
(libraries unix dune cmdliner))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(name main_dune)
|
(name main_dune)
|
||||||
(public_name dune)
|
(public_name dune)
|
||||||
(package dune)
|
(package dune)
|
||||||
(modules (main_dune))
|
(modules main_dune)
|
||||||
(libraries which_program_dune main)
|
(libraries which_program_dune main)
|
||||||
(preprocess no_preprocessing))
|
(preprocess no_preprocessing))
|
||||||
|
|
||||||
|
@ -15,6 +15,6 @@
|
||||||
(name main_jbuilder)
|
(name main_jbuilder)
|
||||||
(public_name jbuilder)
|
(public_name jbuilder)
|
||||||
(package dune)
|
(package dune)
|
||||||
(modules (main_jbuilder))
|
(modules main_jbuilder)
|
||||||
(libraries which_program_jbuilder main)
|
(libraries which_program_jbuilder main)
|
||||||
(preprocess no_preprocessing))
|
(preprocess no_preprocessing))
|
||||||
|
|
|
@ -764,6 +764,19 @@ syntax ``(:include <filename>)``. This is useful for instance when you need to
|
||||||
run a script to figure out some compilation flags. ``<filename>`` is expected to
|
run a script to figure out some compilation flags. ``<filename>`` is expected to
|
||||||
contain a single S-expression and cannot contain ``(:include ...)`` forms.
|
contain a single S-expression and cannot contain ``(:include ...)`` forms.
|
||||||
|
|
||||||
|
Note that inside an ordered set, the first element of a list cannot be
|
||||||
|
an atom except if it starts with `-` or `:`. The reason for this is
|
||||||
|
that we are planning to add simple programmatic features in the
|
||||||
|
futures so that one may write:
|
||||||
|
|
||||||
|
.. code::
|
||||||
|
|
||||||
|
(flags (if (>= %{ocaml_version} 4.06) ...))
|
||||||
|
|
||||||
|
This restriction will allow to add this feature without introducing a
|
||||||
|
breaking changes. If you want to write a list where the first element
|
||||||
|
doesn't start by `-`, you can simply quote it: ``("x" y z)``.
|
||||||
|
|
||||||
Most fields using the ordered set language also support `Variables expansion`_.
|
Most fields using the ordered set language also support `Variables expansion`_.
|
||||||
Variables are expanded after the set language is interpreted.
|
Variables are expanded after the set language is interpreted.
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ module Parse = struct
|
||||||
|
|
||||||
let generic ~inc ~elt =
|
let generic ~inc ~elt =
|
||||||
let open Stanza.Of_sexp in
|
let open Stanza.Of_sexp in
|
||||||
let rec one () =
|
let rec one (kind : Stanza.File_kind.t) =
|
||||||
peek_exn >>= function
|
peek_exn >>= function
|
||||||
| Atom (loc, A "\\") -> Loc.fail loc "unexpected \\"
|
| Atom (loc, A "\\") -> Loc.fail loc "unexpected \\"
|
||||||
| (Atom (_, A "") | Quoted_string (_, _)) | Template _ ->
|
| (Atom (_, A "") | Quoted_string (_, _)) | Template _ ->
|
||||||
|
@ -45,19 +45,30 @@ module Parse = struct
|
||||||
| _ ->
|
| _ ->
|
||||||
elt >>| fun x -> Element x
|
elt >>| fun x -> Element x
|
||||||
end
|
end
|
||||||
| List (_, Atom (_, A ":include") :: _) -> inc
|
| List (_, Atom (loc, A s) :: _) -> begin
|
||||||
| List _ -> enter (many [])
|
match s, kind with
|
||||||
and many acc =
|
| ":include", _ -> inc
|
||||||
|
| s, Dune when s <> "" && s.[0] <> '-' && s.[0] <> ':' ->
|
||||||
|
Loc.fail loc
|
||||||
|
"This atom must be quoted because it is the first element \
|
||||||
|
of a list and doesn't start with - or :"
|
||||||
|
| _ -> enter (many [] kind)
|
||||||
|
end
|
||||||
|
| List _ -> enter (many [] kind)
|
||||||
|
and many acc kind =
|
||||||
peek >>= function
|
peek >>= function
|
||||||
| None -> return (Union (List.rev acc))
|
| None -> return (Union (List.rev acc))
|
||||||
| Some (Atom (_, A "\\")) ->
|
| Some (Atom (_, A "\\")) ->
|
||||||
junk >>> many [] >>| fun to_remove ->
|
junk >>> many [] kind >>| fun to_remove ->
|
||||||
Diff (Union (List.rev acc), to_remove)
|
Diff (Union (List.rev acc), to_remove)
|
||||||
| Some _ ->
|
| Some _ ->
|
||||||
one () >>= fun x ->
|
one kind >>= fun x ->
|
||||||
many (x :: acc)
|
many (x :: acc) kind
|
||||||
in
|
in
|
||||||
one ()
|
Stanza.file_kind () >>= fun kind ->
|
||||||
|
match kind with
|
||||||
|
| Dune -> many [] kind
|
||||||
|
| Jbuild -> one kind
|
||||||
|
|
||||||
let with_include ~elt =
|
let with_include ~elt =
|
||||||
generic ~elt ~inc:(
|
generic ~elt ~inc:(
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
(library
|
(library
|
||||||
(name foo)
|
(name foo)
|
||||||
(c_names bar)
|
(c_names bar)
|
||||||
(modules (dummy))
|
(modules dummy)
|
||||||
(wrapped false))
|
(wrapped false))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(name test)
|
(name test)
|
||||||
(modules (:standard \ dummy))
|
(modules :standard \ dummy)
|
||||||
(libraries foo))
|
(libraries foo))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
|
|
|
@ -2,21 +2,21 @@
|
||||||
(library
|
(library
|
||||||
(name foo1)
|
(name foo1)
|
||||||
(public_name foo.1)
|
(public_name foo.1)
|
||||||
(modules (foo1))
|
(modules foo1)
|
||||||
(preprocess (pps)))
|
(preprocess (pps)))
|
||||||
|
|
||||||
; Too many drivers
|
; Too many drivers
|
||||||
(library
|
(library
|
||||||
(name foo2)
|
(name foo2)
|
||||||
(public_name foo.2)
|
(public_name foo.2)
|
||||||
(modules (foo2))
|
(modules foo2)
|
||||||
(preprocess (pps ppx1 ppx2)))
|
(preprocess (pps ppx1 ppx2)))
|
||||||
|
|
||||||
; Incompatible with Dune
|
; Incompatible with Dune
|
||||||
(library
|
(library
|
||||||
(name foo3)
|
(name foo3)
|
||||||
(public_name foo.3)
|
(public_name foo.3)
|
||||||
(modules (foo3))
|
(modules foo3)
|
||||||
(preprocess (pps ppx_other)))
|
(preprocess (pps ppx_other)))
|
||||||
|
|
||||||
(rule (with-stdout-to foo1.ml (echo "")))
|
(rule (with-stdout-to foo1.ml (echo "")))
|
||||||
|
@ -64,5 +64,5 @@
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name test_ppx_args)
|
(name test_ppx_args)
|
||||||
(modules (test_ppx_args))
|
(modules test_ppx_args)
|
||||||
(preprocess (pps -arg1 driver_print_args -arg2 -- -foo bar)))
|
(preprocess (pps -arg1 driver_print_args -arg2 -- -foo bar)))
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
(library
|
(library
|
||||||
(name foo)
|
(name foo)
|
||||||
(modules (:standard \ fake)))
|
(modules :standard \ fake))
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
$ dune build --display short
|
$ dune build --display short
|
||||||
File "dune", line 3, characters 23-27:
|
File "dune", line 3, characters 22-26:
|
||||||
Warning: Module Fake is excluded but it doesn't exist.
|
Warning: Module Fake is excluded but it doesn't exist.
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name foo_byte)
|
(name foo_byte)
|
||||||
(modules (foo_byte))
|
(modules foo_byte)
|
||||||
(modes byte)
|
(modes byte)
|
||||||
(public_name foo.byte))
|
(public_name foo.byte))
|
||||||
|
|
||||||
(executables
|
(executables
|
||||||
(names bar)
|
(names bar)
|
||||||
(modules (bar))
|
(modules bar)
|
||||||
(public_names bar)
|
(public_names bar)
|
||||||
(libraries foo))
|
(libraries foo))
|
||||||
|
|
||||||
|
@ -28,4 +28,4 @@
|
||||||
(action (echo "%{read:foo.install}")))
|
(action (echo "%{read:foo.install}")))
|
||||||
|
|
||||||
(documentation
|
(documentation
|
||||||
(mld_files (doc)))
|
(mld_files doc))
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
(library
|
(library
|
||||||
(name pas_de_bol)
|
(name pas_de_bol)
|
||||||
(public_name pas-de-bol)
|
(public_name pas-de-bol)
|
||||||
(modules (a b))
|
(modules a b)
|
||||||
(libraries plop.ca-marche-pas))
|
(libraries plop.ca-marche-pas))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
(library
|
(library
|
||||||
(name lib1)
|
(name lib1)
|
||||||
(public_name lib1)
|
(public_name lib1)
|
||||||
(modules (Lib1)))
|
(modules Lib1))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
(name runtest)
|
(name runtest)
|
||||||
|
@ -12,14 +12,14 @@
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(name test1)
|
(name test1)
|
||||||
(modules (Test1))
|
(modules Test1)
|
||||||
(libraries lib1))
|
(libraries lib1))
|
||||||
|
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name lib2)
|
(name lib2)
|
||||||
(public_name lib2)
|
(public_name lib2)
|
||||||
(modules (Lib2)))
|
(modules Lib2))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
(name runtest)
|
(name runtest)
|
||||||
|
@ -29,5 +29,5 @@
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(name test2)
|
(name test2)
|
||||||
(modules (Test2))
|
(modules Test2)
|
||||||
(libraries lib2))
|
(libraries lib2))
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
(library
|
(library
|
||||||
(name foo)
|
(name foo)
|
||||||
(modules (foo))
|
(modules foo)
|
||||||
(c_names stubs/x))
|
(c_names stubs/x))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(name bar)
|
(name bar)
|
||||||
(modules (bar))
|
(modules bar)
|
||||||
(libraries foo))
|
(libraries foo))
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
(echo "let () = print_int 42")
|
(echo "let () = print_int 42")
|
||||||
(echo "\n")
|
(echo "\n")
|
||||||
(echo "let () = print_int 43;;")))
|
(echo "let () = print_int 43;;")))
|
||||||
(flags (inline-test-runner %{library-name}
|
(flags inline-test-runner %{library-name}
|
||||||
-source-tree-root %{ROOT} -diff-cmd -))))
|
-source-tree-root %{ROOT} -diff-cmd -)))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name foo_tests)
|
(name foo_tests)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(library
|
(library
|
||||||
(name lib)
|
(name lib)
|
||||||
(modules (:standard \ test)))
|
(modules :standard \ test))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(name test)
|
(name test)
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
(library
|
(library
|
||||||
(name foo)
|
(name foo)
|
||||||
(modules (foo foo2))
|
(modules foo foo2)
|
||||||
(wrapped false)
|
(wrapped false)
|
||||||
(public_name foo))
|
(public_name foo))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name bar)
|
(name bar)
|
||||||
(public_name bar)
|
(public_name bar)
|
||||||
(modules (bar)))
|
(modules bar))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name foo_byte)
|
(name foo_byte)
|
||||||
(modules (foo_byte))
|
(modules foo_byte)
|
||||||
(modes byte)
|
(modes byte)
|
||||||
(public_name foo.byte))
|
(public_name foo.byte))
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
(library
|
(library
|
||||||
(name foo)
|
(name foo)
|
||||||
(public_name foo)
|
(public_name foo)
|
||||||
(modules (foo)))
|
(modules foo))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name bar)
|
(name bar)
|
||||||
(public_name bar)
|
(public_name bar)
|
||||||
(libraries foo)
|
(libraries foo)
|
||||||
(modules (bar)))
|
(modules bar))
|
||||||
|
|
||||||
(rule
|
(rule
|
||||||
(with-stdout-to foo.ml
|
(with-stdout-to foo.ml
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
((name w_omp_driver)
|
((name w_omp_driver)
|
||||||
(modules (w_omp_driver))
|
(modules w_omp_driver)
|
||||||
(preprocess (pps (fooppx -flag (-arg omp))))))
|
(preprocess (pps (fooppx -flag (-arg omp))))))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
((name w_ppx_driver)
|
((name w_ppx_driver)
|
||||||
(modules (w_ppx_driver))
|
(modules w_ppx_driver)
|
||||||
(preprocess (pps (ppx_driver.runner)))))
|
(preprocess (pps (ppx_driver.runner)))))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
((name w_ppx_driver_flags)
|
((name w_ppx_driver_flags)
|
||||||
(modules (w_ppx_driver_flags))
|
(modules w_ppx_driver_flags)
|
||||||
(preprocess (pps (fooppx -flag (-arg omp) ppx_driver.runner)))))
|
(preprocess (pps (fooppx -flag (-arg omp) ppx_driver.runner)))))
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
(library
|
(library
|
||||||
(name privatelib)
|
(name privatelib)
|
||||||
(modules (privatelib)))
|
(modules privatelib))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
(name publicbin)
|
(name publicbin)
|
||||||
(modules (publicbin))
|
(modules publicbin)
|
||||||
(public_name publicbin)
|
(public_name publicbin)
|
||||||
(package publicbin))
|
(package publicbin))
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
(library
|
(library
|
||||||
(name privatelib)
|
(name privatelib)
|
||||||
(modules (privatelib)))
|
(modules privatelib))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name publiclib)
|
(name publiclib)
|
||||||
(public_name publiclib)
|
(public_name publiclib)
|
||||||
(modules (publiclib))
|
(modules publiclib)
|
||||||
(libraries privatelib)
|
(libraries privatelib)
|
||||||
(optional))
|
(optional))
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
(library
|
(library
|
||||||
(name privatelib)
|
(name privatelib)
|
||||||
(modules (privatelib)))
|
(modules privatelib))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
(name publiclib)
|
(name publiclib)
|
||||||
(public_name publiclib)
|
(public_name publiclib)
|
||||||
(libraries privatelib)
|
(libraries privatelib)
|
||||||
(modules (publiclib)))
|
(modules publiclib))
|
||||||
|
|
|
@ -9,4 +9,4 @@
|
||||||
((name mylib)
|
((name mylib)
|
||||||
(public_name mylib)
|
(public_name mylib)
|
||||||
(preprocess (pps (ppx_internal)))
|
(preprocess (pps (ppx_internal)))
|
||||||
(modules (mylib))))
|
(modules mylib)))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name private_runtime_dep)
|
((name private_runtime_dep)
|
||||||
(modules (private_runtime_dep))))
|
(modules private_runtime_dep)))
|
||||||
|
|
||||||
(library
|
(library
|
||||||
((name private_ppx)
|
((name private_ppx)
|
||||||
|
@ -14,4 +14,4 @@
|
||||||
((name mylib)
|
((name mylib)
|
||||||
(public_name mylib)
|
(public_name mylib)
|
||||||
(preprocess (pps (private_ppx)))
|
(preprocess (pps (private_ppx)))
|
||||||
(modules (mylib))))
|
(modules mylib)))
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
(library
|
(library
|
||||||
((name rlib)
|
((name rlib)
|
||||||
(public_name rlib)
|
(public_name rlib)
|
||||||
(modules (bar cppome foo hello pped))
|
(modules bar cppome foo hello pped)
|
||||||
(lint
|
(lint
|
||||||
(per_module
|
(per_module
|
||||||
((pps (reasonppx (-lint true))) (hello cppome))
|
((pps (reasonppx (-lint true))) (hello cppome))
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
((name rbin)
|
((name rbin)
|
||||||
(modules (rbin))
|
(modules rbin)
|
||||||
(lint (action (run ./pp/reasononlypp.exe -lint %{<})))
|
(lint (action (run ./pp/reasononlypp.exe -lint %{<})))
|
||||||
(preprocess (action (run ./pp/reasononlypp.exe %{<})))
|
(preprocess (action (run ./pp/reasononlypp.exe %{<})))
|
||||||
(libraries (rlib))))
|
(libraries (rlib))))
|
||||||
|
|
Loading…
Reference in New Issue