diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2025-01-07 22:40:19 +0100 | 
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2025-01-22 12:22:26 +0100 | 
| commit | 986bcb796d8b9e1f485baa8da599aa816c56b587 (patch) | |
| tree | 76a83796a60ec0e30575d3078518c6e2545cd4b0 /lib | |
| parent | 5e15341857e57671a3c617579e3d5dcc89040936 (diff) | |
Explicitly list all the availables functions
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/configuration/read_conf.ml | 1 | ||||
| -rw-r--r-- | lib/errors/importErrors.ml | 4 | ||||
| -rw-r--r-- | lib/errors/importErrors.mli | 1 | ||||
| -rw-r--r-- | lib/expression/t.ml | 21 | ||||
| -rw-r--r-- | lib/expression/t.mli | 2 | 
5 files changed, 26 insertions, 3 deletions
| diff --git a/lib/configuration/read_conf.ml b/lib/configuration/read_conf.ml index df1a728..52ccb62 100644 --- a/lib/configuration/read_conf.ml +++ b/lib/configuration/read_conf.ml @@ -117,6 +117,7 @@ end = struct            Printf.sprintf "Unclosed quote at line %d : \"%s\"" line content          in          Error message +    | ImportErrors.UnknowFunction _ as e -> Error (ImportErrors.repr_error e)      | e ->          let message = Printexc.to_string e in          Error message diff --git a/lib/errors/importErrors.ml b/lib/errors/importErrors.ml index 04f9deb..782291e 100644 --- a/lib/errors/importErrors.ml +++ b/lib/errors/importErrors.ml @@ -25,6 +25,7 @@ exception SqlError of Sqlite3.Rc.t  exception MisplacedWindow  exception Unknown_source of string  exception Unknown_extension of string +exception UnknowFunction of string  exception Cycle of string list  (** Cycle between the dpendencies *) @@ -53,6 +54,9 @@ let repr_error = function          (ImportDataTypes.Types.string_of_t expected)          expression    | Unknown_extension ext -> Printf.sprintf "Unknown file extension %s" ext +  | UnknowFunction name -> +      Printf.sprintf "Unknown function or wrong number of arguments for '%s'" +        name    | Cycle deps ->        Printf.sprintf "Cycle between the dependencies : %s"          (String.concat ~sep:"," deps) diff --git a/lib/errors/importErrors.mli b/lib/errors/importErrors.mli index 7d17a5d..5a2921b 100644 --- a/lib/errors/importErrors.mli +++ b/lib/errors/importErrors.mli @@ -11,6 +11,7 @@ exception Cycle of string list  (** Cycle between the dpendencies *)  exception Unknown_extension of string +exception UnknowFunction of string  exception    JsonError of { diff --git a/lib/expression/t.ml b/lib/expression/t.ml index 80cff4f..9ce21b8 100644 --- a/lib/expression/t.ml +++ b/lib/expression/t.ml @@ -38,12 +38,13 @@ and funct =    | Trim    | Upper -let name_of_function = function +let name_of_function : funct -> string = function    | Upper -> "UPPER"    | Trim -> "TRIM"    | Cmp -> "CMP" -let function_of_name param f = +let function_of_name : 'a t list -> string -> 'a t = + fun param f ->    match (String.lowercase_ascii f, param) with    | "nvl", _ -> Nvl param    | "join", Literal sep :: tl -> Join (sep, tl) @@ -51,7 +52,21 @@ let function_of_name param f =    | "upper", _ -> Function' (Upper, param)    | "trim", _ -> Function' (Trim, param)    | "cmp", _ -> Function' (Cmp, param) -  | other, _ -> Function (other, param) +  (* Branch function *) +  | ("if" as fn), [ _; _; _ ] -> Function (fn, param) +  (* Integer functions *) +  | ("abs" as fn), _ +  | ("int" as fn), _ +  (* String functions *) +  | ("concat" as fn), _ +  | ("match" as fn), _ +  | ("substring" as fn), _ +  (* Date functions *) +  | ("date" as fn), _ +  | ("year" as fn), _ -> Function (fn, param) +  | _ -> +      (*Function (other, param)*) +      raise (ImportErrors.UnknowFunction f)  let name_of_operator = function    | Equal -> "=" diff --git a/lib/expression/t.mli b/lib/expression/t.mli index 4b13ac6..49ef3e7 100644 --- a/lib/expression/t.mli +++ b/lib/expression/t.mli @@ -53,4 +53,6 @@ val name_of_window : 'a window -> string  val map_window : f:('a -> 'b) -> 'a window -> 'b window  val window_of_name : string -> 'a option -> 'a window  val name_of_function : funct -> string +  val function_of_name : 'a t list -> string -> 'a t +(** Create a function with the given name *) | 
