From 6883d69e0f8eb0e67928ad2cfc92bf0792f948c9 Mon Sep 17 00:00:00 2001
From: Sébastien Dailly <sebastien@dailly.me>
Date: Thu, 26 Dec 2024 21:29:46 +0100
Subject: Removed some code from the parser and moved it into the Expression.T
 module

---
 lib/configuration/expression_parser.mly | 23 +----------------------
 lib/expression/t.ml                     | 10 ++++++++++
 lib/expression/t.mli                    |  1 +
 3 files changed, 12 insertions(+), 22 deletions(-)

(limited to 'lib')

diff --git a/lib/configuration/expression_parser.mly b/lib/configuration/expression_parser.mly
index 54f3bfe..18b79c8 100644
--- a/lib/configuration/expression_parser.mly
+++ b/lib/configuration/expression_parser.mly
@@ -22,27 +22,6 @@
 %right INEQUALITY_OPERATOR EQUALITY_OPERATOR
 %right CONCAT_OPERATOR BINARY_OPERATOR 
 
-%{
-
-    let function_of_name param f = 
-      match (String.lowercase_ascii f, param) with
-        | "nvl", _ -> 
-            ImportExpression.T.Nvl param 
-        | "join", (ImportExpression.T.Literal sep:: tl) -> 
-            ImportExpression.T.Join (sep, tl)
-        | "join", (ImportExpression.T.Empty:: tl) -> 
-            ImportExpression.T.Join ("", tl)
-        | "upper", _ -> 
-            ImportExpression.T.Function' (ImportExpression.T.Upper, param)
-        | "trim", _ -> 
-            ImportExpression.T.Function' (ImportExpression.T.Trim, param)
-        | "cmp", _ -> 
-            ImportExpression.T.Function' (ImportExpression.T.Cmp, param)
-        | other, _ -> 
-            ImportExpression.T.Function (other, param)
-
-%}
-
 %%
 
 path_expr: 
@@ -146,7 +125,7 @@ expr_(PATH, ENDING_PHANTOM):
         { f }
     | s = IDENT
       args = arguments(PATH)
-      { function_of_name args s }
+      { ImportExpression.T.function_of_name args s }
     | 
       s = IDENT
       L_PAREN
diff --git a/lib/expression/t.ml b/lib/expression/t.ml
index 2df374f..80cff4f 100644
--- a/lib/expression/t.ml
+++ b/lib/expression/t.ml
@@ -43,6 +43,16 @@ let name_of_function = function
   | Trim -> "TRIM"
   | Cmp -> "CMP"
 
+let function_of_name param f =
+  match (String.lowercase_ascii f, param) with
+  | "nvl", _ -> Nvl param
+  | "join", Literal sep :: tl -> Join (sep, tl)
+  | "join", Empty :: tl -> Join ("", tl)
+  | "upper", _ -> Function' (Upper, param)
+  | "trim", _ -> Function' (Trim, param)
+  | "cmp", _ -> Function' (Cmp, param)
+  | other, _ -> Function (other, param)
+
 let name_of_operator = function
   | Equal -> "="
   | Different -> "<>"
diff --git a/lib/expression/t.mli b/lib/expression/t.mli
index 3cd5d23..4b13ac6 100644
--- a/lib/expression/t.mli
+++ b/lib/expression/t.mli
@@ -53,3 +53,4 @@ 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
-- 
cgit v1.2.3