aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2017-11-01 14:53:09 +0100
committerSébastien Dailly <sebastien@chimrod.com>2017-11-01 14:53:09 +0100
commit9fbc5e48ea8183dda8fdb652364c0c29f8a309d5 (patch)
tree052214454101b44d07918131ad500f0c451649eb
parentab721136f50914a21f6cca89f0fcfb055ba58cd2 (diff)
Made scTypes.types private.
-rwxr-xr-xevaluator.ml9
-rwxr-xr-xexpression.ml2
-rwxr-xr-xexpressionParser.mly21
-rwxr-xr-xodf/odf.ml8
-rwxr-xr-xodf/odf_ExpressionParser.mly5
-rw-r--r--[-rwxr-xr-x]scTypes.ml19
-rw-r--r--[-rwxr-xr-x]scTypes.mli19
-rwxr-xr-xtests/expressionParser_test.ml10
-rwxr-xr-xtests/expression_test.ml18
-rwxr-xr-xtests/odf/odf_ExpressionParser_test.ml5
-rwxr-xr-xtests/sheet_test.ml3
11 files changed, 60 insertions, 59 deletions
diff --git a/evaluator.ml b/evaluator.ml
index f2a49d9..46123cb 100755
--- a/evaluator.ml
+++ b/evaluator.ml
@@ -309,9 +309,12 @@ let repr mapper value = begin
in
let Result r = (extract value) in
begin match r with
- | Data.Bool b -> ScTypes.Result (ScTypes.Bool b)
- | Data.Num (format, n) -> ScTypes.Result (ScTypes.Num (format, n))
- | Data.String s -> ScTypes.Result (ScTypes.Str s)
+ | Data.Bool b -> ScTypes.Result (ScTypes.boolean b)
+ | Data.String s -> ScTypes.Result (ScTypes.string s)
+ | Data.Num (format, n) -> begin match ScTypes.get_numeric_type format with
+ | ScTypes.Date -> ScTypes.Result (ScTypes.date n)
+ | ScTypes.Number -> ScTypes.Result (ScTypes.number n)
+ end
| _ -> raise Errors.TypeError
end
end
diff --git a/expression.ml b/expression.ml
index 31b6369..d42b90e 100755
--- a/expression.ml
+++ b/expression.ml
@@ -38,7 +38,7 @@ let load content = begin
ExpressionParser.content ExpressionLexer.read
@@ Lexing.from_string content' in
Basic r
- with _ -> Basic (ScTypes.Str (UTF8.from_utf8string content'))
+ with _ -> Basic (ScTypes.string (UTF8.from_utf8string content'))
)
) else (
(* If the string in empty, build an undefined value *)
diff --git a/expressionParser.mly b/expressionParser.mly
index 303e683..a9f685f 100755
--- a/expressionParser.mly
+++ b/expressionParser.mly
@@ -46,31 +46,28 @@ content:
| basic EOF {$1}
basic:
- | PLUS num {Result (Num (ScTypes.Number, (DataType.Num.of_num (snd $2))))}
- | MINUS num {Result (Num (ScTypes.Number, (DataType.Num.of_num @@ Num.minus_num (snd $2))))}
- | num {Result (Num (ScTypes.Number, (DataType.Num.of_num (snd $1))))}
+ | PLUS num {Result (number (DataType.Num.of_num (snd $2)))}
+ | MINUS num {Result (number (DataType.Num.of_num @@ Num.minus_num (snd $2)))}
+ | num {Result (number (DataType.Num.of_num (snd $1)))}
| NUM DIVIDE NUM DIVIDE NUM {Result (
- Num (
- ScTypes.Date,
+ date (
DataType.Num.of_num @@ (Date.get_julian_day
(Num.int_of_num @@ snd $1)
(Num.int_of_num @@ snd $3)
(Num.int_of_num @@ snd $5)
)))}
| NUM COLON NUM COLON NUM {Result (
- Num (
- ScTypes.Date,
- (Num.(
+ date (
+ Num.(
let nhour = (snd $1) // (num_of_int 24)
and nmin = (snd $3) // (num_of_int 1440)
and nsec = (snd $5) // (num_of_int 86400)
- in DataType.Num.of_num @@ nhour +/ nmin +/ nsec))
+ in DataType.Num.of_num @@ nhour +/ nmin +/ nsec)
)
)}
expr:
- | num {Value (Num (
- ScTypes.Number,
+ | num {Value (number (
DataType.Num.of_num (snd $1)
))}
| MINUS expr {Call (F.sub, [$2])}
@@ -84,7 +81,7 @@ expr:
| LPAREN expr RPAREN {Expression $2}
- | STR {Value (Str (u $1))}
+ | STR {Value (string (u $1))}
(* Mathematical operators *)
| expr MINUS expr {Call (F.sub, [$1; $3])}
diff --git a/odf/odf.ml b/odf/odf.ml
index b091bc9..8fa3411 100755
--- a/odf/odf.ml
+++ b/odf/odf.ml
@@ -30,17 +30,15 @@ let load_formula formula =
let load_content content = begin function
| "float" -> Expression.Basic (
- ScTypes.Num (
- ScTypes.Number,
+ ScTypes.number (
DataType.Num.of_num (Tools.Num.of_float_string content)
))
| "date" -> Expression.Basic (
- ScTypes.Num (
- ScTypes.Date,
+ ScTypes.date (
DataType.Num.of_num (Tools.Num.of_float_string content)
))
| _ -> Expression.Basic (
- ScTypes.Str (
+ ScTypes.string (
UTF8.from_utf8string content))
end
diff --git a/odf/odf_ExpressionParser.mly b/odf/odf_ExpressionParser.mly
index 1b60e1c..190e6f1 100755
--- a/odf/odf_ExpressionParser.mly
+++ b/odf/odf_ExpressionParser.mly
@@ -43,8 +43,7 @@ value:
| LETTERS COLON EQ expr EOF {$4}
expr:
- | num {Value (Num (
- Number,
+ | num {Value (number (
DataType.Num.of_num @@ snd $1
))}
| MINUS expr {Call (F.sub, [$2])}
@@ -54,7 +53,7 @@ expr:
| L_SQ_BRACKET ref R_SQ_BRACKET {$2}
| LPAREN expr RPAREN {Expression $2}
- | STR {Value (Str (u $1))}
+ | STR {Value (string (u $1))}
(* Mathematical operators *)
| expr MINUS expr {Call (F.sub, [$1; $3])}
diff --git a/scTypes.ml b/scTypes.ml
index f8c3d38..ff0af83 100755..100644
--- a/scTypes.ml
+++ b/scTypes.ml
@@ -13,8 +13,8 @@ type 'a number_format = (float -> 'a, Format.formatter, unit) format
type _ dataFormat =
| Date: DataType.Num.t dataFormat (* Date *)
| Number: DataType.Num.t dataFormat (* Number *)
- | String: DataType.String.t dataFormat (* String result, there is only one representation *)
- | Bool: DataType.Bool.t dataFormat (* Boolean result *)
+ | String: DataType.String.t dataFormat(* String *)
+ | Bool: DataType.Bool.t dataFormat (* Boolean *)
type numericType =
| Date
@@ -32,13 +32,20 @@ let priority: type a. a dataFormat -> int = function
type 'a types =
| Num : DataType.Num.t dataFormat * DataType.Num.t -> DataType.Num.t types (** A number *)
- | Str : DataType.String.t -> DataType.String.t types (** A string *)
- | Bool : DataType.Bool.t -> DataType.Bool.t types (** A boolean *)
+ | Str : DataType.String.t -> DataType.String.t types (** A string *)
+ | Bool : DataType.Bool.t -> DataType.Bool.t types (** A boolean *)
+
+let number n = Num (Number, n)
+let string s = Str s
+let date d = Num (Date, d)
+let boolean b = Bool b
+
type 'a returnType =
| Num : DataType.Num.t dataFormat option -> DataType.Num.t returnType (** A number *)
- | Str : DataType.String.t returnType (** A string *)
- | Bool : DataType.Bool.t returnType (** A boolean *)
+ | Str : DataType.String.t returnType (** A string *)
+ | Bool : DataType.Bool.t returnType (** A boolean *)
+
let f_num: DataType.Num.t returnType = Num None
let f_date: DataType.Num.t returnType = Num (Some Date)
diff --git a/scTypes.mli b/scTypes.mli
index 17b51eb..5e5b378 100755..100644
--- a/scTypes.mli
+++ b/scTypes.mli
@@ -11,13 +11,13 @@ type 'a number_format = (float -> 'a, Format.formatter, unit) format
type 'a dataFormat =
| Date: DataType.Num.t dataFormat (* A date in julian day *)
| Number: DataType.Num.t dataFormat (* Number *)
- | String: DataType.String.t dataFormat (* String result, there is only one representation *)
- | Bool: DataType.Bool.t dataFormat (* Boolean result *)
+ | String: DataType.String.t dataFormat (* String *)
+ | Bool: DataType.Bool.t dataFormat (* Boolean *)
type 'a returnType =
| Num : DataType.Num.t dataFormat option -> DataType.Num.t returnType (** A number *)
- | Str : DataType.String.t returnType (** A string *)
- | Bool : DataType.Bool.t returnType (** A boolean *)
+ | Str : DataType.String.t returnType (** A string *)
+ | Bool : DataType.Bool.t returnType (** A boolean *)
type numericType =
| Date
@@ -25,10 +25,15 @@ type numericType =
val get_numeric_type: DataType.Num.t dataFormat -> numericType
-type 'a types =
+type 'a types = private
| Num : DataType.Num.t dataFormat * DataType.Num.t -> DataType.Num.t types (** A number *)
- | Str : DataType.String.t -> DataType.String.t types (** A string *)
- | Bool : DataType.Bool.t -> DataType.Bool.t types (** A boolean *)
+ | Str : DataType.String.t -> DataType.String.t types (** A string *)
+ | Bool : DataType.Bool.t -> DataType.Bool.t types (** A boolean *)
+
+val number: DataType.Num.t -> DataType.Num.t types
+val string: DataType.String.t -> DataType.String.t types
+val boolean: DataType.Bool.t -> DataType.Bool.t types
+val date: DataType.Num.t -> DataType.Num.t types
type typeContainer =
| Value: 'a types -> typeContainer
diff --git a/tests/expressionParser_test.ml b/tests/expressionParser_test.ml
index 476e3aa..30bd665 100755
--- a/tests/expressionParser_test.ml
+++ b/tests/expressionParser_test.ml
@@ -19,11 +19,10 @@ let test_num ctx = begin
let expected = Expression.Formula (
Expression.Expression (
- ScTypes.Value (
- ScTypes.Num (
- ScTypes.Number,
+ ScTypes.Value (ScTypes.number (
DataType.Num.of_num (Num.num_of_int 1)
- )))) in
+ )
+ ))) in
let result = load_expr "=1" in
assert_equal
@@ -54,8 +53,7 @@ let test_call2 ctx = begin
let expected = Expression.Formula (
Expression.Expression (
ScTypes.Call (
- u"foo2", [ScTypes.Value (ScTypes.Num (
- ScTypes.Number,
+ u"foo2", [ScTypes.Value (ScTypes.number (
DataType.Num.of_num (Num.num_of_int 4)
))]))) in
let result = load_expr "=foo2(4)" in
diff --git a/tests/expression_test.ml b/tests/expression_test.ml
index 0950383..2fa4d9b 100755
--- a/tests/expression_test.ml
+++ b/tests/expression_test.ml
@@ -28,7 +28,7 @@ let assert_equal expected result =
let test_str ctx = begin
let result = Expression.load @@ u"cafe" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Str (u"cafe")) in
+ ScTypes.string (u"cafe")) in
assert_equal expected result
end
@@ -36,7 +36,7 @@ end
let test_str_space ctx = begin
let result = Expression.load @@ u" =cafe" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Str (u" =cafe")) in
+ ScTypes.string (u" =cafe")) in
assert_equal expected result
end
@@ -45,15 +45,14 @@ let test_formula_str ctx = begin
let expected = Expression.load_expr @@ Expression.Formula (
Expression.Expression (
ScTypes.Value (
- ScTypes.Str (u"cafe")))) in
+ ScTypes.string (u"cafe")))) in
assert_equal expected result
end
let test_num ctx = begin
let result = Expression.load @@ u"123" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Num (
- ScTypes.Number,
+ ScTypes.number (
DataType.Num.of_num @@ Num.num_of_int 123
)) in
assert_equal expected result
@@ -62,8 +61,7 @@ end
let test_float ctx = begin
let result = Expression.load @@ u"12.45" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Num (
- ScTypes.Number,
+ ScTypes.number (
DataType.Num.of_num @@ T.Num.of_float_string "12.45"
)) in
assert_equal expected result
@@ -72,8 +70,7 @@ end
let test_relative ctx = begin
let result = Expression.load @@ u"-123" in
let expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Num (
- ScTypes.Number,
+ ScTypes.number (
DataType.Num.of_num @@ Num.num_of_int (-123)
)) in
assert_equal expected result
@@ -82,8 +79,7 @@ end
let test_date ctx = begin
let result = Expression.load @@ u"1900/01/01"
and expected = Expression.load_expr @@ Expression.Basic (
- ScTypes.Num (
- ScTypes.Date,
+ ScTypes.date (
DataType.Num.of_num @@ Date.get_julian_day 1900 01 01
)) in
assert_equal expected result
diff --git a/tests/odf/odf_ExpressionParser_test.ml b/tests/odf/odf_ExpressionParser_test.ml
index becf9ab..8b4e4ff 100755
--- a/tests/odf/odf_ExpressionParser_test.ml
+++ b/tests/odf/odf_ExpressionParser_test.ml
@@ -14,8 +14,7 @@ let _msg ~(expected:ScTypes.expression) ~(result:ScTypes.expression) =
-let build_num value = ScTypes.Num (
- ScTypes.Number,
+let build_num value = ScTypes.number (
DataType.Num.of_num @@ Num.num_of_int value
)
@@ -32,7 +31,7 @@ let test_formula ctx = begin
Call(u"CONCATENATE", [
Call (u"SUM", [
Ref (Range (((6, 16), (false, false)), (((36, 16), (false, false)))))]);
- Value (Str (u"/"));
+ Value (string (u"/"));
Call(u"*", [
Value (build_num 8);
Call(u"NETWORKDAYS", [
diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml
index 084118f..7353dc6 100755
--- a/tests/sheet_test.ml
+++ b/tests/sheet_test.ml
@@ -16,8 +16,7 @@ let _msg ~expected ~result = begin
(get_string result)
end
-let build_num value = ScTypes.Num (
- ScTypes.Number,
+let build_num value = ScTypes.number (
DataType.Num.of_num @@ Num.num_of_int value
)