Skip to content

Commit

Permalink
refactor: move [Dialect] to [Dune_lang] (#10819)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored Aug 11, 2024
1 parent 1f9dd2e commit 8735d9d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
8 changes: 4 additions & 4 deletions bin/describe/describe_pp.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Import
module Dialect = Dune_lang.Dialect

let dialect_and_ml_kind file =
let open Memo.O in
Expand All @@ -8,7 +9,7 @@ let dialect_and_ml_kind file =
in
let+ project = Source_tree.root () >>| Source_tree.Dir.project in
let dialects = Dune_project.dialects project in
match Dune_rules.Dialect.DB.find_by_extension dialects ext with
match Dialect.DB.find_by_extension dialects ext with
| None -> User_error.raise [ Pp.textf "unsupported extension: %s" ext ]
| Some x -> x
;;
Expand All @@ -30,13 +31,12 @@ let execute_pp_action ~sctx file pp_file dump_file =
let* action, _observing_facts =
let* loc, action =
let+ dialect, ml_kind = dialect_and_ml_kind file in
match Dune_rules.Dialect.print_ast dialect ml_kind with
match Dialect.print_ast dialect ml_kind with
| Some print_ast -> print_ast
| None ->
(* fall back to the OCaml print_ast function, known to exist, if one
doesn't exist for this dialect. *)
Dune_rules.Dialect.print_ast Dune_rules.Dialect.ocaml ml_kind
|> Option.value_exn
Dialect.print_ast Dialect.ocaml ml_kind |> Option.value_exn
in
let build =
let open Action_builder.O in
Expand Down
16 changes: 8 additions & 8 deletions src/dune_rules/dialect.ml → src/dune_lang/dialect.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Import
module Action = Dune_lang.Action
open Stdune
open Dune_sexp
module Ml_kind = Ocaml.Ml_kind
module Cm_kind = Ocaml.Cm_kind
module Mode = Ocaml.Mode
Expand All @@ -15,7 +15,7 @@ module File_kind = struct
}

let encode { kind; extension; preprocess; format; print_ast; merlin_reader } =
let open Dune_lang.Encoder in
let open Encoder in
let kind =
string
@@
Expand Down Expand Up @@ -67,7 +67,7 @@ let to_dyn { name; file_kinds } =
;;

let encode { name; file_kinds } =
let open Dune_lang.Encoder in
let open Encoder in
let open Option.O in
let file_kind_stanzas =
List.filter_map Ml_kind.all ~f:(fun kind ->
Expand All @@ -79,7 +79,7 @@ let encode { name; file_kinds } =
;;

let decode =
let open Dune_lang.Decoder in
let open Dune_sexp.Decoder in
let kind kind =
let+ loc, extension = field "extension" (located extension)
and+ preprocess = field_o "preprocess" (located Action.decode_dune_file)
Expand All @@ -91,7 +91,7 @@ let decode =
and+ merlin_reader =
field_o
"merlin_reader"
(Dune_lang.Syntax.since Stanza.syntax (3, 16) >>> located (repeat1 string))
(Syntax.since Stanza.syntax (3, 16) >>> located (repeat1 string))
and+ syntax_ver = Syntax.get_exn Stanza.syntax in
let ver = 3, 9 in
if syntax_ver < ver && Option.is_some (String.index_from extension 1 '.')
Expand All @@ -105,7 +105,7 @@ let decode =
and+ loc = loc
and+ impl = field_o "implementation" (fields (kind Ml_kind.Impl))
and+ intf = field_o "interface" (fields (kind Ml_kind.Intf))
and+ version = Dune_lang.Syntax.get_exn Stanza.syntax in
and+ version = Syntax.get_exn Stanza.syntax in
let dialect_kind_optional_since = 3, 9 in
if version < dialect_kind_optional_since
then (
Expand Down Expand Up @@ -387,5 +387,5 @@ module DB = struct

let to_dyn { by_name; _ } = String.Map.to_dyn to_dyn by_name
let builtin = of_list [ ocaml; reason ]
let is_default t = phys_equal t builtin
let is_default t = t == builtin
end
13 changes: 7 additions & 6 deletions src/dune_rules/dialect.mli → src/dune_lang/dialect.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Import
open Stdune
open Dune_sexp
open Ocaml

(** Dialects
Expand All @@ -23,12 +24,12 @@ type t

val name : t -> string
val to_dyn : t -> Dyn.t
val encode : t Dune_lang.Encoder.t
val decode : t Dune_lang.Decoder.t
val encode : t Encoder.t
val decode : t Decoder.t
val extension : t -> Ml_kind.t -> Filename.Extension.t option
val preprocess : t -> Ml_kind.t -> (Loc.t * Dune_lang.Action.t) option
val format : t -> Ml_kind.t -> (Loc.t * Dune_lang.Action.t * string list) option
val print_ast : t -> Ml_kind.t -> (Loc.t * Dune_lang.Action.t) option
val preprocess : t -> Ml_kind.t -> (Loc.t * Action.t) option
val format : t -> Ml_kind.t -> (Loc.t * Action.t * string list) option
val print_ast : t -> Ml_kind.t -> (Loc.t * Action.t) option
val ocaml : t
val reason : t
val rescript : t
Expand Down
1 change: 1 addition & 0 deletions src/dune_lang/dune_lang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ module Package_info = Package_info
module Section = Section
module Package = Package
module Dune_project_name = Dune_project_name
module Dialect = Dialect
1 change: 0 additions & 1 deletion src/dune_rules/dune_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ module Dune_project = Dune_project
module Source_tree = Source_tree
module Source_dir_status = Source_dir_status
module Dune_file0 = Dune_file0
module Dialect = Dialect
module Private_context = Private_context
module Odoc = Odoc
module Library = Library
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ include struct
module Package_constraint = Package_constraint
module Dune_project_name = Dune_project_name
module Package = Package
module Dialect = Dialect
end

include Dune_engine.No_io
Expand Down

0 comments on commit 8735d9d

Please sign in to comment.