Add Stanza.file_kind

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
Jeremie Dimino 2018-06-25 08:11:54 +01:00 committed by Jérémie Dimino
parent f46a6aae53
commit daa4be3dd8
3 changed files with 28 additions and 4 deletions

View File

@ -89,14 +89,22 @@ struct
; "diff",
(path >>= fun file1 ->
path >>= fun file2 ->
Syntax.get_exn Stanza.syntax >>| fun ver ->
let mode = if ver < (1, 0) then Diff_mode.Text_jbuild else Text in
Stanza.file_kind () >>| fun kind ->
let mode =
match kind with
| Jbuild -> Diff_mode.Text_jbuild
| Dune -> Text
in
Diff { optional = false; file1; file2; mode })
; "diff?",
(path >>= fun file1 ->
path >>= fun file2 ->
Syntax.get_exn Stanza.syntax >>| fun ver ->
let mode = if ver < (1, 0) then Diff_mode.Text_jbuild else Text in
Stanza.file_kind () >>| fun kind ->
let mode =
match kind with
| Jbuild -> Diff_mode.Text_jbuild
| Dune -> Text
in
Diff { optional = true; file1; file2; mode })
; "cmp",
(Syntax.since Stanza.syntax (1, 0) >>= fun () ->

View File

@ -11,3 +11,12 @@ let syntax =
[ (0, 0) (* Jbuild syntax *)
; (1, 0)
]
module File_kind = struct
type t = Jbuild | Dune
end
let file_kind () =
let open Sexp.Of_sexp in
Syntax.get_exn syntax >>| fun ver ->
if ver < (1, 0) then File_kind.Jbuild else Dune

View File

@ -16,3 +16,10 @@ end
the Jbuild language while versions from [(1, 0)] correspond to the
Dune one. *)
val syntax : Syntax.t
module File_kind : sig
type t = Jbuild | Dune
end
(** Whether we are parsing a [jbuild] or [dune] file. *)
val file_kind : unit -> (File_kind.t, _) Sexp.Of_sexp.parser