Skip to content

Commit

Permalink
Minor style updates
Browse files Browse the repository at this point in the history
- remove space before `:` and `;`
- remove ocamldoc comments in ml files
- run ocp-indent -i *.ml *.mli to get consistent indentation
- cut long lines
  • Loading branch information
samoht committed Oct 9, 2015
1 parent 5f5fa43 commit 7426803
Show file tree
Hide file tree
Showing 13 changed files with 455 additions and 483 deletions.
177 changes: 81 additions & 96 deletions src/functoria.ml

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions src/functoria.mli
Expand Up @@ -18,91 +18,91 @@
(** Configuration library *)

(** Core functoria DSL *)
module Dsl : module type of struct include Functoria_dsl end
module Dsl: module type of struct include Functoria_dsl end

(** Various generic devices. *)
module Devices : sig
module Devices: sig
open Dsl

(** {2 Noop} *)

val noop : job impl
val noop: job impl
(** [noop] is a job that does nothing, has no dependency and returns [()] *)

(** {2 Argv device} *)

type argv
val argv : argv typ
val argv: argv typ

val sys_argv : argv impl
val sys_argv: argv impl
(** The simplest argv device. Returns {!Sys.argv}. *)

(** {2 Key device} *)

val keys : argv impl -> job impl
val keys: argv impl -> job impl
(** This device takes an [argv] device, calls cmdliner and sets up keys. *)

(** {2 Information device} *)

type info
val info : info typ
val info: info typ

val export_info : info impl
val export_info: info impl
(** Export all the information available at configure time to runtime.
It produces, at runtime, a {!Functoria_info.info}.
*)

end

(** Various helpful functions. *)
module Misc : module type of struct include Functoria_misc end
module Misc: module type of struct include Functoria_misc end

(** A specialized DSL build for specific purposes. *)
module type SPECIALIZED = sig
open Dsl

val prelude : string
val prelude: string
(** Prelude printed at the beginning of [main.ml].
It should put in scope:
- a [run] function of type ['a t -> 'a]
- a [return] function of type ['a -> 'a t]
- a [>>=] operator of type ['a t -> ('a -> 'b t) -> 'b t]
*)

val name : string
val name: string
(** Name of the specialized dsl. *)

val version : string
val version: string
(** Version of the specialized dsl. *)

val driver_error : string -> string
val driver_error: string -> string
(** [driver_error s] is the message given to the user when the
the configurable [s] doesn't initialize correctly. *)

val argv : Devices.argv impl
val argv: Devices.argv impl
(** The device used to access [argv]. *)

val config : job impl list -> job impl
val config: job impl list -> job impl
(** The device implementing specific configuration for this
specialized dsl. *)

end

(** Create a configuration engine for a specialized dsl. *)
module Make (P : SPECIALIZED) : sig
module Make (P: SPECIALIZED): sig
open Dsl

val register:
?keys:Key.t list ->
?libraries:string list ->
?packages:string list ->
string -> job impl list -> unit
(** [register name jobs] registers the application named by [name]
which will executes the given [jobs].
@param libraries The ocamlfind libraries needed by this module.
@param packages The opam packages needed by this module.
@param keys The keys related to this module.
*)
(** [register name jobs] registers the application named by [name]
which will executes the given [jobs].
@param libraries The ocamlfind libraries needed by this module.
@param packages The opam packages needed by this module.
@param keys The keys related to this module.
*)

val get_base_keymap: unit -> Key.map
(** [get_base_keymap ()] returns the keymap containing the keys of the specialized DSL.
Expand All @@ -111,7 +111,7 @@ module Make (P : SPECIALIZED) : sig
@deprecated Use the regular key mechanism.
*)

val launch : unit -> unit
val launch: unit -> unit
(** Launch the cmdliner application.
Should only be used by the host specialized DSL.
*)
Expand Down
41 changes: 20 additions & 21 deletions src/functoria_dsl.ml
Expand Up @@ -24,8 +24,8 @@ module Info = struct
root: string;
keys: Key.Set.t;
keymap: Functoria_key.map;
libraries : StringSet.t;
packages : StringSet.t;
libraries: StringSet.t;
packages: StringSet.t;
}

let name t = t.name
Expand All @@ -38,9 +38,8 @@ module Info = struct
let create
?(keys=Key.Set.empty)
?(libraries=StringSet.empty) ?(packages=StringSet.empty)
~keymap
~name ~root =
{ name ; root ; keys ; libraries ; packages ; keymap}
~keymap ~name ~root =
{ name; root; keys; libraries; packages; keymap}

end

Expand All @@ -53,31 +52,31 @@ let (@->) f t =

let typ ty = Type ty

module rec Typ : sig
module rec Typ: sig

type _ impl =
| Impl: 'ty Typ.configurable -> 'ty impl (* base implementation *)
| App: ('a, 'b) app -> 'b impl (* functor application *)
| If : bool Key.value * 'a impl * 'a impl -> 'a impl
| If: bool Key.value * 'a impl * 'a impl -> 'a impl

and ('a, 'b) app = {
f: ('a -> 'b) impl; (* functor *)
x: 'a impl; (* parameter *)
}

and any_impl = Any : _ impl -> any_impl
and any_impl = Any: _ impl -> any_impl

class type ['ty] configurable = object
method ty : 'ty typ
method ty: 'ty typ
method name: string
method module_name: string
method keys: Key.t list
method packages: string list Key.value
method libraries: string list Key.value
method connect : Info.t -> string -> string list -> string
method connect: Info.t -> string -> string list -> string
method configure: Info.t -> (unit, string) R.t
method clean: Info.t -> (unit, string) R.t
method dependencies : any_impl list
method dependencies: any_impl list
end
end = Typ
include Typ
Expand All @@ -98,14 +97,14 @@ let rec switch ~default l kv = match l with


class base_configurable = object
method libraries : string list Key.value = Key.pure []
method packages : string list Key.value = Key.pure []
method keys : Key.t list = []
method libraries: string list Key.value = Key.pure []
method packages: string list Key.value = Key.pure []
method keys: Key.t list = []
method connect (_:Info.t) (_:string) l =
Printf.sprintf "return (`Ok (%s))" (String.concat ", " l)
method configure (_ : Info.t) : (unit,string) R.t = R.ok ()
method clean (_ : Info.t) : (unit,string) R.t = R.ok ()
method dependencies : any_impl list = []
method configure (_: Info.t): (unit,string) R.t = R.ok ()
method clean (_: Info.t): (unit,string) R.t = R.ok ()
method dependencies: any_impl list = []
end


Expand Down Expand Up @@ -138,7 +137,7 @@ class ['ty] foreign
let foreign ?keys ?libraries ?packages ?dependencies module_name ty =
Impl (new foreign ?keys ?libraries ?packages ?dependencies module_name ty)

(** {Misc} *)
(* {Misc} *)

let rec equal
: type t1 t2. t1 impl -> t2 impl -> bool
Expand All @@ -156,11 +155,11 @@ let rec equal
and equal_any (Any x) (Any y) = equal x y


let rec hash : type t . t impl -> int = function
let rec hash: type t . t impl -> int = function
| Impl c ->
Hashtbl.hash
(c#name, Hashtbl.hash c#keys, List.map hash_any c#dependencies)
| App { f ; x } -> Hashtbl.hash (`Bla (hash f, hash x))
| App { f; x } -> Hashtbl.hash (`Bla (hash f, hash x))
| If (cond, t, e) ->
Hashtbl.hash (`If (cond, hash t, hash e))

Expand All @@ -174,5 +173,5 @@ module ImplTbl = Hashtbl.Make (struct

let explode x = match x with
| Impl c -> `Impl c
| App { f ; x } -> `App (Any f, Any x)
| App { f; x } -> `App (Any f, Any x)
| If (cond, x, y) -> `If (cond, x, y)
56 changes: 28 additions & 28 deletions src/functoria_dsl.mli
Expand Up @@ -46,20 +46,20 @@ val ($): ('a -> 'b) impl -> 'a impl -> 'b impl
(** [m $ a] applies the functor [m] to the module [a]. *)

(** Type of an implementation, with its type variable hidden. *)
type any_impl = Any : _ impl -> any_impl
type any_impl = Any: _ impl -> any_impl

val hidden : _ impl -> any_impl
val hidden: _ impl -> any_impl
(** Hide the type variable of an implementation. Useful for dependencies. *)

(** {2 Keys} *)

(** Key creation and manipulation. *)
module Key : module type of struct include Functoria_key end
module Key: module type of struct include Functoria_key end

val if_impl : bool Key.value -> 'a impl -> 'a impl -> 'a impl
val if_impl: bool Key.value -> 'a impl -> 'a impl -> 'a impl
(** [if_impl v impl1 impl2] is [impl1] if [v] is resolved to true and [impl2] otherwise. *)

val switch :
val switch:
default:'a impl ->
('b * 'a impl) list ->
'b Key.value ->
Expand Down Expand Up @@ -93,30 +93,30 @@ val job: job typ
(** {2 DSL extension} *)

(** Information available during configuration. *)
module Info : sig
module Info: sig

type t
(** Configuration information for the whole project. *)

val name : t -> string
val name: t -> string
(** Name of the project *)

val root : t -> string
val root: t -> string
(** Directory in which the configuration is done. *)

val libraries : t -> StringSet.t
val libraries: t -> StringSet.t
(** Ocamlfind libraries needed by the project. *)

val packages : t -> StringSet.t
val packages: t -> StringSet.t
(** OPAM packages needed by the project. *)

val keys : t -> Key.Set.t
val keys: t -> Key.Set.t
(** Keys declared by the project. *)

val keymap : t -> Key.map
val keymap: t -> Key.map
(** Map from key entered in the command line to values. *)

val create :
val create:
?keys:Key.Set.t ->
?libraries:StringSet.t ->
?packages:StringSet.t ->
Expand All @@ -129,7 +129,7 @@ end
(** Signature for configurable devices. *)
class type ['ty] configurable = object

method ty : 'ty typ
method ty: 'ty typ
(** Type of the device. *)

method name: string
Expand All @@ -149,7 +149,7 @@ class type ['ty] configurable = object
method keys: Key.t list
(** Return the list of keys to configure the device. *)

method connect : Info.t -> string -> string list -> string
method connect: Info.t -> string -> string list -> string
(** Return the function call to connect at runtime with the device. *)

method configure: Info.t -> (unit, string) Rresult.result
Expand All @@ -158,7 +158,7 @@ class type ['ty] configurable = object
method clean: Info.t -> (unit, string) Rresult.result
(** Clean all the files generated to use the device. *)

method dependencies : any_impl list
method dependencies: any_impl list
(** The list of dependencies that must be initalized before this device.
You must use {!hide} to pass an arbitrary implementation.
*)
Expand All @@ -169,29 +169,29 @@ val impl: 'a configurable -> 'a impl
(** Create an implementation based on a specified device. *)

(** The base configurable pre-defining many methods. *)
class base_configurable : object
method libraries : string list Key.value
method packages : string list Key.value
method keys : Key.t list
method connect : Info.t -> string -> string list -> string
method configure : Info.t -> (unit, string) Rresult.result
method clean : Info.t -> (unit, string) Rresult.result
method dependencies : any_impl list
class base_configurable: object
method libraries: string list Key.value
method packages: string list Key.value
method keys: Key.t list
method connect: Info.t -> string -> string list -> string
method configure: Info.t -> (unit, string) Rresult.result
method clean: Info.t -> (unit, string) Rresult.result
method dependencies: any_impl list
end

(** {3 Sharing} *)

val hash : 'a impl -> int
val hash: 'a impl -> int
(** Hash an implementation. *)

val equal : 'a impl -> 'a impl -> bool
val equal: 'a impl -> 'a impl -> bool

module ImplTbl : Hashtbl.S with type key = any_impl
module ImplTbl: Hashtbl.S with type key = any_impl
(** Hashtbl of implementations. *)

(** {3 Misc} *)

val explode : 'a impl ->
val explode: 'a impl ->
[ `App of any_impl * any_impl
| `If of bool Key.value * 'a impl * 'a impl
| `Impl of 'a configurable ]

0 comments on commit 7426803

Please sign in to comment.