From 01d7f77f65c3a2b83978b1f00c87b54f00647816 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 25 Oct 2017 14:50:32 +0200 Subject: Update sheet traversal --- odf/odf.ml | 42 +++++++++++++++++++++++++++--------------- odf/odf_ExpressionParser.mly | 5 ++++- 2 files changed, 31 insertions(+), 16 deletions(-) (limited to 'odf') diff --git a/odf/odf.ml b/odf/odf.ml index 7af44a9..b091bc9 100755 --- a/odf/odf.ml +++ b/odf/odf.ml @@ -31,10 +31,14 @@ let load_formula formula = let load_content content = begin function | "float" -> Expression.Basic ( ScTypes.Num ( - (Tools.Num.of_float_string content), Some (u @@ Tools.String.filter_float content))) + ScTypes.Number, + DataType.Num.of_num (Tools.Num.of_float_string content) + )) | "date" -> Expression.Basic ( - ScTypes.Date ( - Tools.Date.from_string content)) + ScTypes.Num ( + ScTypes.Date, + DataType.Num.of_num (Tools.Num.of_float_string content) + )) | _ -> Expression.Basic ( ScTypes.Str ( UTF8.from_utf8string content)) @@ -164,15 +168,19 @@ let write_bool = write_type "bool" "bool" let write_error = write_type "string" "error" let write_date = write_type "date" "date" -let write_basic attrs output = begin function - | ScTypes.Num (n,_) -> - let value = (string_of_float @@ Num.float_of_num n) in - write_num ((NS.value_attr, value)::attrs) output value +let write_basic: type a. 'b list -> Xmlm.output -> a ScTypes.types -> unit = fun attrs output types -> begin match types with | ScTypes.Str s -> write_str attrs output (UTF8.to_utf8string s) | ScTypes.Bool b -> write_bool attrs output (string_of_bool b) - | ScTypes.Date d -> - let value = Tools.Date.to_string d in + | ScTypes.Num (data_type, d) -> + let n = DataType.Num.to_num d in + begin match ScTypes.get_numeric_type data_type with + | ScTypes.Number -> + let value = (string_of_float @@ Num.float_of_num n) in + write_num ((NS.value_attr, value)::attrs) output value + | ScTypes.Date -> + let value = Date.to_string n in write_date ((NS.date_value_attr, value)::attrs) output value + end end let write_formula output attrs f = begin function @@ -191,17 +199,21 @@ let print_ref buffer c = end; UTF8.Buffer.add_string buffer @@ u"]" -let rec print_expr buffer = begin function - | ScTypes.Value (ScTypes.Num (n, _)) -> - UTF8.Buffer.add_string buffer @@ u(string_of_float @@ Num.float_of_num n) +let rec print_expr : UTF8.Buffer.buffer -> ScTypes.expression -> unit = fun buffer -> begin function | ScTypes.Value (ScTypes.Str s) -> UTF8.Printf.bprintf buffer "\"%s\"" (UTF8.to_utf8string s) | ScTypes.Value (ScTypes.Bool b) -> u(string_of_bool b) |> UTF8.Buffer.add_string buffer - | ScTypes.Value (ScTypes.Date d) -> - u(Tools.Date.to_string d) - |> UTF8.Buffer.add_string buffer + | ScTypes.Value (ScTypes.Num (data_type, d)) -> + let n = DataType.Num.to_num d in + begin match ScTypes.get_numeric_type data_type with + | ScTypes.Number -> + UTF8.Buffer.add_string buffer @@ u(string_of_float @@ Num.float_of_num n) + | ScTypes.Date -> + u(Date.to_string n) + |> UTF8.Buffer.add_string buffer + end | ScTypes.Ref r -> print_ref buffer r | ScTypes.Expression x -> UTF8.Buffer.add_char buffer '('; diff --git a/odf/odf_ExpressionParser.mly b/odf/odf_ExpressionParser.mly index 9731699..1b60e1c 100755 --- a/odf/odf_ExpressionParser.mly +++ b/odf/odf_ExpressionParser.mly @@ -43,7 +43,10 @@ value: | LETTERS COLON EQ expr EOF {$4} expr: - | num {Value (Num ((snd $1), Some (u(fst $1))))} + | num {Value (Num ( + Number, + DataType.Num.of_num @@ snd $1 + ))} | MINUS expr {Call (F.sub, [$2])} | PLUS expr {Call (F.add, [$2])} -- cgit v1.2.3