Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add *.mli #307

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions satyrographos.opam
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ depends: [
"uri-sexp" {>= "3.0.0"}
"yaml" {>= "3.0" & < "4.0"}
"yaml-sexp" {>= "3.0" & < "4.0"}
"yojson"
"yojson" {< "2.0.0"}

# Janestreet Libs
"core" {>= "v0.14" & < "v0.15"}
"core" {>= "v0.14" & < "v0.16"}
"ppx_jane"
"shexp"
]
Expand Down
27 changes: 27 additions & 0 deletions src/command/build.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
open Satyrographos

val read_module :
outf:Format.formatter ->
verbose:bool ->
build_module:BuildScript_prim.m ->
buildscript_path:string ->
string * Library.t

val build :
outf:Format.formatter ->
build_dir:string option ->
verbose:bool ->
build_module:BuildScript_prim.m ->
buildscript_path:string ->
system_font_prefix:string option ->
env:Environment.t ->
unit

val build_command :
outf:Format.formatter ->
buildscript_path:string ->
names:string list option ->
verbose:bool ->
env:Environment.t ->
build_dir:string option ->
unit
5 changes: 1 addition & 4 deletions src/command/install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ open Core
open Satyrographos
module Autogen = Satyrographos_autogen

module StringSet = Set.Make(String)

(* TODO Abstract this *)
module StringMap = Map.Make(String)
module StringSet = Library.StringSet

type persistent_autogen = Satyrographos_lockdown.LockdownFile.autogen

Expand Down
27 changes: 27 additions & 0 deletions src/command/install.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
open Satyrographos

type persistent_autogen = Satyrographos_lockdown.LockdownFile.autogen

val get_library_map :
outf:Format.formatter ->
system_font_prefix:string option ->
autogen_libraries:string list ->
libraries:string list option ->
env:Environment.t ->
persistent_autogen:persistent_autogen ->
unit ->
(string, Library.t, Library.StringSet.Elt.comparator_witness) Base.Map.t

val install :
string ->
outf:Format.formatter ->
system_font_prefix:string option ->
?autogen_libraries:string list ->
libraries:string list option ->
verbose:bool ->
?safe:bool ->
copy:bool ->
env:Environment.t ->
persistent_autogen:persistent_autogen ->
unit ->
unit
12 changes: 12 additions & 0 deletions src/command/lint.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
open Satyrographos

val lint :
outf:Format.formatter ->
satysfi_version:Satyrographos_satysfi.Version.t ->
warning_expr:bool Glob.TokenMatcher.t option ->
verbose:bool ->
buildscript_path:string option ->
env:Environment.t ->
int

val get_opam_name : opam:OpamFile.OPAM.t -> opam_path:string -> string
4 changes: 2 additions & 2 deletions src/command/lint_module_dependency.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Satyrographos
open Lint_prim


module StringSet = Set.Make(String)
module StringSet = Library.StringSet

let dummy_formatter =
Format.make_formatter (fun _ _ _ -> ()) ignore
Expand Down Expand Up @@ -44,7 +44,7 @@ let get_libraries ~locs ~env ~library_override m =
~system_font_prefix:None
~libraries:(Some libraries)
~autogen_libraries
~persistent_autogen:[]
~persistent_autogen:[]
~env
()
|> (fun m -> Map.merge_skewed ~combine m library_override)
Expand Down
6 changes: 6 additions & 0 deletions src/command/new.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

val template_map : (string * string) list Core.String.Map.t

val template_descriptions : (string * string) list

val create_project : string -> string option -> (string * string) list -> unit
4 changes: 3 additions & 1 deletion src/command/runSatysfi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ open Satyrographos
module Process = Shexp_process
module P = Process

module StringMap = Map.Make(String)
module StringMap = Library.StringMap

(*
let library_dir prefix (buildscript: BuildScript.m) =
let libdir = Filename.concat prefix "share/satysfi" in
Filename.concat libdir (BuildScript.get_name buildscript)
Expand All @@ -19,6 +20,7 @@ let read_module ~outf ~verbose ~build_module ~buildscript_path =
Format.fprintf outf "@."
end;
(src_dir, p)
*)

let test_satysfi_option options =
let open P in
Expand Down
14 changes: 14 additions & 0 deletions src/command/runSatysfi.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Satyrographos

val run_satysfi_command : satysfi_runtime:string -> string list -> unit Shexp_process.t

val satysfi_command :
outf:Format.formatter ->
system_font_prefix:string option ->
autogen_libraries:string list ->
libraries:string list option ->
verbose:bool ->
project_env:Environment.project_env option ->
env:Environment.t ->
string list ->
int Shexp_process.t
2 changes: 2 additions & 0 deletions src/fontInfo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ let fc_format_data =

module DistinctFontMap = Map.Make(DistinctFont)

(*
let system_font_info_list_task =
let open P.Infix in
P.echo "("
>> P.run "fc-list" ["-f"; fc_format_data]
>> P.echo ")"
*)

(* TODO Handle extremely long argument lists *)
let font_info_list_task fonts =
Expand Down
46 changes: 46 additions & 0 deletions src/fontInfo.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Font : sig
type lang = string
[@@deriving sexp, compare]

type t = {
file: string;
postscriptname: string;
index: int;
fontformat: string;
family: (string * lang) list;
style: (string * lang) list;
fullname: (string * lang) list;
slant: int;
weight: float;
width: int;
foundry: string;
verticallayout: string; (* TODO It should be int, though*)
outline: bool;
scalable: bool;
color: bool;
charset: string;
lang: lang list;
fontversion: int;
fontfeatures: string;
namelang: string;
prgname: string;
} [@@deriving sexp, compare]

end

module DistinctFont : sig
type t = {
file: string;
index: int;
} [@@deriving sexp, compare]

val of_font : Font.t -> t
end

module DistinctFontMap : sig
include Core.Map.S with type Key.t = DistinctFont.t
end

val font_info_list_task : string list -> unit Shexp_process.t

val font_list_task : outf:Format.formatter -> unit Shexp_process.t -> Font.t DistinctFontMap.t Shexp_process.t
2 changes: 2 additions & 0 deletions src/glob.ml
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,13 @@ module TokenMatcherSemantics = struct
type value = bool

type glob = value -> value TokenMatcher.t
(*
let id_char =
Re.alt [
Re.alnum;
Re.set "_-.";
]
*)
let star : glob = fun v ->
TokenMatcher.node (Some v) []
let atom x : glob = fun v ->
Expand Down
11 changes: 11 additions & 0 deletions src/glob.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module TokenMatcher : sig
type 'a t

val empty : 'a t

val exec : 'a t -> string list -> 'a option
end

val parse_as_tm_exn : Lexing.lexbuf -> bool TokenMatcher.t

val split_on_slash : string -> string list
1 change: 1 addition & 0 deletions src/library.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ end

module Dependency = Set.Make(String)
module StringMap = Map.Make(String)
module StringSet = Set.Make(String)
module JsonSet = Set.Make(Json)
module Rename = struct
type t = {
Expand Down
4 changes: 4 additions & 0 deletions src/library.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module StringMap : sig
include Core.Map.S with type Key.t = String.t
end

module StringSet : sig
include Core.Set.S with type Elt.t = String.t
end

module JsonSet : sig
include Core.Set.S with type Elt.t = Json.t
end
Expand Down
8 changes: 4 additions & 4 deletions src/libraryMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ let empty_set_of (type k cmp) another_set: (k, cmp) Base.Set.t =
let comparator = (Set.comparator another_set)
end)

module StringSet = Set.Make(String)
module StringMap = Map.Make(String)
module StringSet = Library.StringSet
module StringMap = Library.StringMap

(*
type t = Library.t StringMap.t
*)

(** Calculate a transitive closure. *)
let transitive_closure map init =
Expand Down Expand Up @@ -67,5 +69,3 @@ let%expect_test "transitive_closure: non-closed" =
transitive_closure map init
|> [%sexp_of: StringSet.t] |> Sexp.to_string_hum |> print_endline;
[%expect{| (c) |}]


3 changes: 3 additions & 0 deletions src/libraryMap.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val transitive_closure :
(string, Library.Dependency.t, Library.StringSet.Elt.comparator_witness) Base.Map.t ->
Library.Dependency.t -> Library.Dependency.t
3 changes: 2 additions & 1 deletion src/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ let%expect_test "position_of_offset: empty content" =
4: ((lnum 1) (cnum 1))
5: ((lnum 2) (cnum 0)) |}]

(*
let offset_of_position content pos =
let rec sub off cur =
if equal_position pos cur
Expand All @@ -115,4 +116,4 @@ let offset_of_position content pos =
else sub off {pos with cnum = pos.cnum + 1;}
in
sub 0 {lnum=0; cnum=0;}

*)
31 changes: 31 additions & 0 deletions src/location.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
type position
[@@deriving sexp, equal, compare, hash]

type column_range = {
rstart: position;
rend: position;
}
[@@deriving sexp, equal, compare, hash]

type line_range = {
rstart: int;
rend: int;
}
[@@deriving sexp, equal, compare, hash]

type position_or_range =
| Line of int
| Column of position
| LineRange of line_range
| ColumnRange of column_range
[@@deriving sexp, equal, compare, hash]

type t = {
path: string;
range: position_or_range option;
}
[@@deriving sexp, equal, compare, hash]

val position_of_offset : string -> int -> position

val display : t -> string
6 changes: 6 additions & 0 deletions src/metadata.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ open Core

module Uri_sexp = struct
include Uri_sexp
(*
let compare = Uri.compare
*)
end

type library_name = string
(*
exception RegisteredAlready of library_name
*)

module Libraries = String.Map
type entry = {
Expand Down Expand Up @@ -45,7 +49,9 @@ let with_modifying_file file ~f =
let list reg = with_reading_file reg ~f:(fun m -> Libraries.keys m.libraries)
let find reg name = with_reading_file reg ~f:(fun m -> Libraries.find m.libraries name)
let mem reg name = with_reading_file reg ~f:(fun m -> Libraries.mem m.libraries name)
(*
let remove reg name = with_modifying_file reg ~f:(fun m -> {libraries = Libraries.remove m.libraries name})
*)
let remove_multiple reg names =
let name_set = String.Set.of_list names in
with_modifying_file reg ~f:(fun m ->
Expand Down
19 changes: 19 additions & 0 deletions src/metadata.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type library_name = string

type entry = {
url: Uri_sexp.t;
} [@@deriving sexp]

type store

val initialize : store -> unit

val list : store -> library_name list

val find : store -> library_name -> entry option

val mem : store -> library_name -> bool

val remove_multiple : store -> library_name list -> unit

val add : store -> library_name -> entry -> unit
2 changes: 2 additions & 0 deletions src/opamSatysfiRegistry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ let read registry_dir =
else None
let list reg = FileUtil.ls reg.registry_dir |> List.map FilePath.basename
let directory reg name = Filename.concat reg.registry_dir name
(*
let mem reg name = directory reg name |> FileUtil.test FileUtil.Is_dir
*)
8 changes: 8 additions & 0 deletions src/opamSatysfiRegistry.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type t
[@@deriving sexp]

val read : string -> t option

val list : t -> string list

val directory : t -> string -> string