aboutsummaryrefslogtreecommitdiff
path: root/lib/configuration
diff options
context:
space:
mode:
Diffstat (limited to 'lib/configuration')
-rw-r--r--lib/configuration/importConf.ml8
-rw-r--r--lib/configuration/importConf.mli4
-rw-r--r--lib/configuration/of_json.ml5
-rw-r--r--lib/configuration/read_conf.ml2
-rw-r--r--lib/configuration/syntax.ml69
5 files changed, 45 insertions, 43 deletions
diff --git a/lib/configuration/importConf.ml b/lib/configuration/importConf.ml
index 586be3c..eb7c8d2 100644
--- a/lib/configuration/importConf.ml
+++ b/lib/configuration/importConf.ml
@@ -60,18 +60,18 @@ let get_table_for_name : Syntax.t -> string option -> Table.t =
if String.equal name conf.source.name then conf.source
else
let ext =
- List.find conf.externals ~f:(fun (ext : Syntax.extern) ->
+ List.find conf.externals ~f:(fun (ext : Syntax.Extern.t) ->
String.equal name ext.target.name)
in
ext.target
let root_table : Syntax.t -> Table.t = fun conf -> conf.source
-let get_dependancies_for_table : Syntax.t -> Table.t -> Syntax.extern list =
+let get_dependancies_for_table : Syntax.t -> Table.t -> Syntax.Extern.t list =
fun conf source ->
let is_root = source = conf.source in
- List.filter conf.externals ~f:(fun (ext : Syntax.extern) ->
+ List.filter conf.externals ~f:(fun (ext : Syntax.Extern.t) ->
(* Enumerate the intern_key and check the source pointed by each column *)
Expression.fold_values ext.intern_key ~init:false ~f:(fun acc expr ->
if acc then acc
@@ -83,7 +83,7 @@ let get_dependancies_for_table : Syntax.t -> Table.t -> Syntax.extern list =
let print_path_expression t = ImportExpression.Repr.repr Path.repr t
let print_extern t =
- let toml = Syntax.toml_of_extern t in
+ let toml = Syntax.Extern.toml_of_extern t in
Otoml.Printer.to_string toml
let expression_from_string s =
diff --git a/lib/configuration/importConf.mli b/lib/configuration/importConf.mli
index 3a8ae75..be1d1d4 100644
--- a/lib/configuration/importConf.mli
+++ b/lib/configuration/importConf.mli
@@ -12,7 +12,7 @@ val t_of_yojson : Yojson.Safe.t -> Syntax.t
val t_of_toml : Otoml.t -> (Syntax.t, string) result
val get_table_for_name : Syntax.t -> string option -> Table.t
-val get_dependancies_for_table : Syntax.t -> Table.t -> Syntax.extern list
+val get_dependancies_for_table : Syntax.t -> Table.t -> Syntax.Extern.t list
(** Get all the externals refered by the source *)
val print_path_expression : Path.t ImportExpression.T.t -> string
@@ -20,4 +20,4 @@ val print_path_expression : Path.t ImportExpression.T.t -> string
val expression_from_string :
string -> (Path.t ImportExpression.T.t, string) result
-val print_extern : Syntax.extern -> string
+val print_extern : Syntax.Extern.t -> string
diff --git a/lib/configuration/of_json.ml b/lib/configuration/of_json.ml
index f9171b9..e6ee7a4 100644
--- a/lib/configuration/of_json.ml
+++ b/lib/configuration/of_json.ml
@@ -2,7 +2,6 @@ open StdLabels
module Table = ImportDataTypes.Table
module Path = ImportDataTypes.Path
module Expression = ImportExpression.T
-
open Ppx_yojson_conv_lib.Yojson_conv.Primitives
let current_syntax = 1
@@ -100,7 +99,7 @@ type extern = {
}
[@@deriving of_yojson]
-type syntax_v1_extern = Syntax.extern
+type syntax_v1_extern = Syntax.Extern.t
let syntax_v1_extern_of_yojson yojson =
let e = extern_of_yojson yojson in
@@ -108,7 +107,7 @@ let syntax_v1_extern_of_yojson yojson =
Expression.map e.intern_key ~f:(fun column ->
Syntax.Path.{ column; alias = e.source })
in
- Syntax.
+ Syntax.Extern.
{
extern_key = e.extern_key;
intern_key;
diff --git a/lib/configuration/read_conf.ml b/lib/configuration/read_conf.ml
index 8d467a5..952c43c 100644
--- a/lib/configuration/read_conf.ml
+++ b/lib/configuration/read_conf.ml
@@ -161,7 +161,7 @@ module Make (S : Decoders.Decode.S) = struct
in
S.succeed
- Syntax.
+ Syntax.Extern.
{
intern_key;
extern_key;
diff --git a/lib/configuration/syntax.ml b/lib/configuration/syntax.ml
index 8efdc59..1eb3c70 100644
--- a/lib/configuration/syntax.ml
+++ b/lib/configuration/syntax.ml
@@ -13,46 +13,49 @@ let toml_of_table Table.{ file; tab; name } =
Otoml.table values
-type extern = {
- intern_key : Path.t E.t;
- target : Table.t;
- extern_key : Path.column E.t;
- allow_missing : bool;
- match_rule : string option;
-}
+module Extern = struct
+ type t = {
+ intern_key : Path.t E.t;
+ target : Table.t;
+ extern_key : Path.column E.t;
+ allow_missing : bool;
+ match_rule : string option;
+ }
+ (** Describe a relation beteween two tables *)
-let toml_of_extern extern =
- let values =
- [
- ( "intern_key",
- Otoml.string
- @@ ImportExpression.Repr.repr ~top:true Path.repr extern.intern_key );
- ( "extern_key",
- Otoml.string
- @@ ImportExpression.Repr.repr ~top:true
- (fun v -> ":" ^ ImportCSV.Csv.column_to_string v)
- extern.extern_key );
- ("file", Otoml.string extern.target.file);
- ("allow_missing", Otoml.boolean extern.allow_missing);
- ]
- in
+ let toml_of_extern extern =
+ let values =
+ [
+ ( "intern_key",
+ Otoml.string
+ @@ ImportExpression.Repr.repr ~top:true Path.repr extern.intern_key );
+ ( "extern_key",
+ Otoml.string
+ @@ ImportExpression.Repr.repr ~top:true
+ (fun v -> ":" ^ ImportCSV.Csv.column_to_string v)
+ extern.extern_key );
+ ("file", Otoml.string extern.target.file);
+ ("allow_missing", Otoml.boolean extern.allow_missing);
+ ]
+ in
- let values =
- match extern.target.tab with
- | 1 -> values
- | tab -> ("tab", Otoml.integer tab) :: values
- in
+ let values =
+ match extern.target.tab with
+ | 1 -> values
+ | tab -> ("tab", Otoml.integer tab) :: values
+ in
- Otoml.table values
+ Otoml.table values
-let toml_of_externs externs =
- List.map externs ~f:(fun e -> (e.target.name, toml_of_extern e))
- |> Otoml.table
+ let toml externs =
+ List.map externs ~f:(fun e -> (e.target.name, toml_of_extern e))
+ |> Otoml.table
+end
type t = {
version : int;
source : Table.t;
- externals : extern list;
+ externals : Extern.t list;
columns : Path.t E.t list;
filters : Path.t E.t list;
sort : Path.t E.t list;
@@ -80,7 +83,7 @@ let repr t =
[
("version", Otoml.integer t.version);
("source", toml_of_table t.source);
- ("externals", toml_of_externs t.externals);
+ ("externals", Extern.toml t.externals);
("sheet", sheet);
]
in