Pārlūkot izejas kodu

added #if( v >= ~/1.5/ ) syntax for checking against semantic versioning

ncannasse 6 gadi atpakaļ
vecāks
revīzija
1c6a91fe6a
2 mainītis faili ar 9 papildinājumiem un 0 dzēšanām
  1. 1 0
      src/syntax/grammar.mly
  2. 8 0
      src/syntax/parserEntry.ml

+ 1 - 0
src/syntax/grammar.mly

@@ -1468,6 +1468,7 @@ let rec validate_macro_cond s e = match fst e with
 	| EConst (String _)
 	| EConst (Int _)
 	| EConst (Float _)
+	| EConst (Regexp _)
 		-> e
 	| EUnop (op,p,e1) -> (EUnop (op, p, validate_macro_cond s e1), snd e)
 	| EBinop (op,e1,e2) -> (EBinop(op, (validate_macro_cond s e1), (validate_macro_cond s e2)), snd e)

+ 8 - 0
src/syntax/parserEntry.ml

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