From 84652d299e934d1431e5b5b9d2dd17f00598e931 Mon Sep 17 00:00:00 2001 From: SBD580 Date: Tue, 2 Apr 2013 21:27:20 +0300 Subject: [PATCH 1/3] fix operator precedence bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit first check for 'op_${opName}' and then for 'op_${ltype}_${rtype}', as we might want to "{color} != {color}".  This is not an optimal solution, as a way to override a general operator by it's arguments type is something good and not viable this way. --- scss.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scss.inc.php b/scss.inc.php index 7ba58295..450f58ad 100644 --- a/scss.inc.php +++ b/scss.inc.php @@ -765,12 +765,12 @@ protected function reduce($value, $inExp = false) { // 3. op_[op name] $fn = "op_${opName}_${ltype}_${rtype}"; if (is_callable(array($this, $fn)) || - (($fn = "op_${ltype}_${rtype}") && - is_callable(array($this, $fn)) && - $passOp = true) || (($fn = "op_${opName}") && is_callable(array($this, $fn)) && - $genOp = true)) + $genOp = true) || + (($fn = "op_${ltype}_${rtype}") && + is_callable(array($this, $fn)) && + $passOp = true)) { $unitChange = false; if (!isset($genOp) && From f510f0fbe9b5668f262afa9fe78b9f9429569309 Mon Sep 17 00:00:00 2001 From: SBD580 Date: Fri, 5 Apr 2013 14:36:19 +0300 Subject: [PATCH 2/3] remove "!=" operator old bug fix and add new fix The previous fix break the tests and was not good. This is a new one which just implement the op_neq_color_color method so the "!=" operator will work on colors as well --- scss.inc.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scss.inc.php b/scss.inc.php index 450f58ad..bb329ba1 100644 --- a/scss.inc.php +++ b/scss.inc.php @@ -765,12 +765,12 @@ protected function reduce($value, $inExp = false) { // 3. op_[op name] $fn = "op_${opName}_${ltype}_${rtype}"; if (is_callable(array($this, $fn)) || - (($fn = "op_${opName}") && - is_callable(array($this, $fn)) && - $genOp = true) || (($fn = "op_${ltype}_${rtype}") && is_callable(array($this, $fn)) && - $passOp = true)) + $passOp = true) || + (($fn = "op_${opName}") && + is_callable(array($this, $fn)) && + $genOp = true)) { $unitChange = false; if (!isset($genOp) && @@ -1065,6 +1065,17 @@ protected function op_eq($left, $right) { protected function op_neq($left, $right) { return $this->toBool($left != $right); } + + protected function op_neq_color_color($left, $right) { + foreach (range(1, 4) as $i) { + $lval = isset($left[$i]) ? $left[$i] : 0; + $rval = isset($right[$i]) ? $right[$i] : 0; + if($lval!=$rval) + return $this->toBool(true); + } + + return $this->toBool(false); + } protected function op_gte_number_number($left, $right) { return $this->toBool($left[1] >= $right[1]); From 901808e196c48d5a2f79c9698899e477f212797c Mon Sep 17 00:00:00 2001 From: SBD580 Date: Fri, 5 Apr 2013 14:48:29 +0300 Subject: [PATCH 3/3] add support for "==" operator on colors Implement the op_eq_color_color in order to support the equality between two colors. In addition, fix small issue on "!=" operator when dealing with alpha value. --- scss.inc.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scss.inc.php b/scss.inc.php index bb329ba1..763132ce 100644 --- a/scss.inc.php +++ b/scss.inc.php @@ -1068,14 +1068,25 @@ protected function op_neq($left, $right) { protected function op_neq_color_color($left, $right) { foreach (range(1, 4) as $i) { - $lval = isset($left[$i]) ? $left[$i] : 0; - $rval = isset($right[$i]) ? $right[$i] : 0; + $lval = isset($left[$i]) ? $left[$i] : ($i==4?1:0); + $rval = isset($right[$i]) ? $right[$i] : ($i==4?1:0); if($lval!=$rval) return $this->toBool(true); } return $this->toBool(false); } + + protected function op_eq_color_color($left, $right) { + foreach (range(1, 4) as $i) { + $lval = isset($left[$i]) ? $left[$i] : ($i==4?1:0); + $rval = isset($right[$i]) ? $right[$i] : ($i==4?1:0); + if($lval!=$rval) + return $this->toBool(false); + } + + return $this->toBool(true); + } protected function op_gte_number_number($left, $right) { return $this->toBool($left[1] >= $right[1]);