aboutsummaryrefslogtreecommitdiff
path: root/expression.ml
diff options
context:
space:
mode:
Diffstat (limited to 'expression.ml')
-rwxr-xr-xexpression.ml19
1 files changed, 10 insertions, 9 deletions
diff --git a/expression.ml b/expression.ml
index 0bc8f43..31b6369 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 =
+ ExpressionParser.content ExpressionLexer.read
+ @@ Lexing.from_string content' 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