From 6f6ff0e39eb6d771ef5336394079646ccdc18bd5 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 7 Nov 2017 15:44:40 +0100 Subject: Use Zarith instead of Num for computing numbers --- odf/odf.ml | 19 ++++++++++--------- odf/odf_ExpressionLexer.mll | 18 +++++++++--------- odf/odf_ExpressionParser.mly | 16 +++++++--------- 3 files changed, 26 insertions(+), 27 deletions(-) (limited to 'odf') diff --git a/odf/odf.ml b/odf/odf.ml index 8fa3411..ae120d9 100755 --- a/odf/odf.ml +++ b/odf/odf.ml @@ -31,11 +31,11 @@ let load_formula formula = let load_content content = begin function | "float" -> Expression.Basic ( ScTypes.number ( - DataType.Num.of_num (Tools.Num.of_float_string content) + DataType.Num.of_float (float_of_string content) )) | "date" -> Expression.Basic ( ScTypes.date ( - DataType.Num.of_num (Tools.Num.of_float_string content) + DataType.Num.of_float (float_of_string content) )) | _ -> Expression.Basic ( ScTypes.string ( @@ -170,13 +170,13 @@ let write_basic: type a. 'b list -> Xmlm.output -> a ScTypes.types -> unit = fun | ScTypes.Str s -> write_str attrs output (UTF8.to_utf8string s) | ScTypes.Bool b -> write_bool attrs output (string_of_bool b) | 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 + let f = DataType.Num.to_float d in + let value = string_of_float f in write_num ((NS.value_attr, value)::attrs) output value | ScTypes.Date -> - let value = Date.to_string n in + let value = DataType.Date.to_string d in write_date ((NS.date_value_attr, value)::attrs) output value end end @@ -204,13 +204,14 @@ let rec print_expr : UTF8.Buffer.buffer -> ScTypes.expression -> unit = fun buff u(string_of_bool b) |> 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) + let f = DataType.Num.to_float d in + UTF8.Buffer.add_string buffer @@ u(string_of_float f) | ScTypes.Date -> - u(Date.to_string n) - |> UTF8.Buffer.add_string buffer + DataType.Date.to_string d + |> u + |> UTF8.Buffer.add_string buffer end | ScTypes.Ref r -> print_ref buffer r | ScTypes.Expression x -> diff --git a/odf/odf_ExpressionLexer.mll b/odf/odf_ExpressionLexer.mll index 1db73c3..7f6a55b 100755 --- a/odf/odf_ExpressionLexer.mll +++ b/odf/odf_ExpressionLexer.mll @@ -26,8 +26,8 @@ let cell = letters+ digit+ rule read = parse | space+ { read lexbuf } - | digit+ as _1 { NUM (_1, Num.num_of_string _1)} - | real as _1 { REAL (Tools.String.filter_float _1, Tools.Num.of_float_string _1)} + | digit+ as _1 { NUM _1} + | real as _1 { REAL (Tools.String.filter_float _1)} | '$' { DOLLAR } | '=' { EQ } @@ -58,14 +58,14 @@ rule read = parse and read_string buf = parse | '"' { STR (Buffer.contents buf) } - | '\\' '/' { Buffer.add_char buf '/'; read_string buf lexbuf } - | '\\' '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf } - | '\\' 'b' { Buffer.add_char buf '\b'; read_string buf lexbuf } + | '\\' '/' { Buffer.add_char buf '/'; read_string buf lexbuf } + | '\\' '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf } + | '\\' 'b' { Buffer.add_char buf '\b'; read_string buf lexbuf } | '\\' 'f' { Buffer.add_char buf '\012'; read_string buf lexbuf } - | '\\' 'n' { Buffer.add_char buf '\n'; read_string buf lexbuf } - | '\\' 'r' { Buffer.add_char buf '\r'; read_string buf lexbuf } - | '\\' 't' { Buffer.add_char buf '\t'; read_string buf lexbuf } - | '\\' '"' { Buffer.add_char buf '"'; read_string buf lexbuf } + | '\\' 'n' { Buffer.add_char buf '\n'; read_string buf lexbuf } + | '\\' 'r' { Buffer.add_char buf '\r'; read_string buf lexbuf } + | '\\' 't' { Buffer.add_char buf '\t'; read_string buf lexbuf } + | '\\' '"' { Buffer.add_char buf '"'; read_string buf lexbuf } | [^ '"' '\\' '\000']+ { Buffer.add_string buf (Lexing.lexeme lexbuf); read_string buf lexbuf diff --git a/odf/odf_ExpressionParser.mly b/odf/odf_ExpressionParser.mly index 190e6f1..6b571a9 100755 --- a/odf/odf_ExpressionParser.mly +++ b/odf/odf_ExpressionParser.mly @@ -4,12 +4,12 @@ let u = UTF8.from_utf8string - let extractColumnNameFromNum (fixed, (str, value)) = (fixed, value) + let extractColumnNameFromNum (fixed, str) = (fixed, int_of_string str) %} -%token REAL -%token NUM +%token REAL +%token NUM %token STR %token LETTERS @@ -43,9 +43,7 @@ value: | LETTERS COLON EQ expr EOF {$4} expr: - | num {Value (number ( - DataType.Num.of_num @@ snd $1 - ))} + | num {Value (number ($1))} | MINUS expr {Call (F.sub, [$2])} | PLUS expr {Call (F.add, [$2])} @@ -85,8 +83,8 @@ fixed(X): | X {false, $1} num: - | REAL {$1} - | NUM {$1} + | REAL {DataType.Num.of_float @@ float_of_string $1} + | NUM {DataType.Num.of_int @@ int_of_string $1} ident: | IDENT { $1 } @@ -94,4 +92,4 @@ ident: text: | LETTERS { $1 } - | NUM { fst $1 } + | NUM { $1 } -- cgit v1.2.3