Skip to content

Commit

Permalink
Make the (interface) field of a (dialect) optional
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Petiot <guillaume@tarides.com>
  • Loading branch information
gpetiot committed May 18, 2023
1 parent 40de133 commit e055782
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/dune_rules/dialect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module File_kind = struct
; format : (Loc.t * Action.t * string list) option
}

let dummy_intf =
{ kind = Ml_kind.Intf
; extension = "__DUMMY__"
; preprocess = None
; format = None
}

let encode { kind; extension; preprocess; format } =
let open Dune_lang.Encoder in
let kind =
Expand Down Expand Up @@ -88,7 +95,8 @@ let decode =
fields
(let+ name = field "name" string
and+ impl = field "implementation" (fields (kind Ml_kind.Impl))
and+ intf = field "interface" (fields (kind Ml_kind.Intf)) in
and+ intf = field_o "interface" (fields (kind Ml_kind.Intf)) in
let intf = Option.value intf ~default:File_kind.dummy_intf in
{ name; file_kinds = Ml_kind.Dict.make ~intf ~impl })

let extension { file_kinds; _ } ml_kind =
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions test/blackbox-tests/test-cases/dialects/no_intf.t/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(executable
(name main)
(public_name main)
(modules main))

(executable
(name fmt)
(public_name fmt)
(modules fmt))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(lang dune 1.11)
(using fmt 1.2 (enabled_for mlfi))

(dialect
(name mlfi)
(implementation
(extension mf)
(format (run fmt %{input-file}))))
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/dialects/no_intf.t/fmt.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prerr_endline ("Formatting " ^ Sys.argv.(1))
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions test/blackbox-tests/test-cases/dialects/no_intf.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Test the (dialect ...) stanza inside the dune-project file.

$ dune exec ./main.exe

$ dune build @fmt
Formatting main.mf

0 comments on commit e055782

Please sign in to comment.