@@ 72,7 72,7 @@ pushOp toks op b ops = parse' toks ((op, b):ops)
---- Shunting Yard Evaluator
--------
-- | Dynamic types for evaluating media queries.
-data Datum = B Bool | N Float | Ratio Float Float deriving Eq
+data Datum = B Bool | N Float | R {minv :: Float, maxv :: Float} | Ratio Float Float deriving Eq
-- | Evaluates a media query with the given functions for evaluating vars & tokens.
eval :: (Text -> Datum) -> (Token -> Datum) -> Expr -> Bool
@@ 89,10 89,24 @@ eval' stack v t (Tok (Ident name):ops) = eval' (v name:stack) v t ops
-- TODO: How should I handle ratios?
eval' (N y:N x:stack) v t (MkRatio:ops) = eval' (Ratio x y:stack) v t ops
eval' (N y:N x:stack) v t (Less:ops) = eval' (B (x < y):stack) v t ops
+eval' (R _ y:N x:stack) v t (Less:ops) = eval' (B (x < y):stack) v t ops
+eval' (N y: R x _:stack) v t (Less:ops) = eval' (B (x < y):stack) v t ops
+eval' (R _ y:R x _:stack) v t (Less:ops) = eval' (B (x < y):stack) v t ops
eval' (N y:N x:stack) v t (LessEq:ops) = eval' (B (x <= y):stack) v t ops
+eval' (R _ y:N x:stack) v t (LessEq:ops) = eval' (B (x <= y):stack) v t ops
+eval' (N y: R x _:stack) v t (LessEq:ops) = eval' (B (x <= y):stack) v t ops
+eval' (R _ y:R x _:stack) v t (LessEq:ops) = eval' (B (x <= y):stack) v t ops
+eval' (R yMin yMax:R xMin xMax:stack) v t (Equal:ops) =
+ eval' (B (xMax >= yMin && xMin <= yMax) : stack) v t ops
eval' (y:x:stack) v t (Equal:ops) = eval' (B (x == y):stack) v t ops
eval' (N y:N x:stack) v t (Greater:ops) = eval' (B (x > y):stack) v t ops
+eval' (R y _:N x:stack) v t (Greater:ops) = eval' (B (x > y):stack) v t ops
+eval' (N y:R _ x:stack) v t (Greater:ops) = eval' (B (x > y):stack) v t ops
+eval' (R y _:R _ x:stack) v t (Greater:ops) = eval' (B (x > y):stack) v t ops
eval' (N y:N x:stack) v t (GreaterEq:ops) = eval' (B (x >= y):stack) v t ops
+eval' (R y _:N x:stack) v t (GreaterEq:ops) = eval' (B (x >= y):stack) v t ops
+eval' (N y:R _ x:stack) v t (GreaterEq:ops) = eval' (B (x >= y):stack) v t ops
+eval' (R y _:R _ x:stack) v t (GreaterEq:ops) = eval' (B (x >= y):stack) v t ops
eval' (B ret:_) _ _ [] = ret
eval' [] _ _ [] = True -- Special case
eval' _ _ _ _ = False -- Error handling fallback.