|
@@ -28,11 +28,15 @@ type small_type =
|
|
| TBool of bool
|
|
| TBool of bool
|
|
| TFloat of float
|
|
| TFloat of float
|
|
| TString of string
|
|
| TString of string
|
|
|
|
+ | TVersion of int list
|
|
|
|
|
|
let is_true = function
|
|
let is_true = function
|
|
| TBool false | TNull | TFloat 0. | TString "" -> false
|
|
| TBool false | TNull | TFloat 0. | TString "" -> false
|
|
| _ -> true
|
|
| _ -> true
|
|
|
|
|
|
|
|
+let make_version s =
|
|
|
|
+ List.map (fun s -> try int_of_string s with _ -> 0) (ExtString.String.nsplit s ".")
|
|
|
|
+
|
|
let cmp v1 v2 =
|
|
let cmp v1 v2 =
|
|
match v1, v2 with
|
|
match v1, v2 with
|
|
| TNull, TNull -> 0
|
|
| TNull, TNull -> 0
|
|
@@ -41,6 +45,9 @@ let cmp v1 v2 =
|
|
| TBool a, TBool b -> compare a b
|
|
| TBool a, TBool b -> compare a b
|
|
| TString a, TFloat b -> compare (float_of_string a) b
|
|
| TString a, TFloat b -> compare (float_of_string a) b
|
|
| TFloat a, TString b -> compare a (float_of_string b)
|
|
| TFloat a, TString b -> compare a (float_of_string b)
|
|
|
|
+ | TVersion a, TVersion b -> compare a b
|
|
|
|
+ | TString a, TVersion b -> compare (make_version a) b
|
|
|
|
+ | TVersion a, TString b -> compare a (make_version b)
|
|
| _ -> raise Exit (* always false *)
|
|
| _ -> raise Exit (* always false *)
|
|
|
|
|
|
let rec eval ctx (e,p) =
|
|
let rec eval ctx (e,p) =
|
|
@@ -50,6 +57,7 @@ let rec eval ctx (e,p) =
|
|
| EConst (String s) -> TString s
|
|
| EConst (String s) -> TString s
|
|
| EConst (Int i) -> TFloat (float_of_string i)
|
|
| EConst (Int i) -> TFloat (float_of_string i)
|
|
| EConst (Float f) -> TFloat (float_of_string f)
|
|
| EConst (Float f) -> TFloat (float_of_string f)
|
|
|
|
+ | EConst (Regexp (s,_)) -> TVersion (make_version s)
|
|
| EBinop (OpBoolAnd, e1, e2) -> TBool (is_true (eval ctx e1) && is_true (eval ctx e2))
|
|
| EBinop (OpBoolAnd, e1, e2) -> TBool (is_true (eval ctx e1) && is_true (eval ctx e2))
|
|
| EBinop (OpBoolOr, e1, e2) -> TBool (is_true (eval ctx e1) || is_true(eval ctx e2))
|
|
| EBinop (OpBoolOr, e1, e2) -> TBool (is_true (eval ctx e1) || is_true(eval ctx e2))
|
|
| EUnop (Not, _, e) -> TBool (not (is_true (eval ctx e)))
|
|
| EUnop (Not, _, e) -> TBool (not (is_true (eval ctx e)))
|