Skip to content

Commit

Permalink
Add configured and configurable printer types to Pp_ast
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rebours <[email protected]>
  • Loading branch information
NathanReb committed Nov 22, 2024
1 parent eafae4a commit 1385740
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
33 changes: 22 additions & 11 deletions src/pp_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,32 @@ class lift_simple_val =
| NoInjectivity -> Constr ("NoInjectivity", [])
end

type 'a pp = Format.formatter -> 'a -> unit
type 'a configurable = ?config:Config.t -> 'a pp
type 'a configured = 'a pp

module type S = sig
type 'a printer

val structure : structure printer
val structure_item : structure_item printer
val signature : signature printer
val signature_item : signature_item printer
val expression : expression printer
val pattern : pattern printer
val core_type : core_type printer
end

module type Conf = sig
val config : Config.t
end

module type Configured = sig
val structure : Format.formatter -> structure -> unit
val structure_item : Format.formatter -> structure_item -> unit
val signature : Format.formatter -> signature -> unit
val signature_item : Format.formatter -> signature_item -> unit
val expression : Format.formatter -> expression -> unit
val pattern : Format.formatter -> pattern -> unit
val core_type : Format.formatter -> core_type -> unit
end
module type Configured = S with type 'a printer = 'a configured
module type Configurable = S with type 'a printer = 'a configurable

module Make (Conf : Conf) : Configured = struct
type 'a printer = 'a configured

let lsv =
let lift_simple_val = new lift_simple_val in
lift_simple_val#set_config Conf.config;
Expand All @@ -340,9 +351,9 @@ module Default = Make (struct
let config = Config.default
end)

let lift_simple_val = new lift_simple_val
type 'a printer = 'a configurable

type 'node pp = ?config:Config.t -> Format.formatter -> 'node -> unit
let lift_simple_val = new lift_simple_val

let with_config ~config ~f =
let old_config = lift_simple_val#get_config () in
Expand Down
38 changes: 19 additions & 19 deletions src/pp_ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,32 @@ module Config : sig
be. *)
end

type 'a pp = Format.formatter -> 'a -> unit
type 'a configurable = ?config:Config.t -> 'a pp
type 'a configured = 'a pp

module type S = sig
type 'a printer

val structure : structure printer
val structure_item : structure_item printer
val signature : signature printer
val signature_item : signature_item printer
val expression : expression printer
val pattern : pattern printer
val core_type : core_type printer
end

module type Conf = sig
val config : Config.t
end

module type Configured = sig
val structure : Format.formatter -> structure -> unit
val structure_item : Format.formatter -> structure_item -> unit
val signature : Format.formatter -> signature -> unit
val signature_item : Format.formatter -> signature_item -> unit
val expression : Format.formatter -> expression -> unit
val pattern : Format.formatter -> pattern -> unit
val core_type : Format.formatter -> core_type -> unit
end
module type Configured = S with type 'a printer = 'a configured
module type Configurable = S with type 'a printer = 'a configurable

module Make (Conf : Conf) : Configured

val make : Config.t -> (module Configured)

module Default : Configured

type 'node pp = ?config:Config.t -> Format.formatter -> 'node -> unit

val structure : structure pp
val structure_item : structure_item pp
val signature : signature pp
val signature_item : signature_item pp
val expression : expression pp
val pattern : pattern pp
val core_type : core_type pp
include Configurable

0 comments on commit 1385740

Please sign in to comment.