|
@@ -19,6 +19,7 @@
|
|
open Globals
|
|
open Globals
|
|
open Ast
|
|
open Ast
|
|
open Parser
|
|
open Parser
|
|
|
|
+open Semver
|
|
open Grammar
|
|
open Grammar
|
|
open DisplayPosition
|
|
open DisplayPosition
|
|
|
|
|
|
@@ -28,25 +29,12 @@ 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
|
|
|
|
|
|
+ | TVersion of (version * version * version) * (version list option)
|
|
|
|
|
|
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 rec compare_version a b =
|
|
|
|
- match a, b with
|
|
|
|
- | [], [] -> 0
|
|
|
|
- | 0 :: l1, [] -> compare_version l1 []
|
|
|
|
- | [], 0 :: l2 -> compare_version [] l2
|
|
|
|
- | a :: l1 , b :: l2 when a = b -> compare_version l1 l2
|
|
|
|
- | a :: _, b :: _ -> compare a b
|
|
|
|
- | (_ :: _, []) -> 1
|
|
|
|
- | ([] , _ :: _) -> -1
|
|
|
|
-
|
|
|
|
let cmp v1 v2 =
|
|
let cmp v1 v2 =
|
|
match v1, v2 with
|
|
match v1, v2 with
|
|
| TNull, TNull -> 0
|
|
| TNull, TNull -> 0
|
|
@@ -55,9 +43,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_version a b
|
|
|
|
- | TString a, TVersion b -> compare_version (make_version a) b
|
|
|
|
- | TVersion a, TString b -> compare_version a (make_version b)
|
|
|
|
|
|
+ | TString a, TVersion (release,pre) -> compare_version (parse_version a) (release,pre)
|
|
|
|
+ | TVersion (release,pre), TString b -> compare_version (release,pre) (parse_version b)
|
|
|
|
+ | TVersion (release1,pre1), TVersion (release2,pre2) -> compare_version (release1,pre1) (release2,pre2)
|
|
| _ -> raise Exit (* always false *)
|
|
| _ -> raise Exit (* always false *)
|
|
|
|
|
|
let rec eval ctx (e,p) =
|
|
let rec eval ctx (e,p) =
|
|
@@ -67,7 +55,9 @@ 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)
|
|
- | ECall ((EConst (Ident "version"),_),[(EConst (String s),_)]) -> TVersion (make_version s)
|
|
|
|
|
|
+ | ECall ((EConst (Ident "version"),_),[(EConst (String s), p)]) ->
|
|
|
|
+ (try match parse_version s with release,pre -> TVersion (release,pre)
|
|
|
|
+ with Invalid_argument msg -> error (Custom msg) p)
|
|
| 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)))
|
|
@@ -76,7 +66,8 @@ let rec eval ctx (e,p) =
|
|
let v1 = eval ctx e1 in
|
|
let v1 = eval ctx e1 in
|
|
let v2 = eval ctx e2 in
|
|
let v2 = eval ctx e2 in
|
|
let compare op =
|
|
let compare op =
|
|
- TBool (try op (cmp v1 v2) 0 with _ -> false)
|
|
|
|
|
|
+ try TBool (try op (cmp v1 v2) 0 with _ -> false)
|
|
|
|
+ with Invalid_argument msg -> error (Custom msg) p
|
|
in
|
|
in
|
|
(match op with
|
|
(match op with
|
|
| OpEq -> compare (=)
|
|
| OpEq -> compare (=)
|