aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2025-01-11 06:40:30 +0100
committerSébastien Dailly <sebastien@dailly.me>2025-01-22 12:22:26 +0100
commit820a7bda25c5541ce9580f99ec9f6eb512103e59 (patch)
tree8aec624cff21303fac4afe137ecb52c17c5d5329
parent986bcb796d8b9e1f485baa8da599aa816c56b587 (diff)
Removed the json configuration management
-rwxr-xr-xbin/dune2
-rw-r--r--bin/importer.ml6
-rwxr-xr-xdune-project1
-rwxr-xr-xlib/configuration/dune3
-rw-r--r--lib/configuration/importConf.ml26
-rw-r--r--lib/configuration/importConf.mli1
-rw-r--r--lib/configuration/of_json.ml134
-rw-r--r--lib/errors/importErrors.ml7
-rw-r--r--lib/errors/importErrors.mli10
9 files changed, 5 insertions, 185 deletions
diff --git a/bin/dune b/bin/dune
index fad168d..f28f22b 100755
--- a/bin/dune
+++ b/bin/dune
@@ -13,7 +13,6 @@
lwt
lwt.unix
otoml
- yojson
tools
helpers
importConf
@@ -27,7 +26,6 @@
importSQL
)
(link_flags (:standard))
-(preprocess (pps ppx_yojson_conv))
)
(install
diff --git a/bin/importer.ml b/bin/importer.ml
index 4ca04fd..c710aed 100644
--- a/bin/importer.ml
+++ b/bin/importer.ml
@@ -34,12 +34,6 @@ module Args = struct
let load_conf : string -> ImportConf.Syntax.t =
fun file ->
match Filename.extension file with
- | ".json" -> (
- let configuration_file = Yojson.Safe.from_file (exists file) in
- try ImportConf.t_of_yojson configuration_file with
- | e ->
- print_endline @@ ImportErrors.repr_error e;
- exit 1)
| _ -> (
let (conf : (Db.Syntax.t, string) result) =
let* configuration_file =
diff --git a/dune-project b/dune-project
index ca435e6..11dc9e3 100755
--- a/dune-project
+++ b/dune-project
@@ -15,7 +15,6 @@
(csv (>= 2.4))
(csv-lwt (>= 2.4))
(decoders (>= 1.0.0))
- (ppx_yojson_conv (>= v0.14.0))
(ounit (>= 2.2.6))
(otoml (>= 1.0.1))
(re (>= 1.10.4))
diff --git a/lib/configuration/dune b/lib/configuration/dune
index b08e9bd..c29ba49 100755
--- a/lib/configuration/dune
+++ b/lib/configuration/dune
@@ -5,7 +5,6 @@
otoml
menhirLib
importCSV
- yojson
re
helpers
importDataTypes
@@ -14,7 +13,7 @@
)
(foreign_stubs (language c) (names locale))
-(preprocess (pps ppx_yojson_conv ppx_deriving.ord))
+(preprocess (pps ppx_deriving.ord))
)
(rule
diff --git a/lib/configuration/importConf.ml b/lib/configuration/importConf.ml
index aa0e2f3..47f4ea4 100644
--- a/lib/configuration/importConf.ml
+++ b/lib/configuration/importConf.ml
@@ -7,34 +7,12 @@ module Expression = ImportExpression.T
external set_locale : string -> unit = "set_locale"
-let current_syntax = 1
-
-let t_of_yojson : Yojson.Safe.t -> Syntax.t =
- fun json ->
- let keys = Yojson.Safe.Util.keys json in
- let version =
- match List.find_opt keys ~f:(String.equal "version") with
- | None ->
- Printf.printf
- "No version given. Your setup may break in the future.\n\
- Please add « \"version\":%d » in your configuration.\n\n"
- current_syntax;
- `Int 1
- | Some _ -> Yojson.Safe.Util.member "version" json
- in
-
- match version with
- | `Int 1 -> Of_json.t_of_yojson json
- | other ->
- Printf.eprintf "Unsuported version : %s\n" (Yojson.Safe.to_string other);
- exit 1
+let latest_version = 1
module TomlReader = Read_conf.Make (Helpers.Toml.Decode)
let t_of_toml : Otoml.t -> (Syntax.t, string) result =
fun toml ->
- let latest_version = 1 in
-
let version =
Otoml.find_or ~default:latest_version toml
(Otoml.get_integer ~strict:false)
@@ -57,7 +35,7 @@ let dummy_conf =
Syntax.
{
source = { file = ""; tab = 0; name = "" };
- version = 1;
+ version = latest_version;
locale = Some "C";
externals = [];
columns = [];
diff --git a/lib/configuration/importConf.mli b/lib/configuration/importConf.mli
index be1d1d4..c88b0f1 100644
--- a/lib/configuration/importConf.mli
+++ b/lib/configuration/importConf.mli
@@ -8,7 +8,6 @@ val root_table : Syntax.t -> Table.t
(** Get the root table, this table is the main table to load and each line in
this table will be processed *)
-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
diff --git a/lib/configuration/of_json.ml b/lib/configuration/of_json.ml
deleted file mode 100644
index 6ac59a2..0000000
--- a/lib/configuration/of_json.ml
+++ /dev/null
@@ -1,134 +0,0 @@
-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
-
-let rec expression_of_yojson :
- (Yojson.Safe.t -> 'a) -> Yojson.Safe.t -> 'a Expression.t =
- fun f expr ->
- match expr with
- | `Null -> Empty
- | `List l -> Concat (List.map ~f:(expression_of_yojson f) l)
- | `String s as json -> (
- try Path (f json) with
- | _ -> Literal s)
- | `Assoc [ (fn, `List [ `List l1; `List l2 ]) ]
- when String.equal "counter" (String.lowercase_ascii fn) ->
- Window
- ( Expression.Counter,
- List.map ~f:(expression_of_yojson f) l1,
- List.map ~f:(expression_of_yojson f) l2 )
- | `Assoc [ (fn, `List [ expr1; `List l2; `List l3 ]) ]
- when String.equal "previous" (String.lowercase_ascii fn) ->
- Window
- ( Expression.Previous (expression_of_yojson f expr1),
- List.map ~f:(expression_of_yojson f) l2,
- List.map ~f:(expression_of_yojson f) l3 )
- | `Assoc [ (fn, `List l) ] when String.equal "nvl" (String.lowercase_ascii fn)
- -> Nvl (List.map ~f:(expression_of_yojson f) l)
- | `Assoc [ (fn, `List l) ] ->
- Function
- (String.lowercase_ascii fn, List.map ~f:(expression_of_yojson f) l)
- | json -> (
- try Path (f json) with
- | _ ->
- let str_json = Yojson.Safe.pretty_to_string json in
- raise
- (ImportErrors.JsonError { json = str_json; element = "Expression" })
- )
-
-type 'a expression = 'a Expression.t
-type column = Path.column
-
-let column_of_yojson : Yojson.Safe.t -> int = function
- | `Int i -> i
- | `String s -> ImportCSV.Csv.column_of_string s
- | _ -> raise (Invalid_argument "column")
-
-let yojson_of_column i = `String (ImportCSV.Csv.column_to_string i)
-
-type path = Syntax.Path.t = {
- alias : string option; [@default None] [@yojson_drop_default ( = )]
- (* External file to load, when the information is missing, load in
- the current file *)
- column : column;
-}
-[@@deriving of_yojson]
-
-let path_of_yojson : Yojson.Safe.t -> path = function
- | `String s ->
- Scanf.sscanf s ":%s@.%s" (fun table column ->
- if String.equal column "" then
- { alias = None; column = ImportCSV.Csv.column_of_string table }
- else
- {
- alias = Some table;
- column = ImportCSV.Csv.column_of_string column;
- })
- | other -> path_of_yojson other
-
-let yojson_of_path : path -> Yojson.Safe.t =
- fun { alias; column } ->
- let table =
- match alias with
- | None -> ""
- | Some table -> String.cat table "."
- in
-
- `String
- (String.concat ~sep:""
- [ ":"; table; ImportCSV.Csv.column_to_string column ])
-
-type table = Table.t = {
- file : string;
- tab : int; [@default 1] [@yojson_drop_default ( = )]
- name : string;
-}
-[@@deriving of_yojson]
-
-type extern = {
- source : string option; [@default None] [@yojson_drop_default ( = )]
- intern_key : column expression;
- target : table;
- extern_key : column expression;
- allow_missing : bool; [@default false] [@yojson_drop_default ( = )]
- match_rule : string option; [@default None] [@yojson_drop_default ( = )]
-}
-[@@deriving of_yojson]
-
-type syntax_v1_extern = Syntax.Extern.t
-
-let syntax_v1_extern_of_yojson yojson =
- let e = extern_of_yojson yojson in
- let intern_key : path Expression.t =
- Expression.map e.intern_key ~f:(fun column ->
- Syntax.Path.{ column; alias = e.source })
- in
- Syntax.Extern.
- {
- extern_key = e.extern_key;
- intern_key;
- target = e.target;
- allow_missing = e.allow_missing;
- match_rule = e.match_rule;
- }
-
-type predicate = unit
-
-let predicate_of_yojson _ = ()
-let yojson_of_predicate () = `Null
-
-type t = Syntax.t = {
- version : int; [@default current_syntax]
- locale : string option;
- source : table;
- externals : syntax_v1_extern list; [@default []]
- columns : path expression list;
- filters : path expression list; [@default []] [@yojson_drop_default ( = )]
- sort : path expression list; [@default []] [@yojson_drop_default ( = )]
- uniq : path expression list; [@default []] [@yojson_drop_default ( = )]
-}
-[@@deriving of_yojson]
diff --git a/lib/errors/importErrors.ml b/lib/errors/importErrors.ml
index 782291e..97a6259 100644
--- a/lib/errors/importErrors.ml
+++ b/lib/errors/importErrors.ml
@@ -13,12 +13,6 @@ type xlsError = {
exn : exn;
}
-exception
- JsonError of {
- json : string;
- element : string;
- }
-
exception InvalidEncoding of string
exception NullKey of int
exception SqlError of Sqlite3.Rc.t
@@ -40,7 +34,6 @@ exception
let repr_error = function
| SqlError s -> Printf.sprintf "%s Error" (Sqlite3.Rc.to_string s)
- | JsonError { json; element } -> Printf.sprintf "%s : %s" element json
| NullKey k ->
Printf.sprintf "The key %s is null" (ImportCSV.Csv.column_to_string k)
| Unknown_source source ->
diff --git a/lib/errors/importErrors.mli b/lib/errors/importErrors.mli
index 5a2921b..445361e 100644
--- a/lib/errors/importErrors.mli
+++ b/lib/errors/importErrors.mli
@@ -4,8 +4,8 @@ exception SqlError of Sqlite3.Rc.t
exception MisplacedWindow
exception Unknown_source of string
-(** Exception raised when a source used in a path is not declared as an
- external *)
+(** Exception raised when a source used in a path is not declared as an external
+*)
exception Cycle of string list
(** Cycle between the dpendencies *)
@@ -13,12 +13,6 @@ exception Cycle of string list
exception Unknown_extension of string
exception UnknowFunction of string
-exception
- JsonError of {
- json : string;
- element : string;
- }
-
type xlsError = {
source : ImportDataTypes.Table.t;
row : int;