Present menhir as an extension

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
Jeremie Dimino 2018-06-20 12:16:51 +01:00 committed by Jérémie Dimino
parent 74c008ea62
commit 58997d9df7
7 changed files with 56 additions and 9 deletions

View File

@ -81,6 +81,9 @@ next
- Rename `files_recursively_in` to `source_tree` to make it clearer it
doesn't include generated files (#899, fix #843, @diml)
- Present the `menhir` stanza as an extension with its own version
(#..., @diml)
1.0+beta20 (10/04/2018)
-----------------------

View File

@ -259,7 +259,7 @@ module Extension = struct
let parse_args p =
let open Sexp.Of_sexp in
let dune_project_edited = ref false in
parse p Univ_map.empty (List (Loc.none, []))
parse (enter p) Univ_map.empty (List (Loc.of_pos __POS__, []))
|> List.map ~f:(fun (name, p) ->
(name,
return () >>= fun () ->

View File

@ -252,7 +252,7 @@ module Gen(P : Install_rules.Params) = struct
let generated_files =
List.concat_map stanzas ~f:(fun stanza ->
match (stanza : Stanza.t) with
| Menhir menhir ->
| Menhir.T menhir ->
Menhir_rules.targets menhir
| Rule rule ->
List.map (user_rule rule ~dir ~scope) ~f:Path.basename
@ -998,7 +998,7 @@ module Gen(P : Install_rules.Params) = struct
| _ -> None));
List.iter stanzas ~f:(fun stanza ->
match (stanza : Stanza.t) with
| Menhir m ->
| Menhir.T m ->
let cctx =
match
List.find_map (Menhir_rules.module_names m)

View File

@ -1155,7 +1155,34 @@ module Menhir = struct
; loc : Loc.t
}
let syntax =
Syntax.create
~name:"menhir"
~desc:"the menhir extension"
[ (1, 0) ]
let t =
record
(field_o "merge_into" string >>= fun merge_into ->
field_oslu "flags" >>= fun flags ->
field "modules" (list string) >>= fun modules ->
Rule.Mode.field >>= fun mode ->
return
{ merge_into
; flags
; modules
; mode
; loc = Loc.none
})
type Stanza.t += T of t
let () =
Dune_project.Extension.register syntax
(return [ "menhir", t >>| fun x -> [T x] ])
(* Syntax for jbuild files *)
let jbuild_syntax =
record
(field_o "merge_into" string >>= fun merge_into ->
field_oslu "flags" >>= fun flags ->
@ -1275,7 +1302,6 @@ type Stanza.t +=
| Install of Install_conf.t
| Alias of Alias_conf.t
| Copy_files of Copy_files.t
| Menhir of Menhir.t
| Documentation of Documentation.t
| Env of Env.t
@ -1313,10 +1339,6 @@ module Stanzas = struct
(loc >>= fun loc ->
Rule.ocamlyacc >>| fun x ->
rules (Rule.ocamlyacc_to_rule loc x))
; "menhir",
(loc >>= fun loc ->
Menhir.t >>| fun x ->
[Menhir { x with loc }])
; "install",
(Install_conf.t >>| fun x ->
[Install x])
@ -1347,6 +1369,17 @@ module Stanzas = struct
]
let jbuild_parser =
(* The menhir stanza was part of the vanilla jbuild
syntax. Starting from Dune 1.0, it is presented as an
extension with its own version. *)
let stanzas =
stanzas @
[ "menhir",
(loc >>= fun loc ->
Menhir.jbuild_syntax >>| fun x ->
[Menhir.T { x with loc }])
]
in
Syntax.set syntax (0, 0) (sum stanzas)
let () =

View File

@ -303,6 +303,8 @@ module Menhir : sig
; mode : Rule.Mode.t
; loc : Loc.t
}
type Stanza.t += T of t
end
module Alias_conf : sig
@ -353,7 +355,6 @@ type Stanza.t +=
| Install of Install_conf.t
| Alias of Alias_conf.t
| Copy_files of Copy_files.t
| Menhir of Menhir.t
| Documentation of Documentation.t
| Env of Env.t

View File

@ -7,3 +7,12 @@
Info: creating file dune-project with this contents: (lang dune 1.0)
$ cat dune-project
(lang dune 1.0)
Test that using menhir automatically update the dune-project file
$ echo '(library ((name x))) (menhir ((modules (x))))' >> src/dune
$ dune build
Info: appending this line to dune-project: (using menhir 1.0)
$ cat dune-project
(lang dune 1.0)
(using menhir 1.0)

View File

@ -1 +1,2 @@
(lang dune 1.0)
(using menhir 1.0)