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 --- expression.ml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'expression.ml') diff --git a/expression.ml b/expression.ml index 0bc8f43..c61131e 100755 --- a/expression.ml +++ b/expression.ml @@ -3,9 +3,9 @@ module Tuple2 = Tools.Tuple2 let u = UTF8.from_utf8string type t = - | Basic of ScTypes.types (** A direct type *) - | Formula of formula (** A formula *) - | Undefined (** The content is not defined *) + | Basic: 'a ScTypes.types -> t (** A direct type *) + | Formula: formula -> t (** A formula *) + | Undefined: t (** The content is not defined *) and formula = | Expression of ScTypes.expression (** A valid expression *) @@ -33,11 +33,12 @@ let load content = begin let content' = try String.sub content 0 (String.index content '\000') with Not_found -> content in - Basic ( - try Lexing.from_string content' - |> ExpressionParser.content ExpressionLexer.read - with _ -> ScTypes.Str (UTF8.from_utf8string content') - ) + try + let ScTypes.Result r = + Lexing.from_string content' + |> ExpressionParser.content ExpressionLexer.read in + Basic r + with _ -> Basic (ScTypes.Str (UTF8.from_utf8string content')) ) ) else ( (* If the string in empty, build an undefined value *) @@ -58,7 +59,7 @@ let eval expr sources = begin begin try match expr with | Basic value -> ScTypes.Result value - | Formula (Expression f) -> ScTypes.Result (eval_exp f) + | Formula (Expression f) -> eval_exp f | Formula (Error (i, s)) -> ScTypes.Error ScTypes.Error | Undefined -> ScTypes.Error Not_found with ex -> ScTypes.Error ex -- cgit v1.2.3 From d8ed0babfa1c03c8f1968443a465972bb3bf460c Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 31 Oct 2017 15:59:38 +0100 Subject: Merged Evaluator types with ScTypes --- evaluator.ml | 11 +++++------ expression.ml | 4 ++-- sheet.ml | 7 +------ 3 files changed, 8 insertions(+), 14 deletions(-) (limited to 'expression.ml') diff --git a/evaluator.ml b/evaluator.ml index c17a397..f2a49d9 100755 --- a/evaluator.ml +++ b/evaluator.ml @@ -280,8 +280,8 @@ let repr mapper value = begin | ScTypes.Refs.Array1 l -> (* Guess the list type from it's first defined element *) let Result r = extract_value (Tools.List.find_map (fun x -> x) l) in - let format_of = Data.format_of_value r in - let type_of = Data.type_of_value r in + let format_of = Data.format_of_value r + and type_of = Data.type_of_value r in (* Build the list with all the elements *) let elems, format = List.fold_left (add_elem type_of) ([], format_of) l in Result (Data.List (format, elems)) @@ -289,13 +289,13 @@ let repr mapper value = begin (* Guess the list type from it's first defined element *) let Result r = extract_value (Tools.List.find_map2 (fun x -> x) l) in - let format_of = Data.format_of_value r in - let type_of = Data.type_of_value r in + let format_of = Data.format_of_value r + and type_of = Data.type_of_value r in (* Build the list with all the elements *) let elems, format = List.fold_left (fun (result, format_of) elems -> let elems, format = List.fold_left (add_elem type_of) ([], format_of) elems in elems::result, (Data.most_generic_format format_of format) - ) ([], format_of) l in + ) ([], format_of) l in Result (Data.Matrix (format, elems)) end @@ -308,7 +308,6 @@ let repr mapper value = begin end 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)) diff --git a/expression.ml b/expression.ml index c61131e..31b6369 100755 --- a/expression.ml +++ b/expression.ml @@ -35,8 +35,8 @@ let load content = begin with Not_found -> content in try let ScTypes.Result r = - Lexing.from_string content' - |> ExpressionParser.content ExpressionLexer.read in + ExpressionParser.content ExpressionLexer.read + @@ Lexing.from_string content' in Basic r with _ -> Basic (ScTypes.Str (UTF8.from_utf8string content')) ) diff --git a/sheet.ml b/sheet.ml index 241039e..67b1ee1 100755 --- a/sheet.ml +++ b/sheet.ml @@ -50,13 +50,8 @@ module Raw = struct *) let get_ref from t ref : ScTypes.result option ScTypes.Refs.range = begin - let extract_values = begin function - | ScTypes.Error e -> raise e - | v -> v - end in - ScTypes.Refs.collect ref - |> ScTypes.Refs.map (fun coord -> Option.map extract_values (get_value coord t)) + |> ScTypes.Refs.map (fun coord -> get_value coord t) end -- cgit v1.2.3