From 8c5853e3b1ce0d4e877ad1fff6b314aca62f6578 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 30 Oct 2012 17:40:52 +0100 Subject: [PATCH] fixed bitwise operator precedences (closes #866) --- CHANGELOG | 1 + lib/Twig/Extension/Core.php | 6 +++--- test/Twig/Tests/Fixtures/expressions/bitwise.test | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 92cdb8c..f1656ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.11.0 (2012-XX-XX) + * fixed bitwise operator precedences * added the template_from_string function * fixed default timezone usage for the date function * optimized the way Twig exceptions are managed (to make them faster) diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 372e40d..9bbff6d 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -228,11 +228,11 @@ class Twig_Extension_Core extends Twig_Extension '+' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'), ), array( - 'b-and' => array('precedence' => 5, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), - 'b-xor' => array('precedence' => 5, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), - 'b-or' => array('precedence' => 5, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), 'or' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), 'and' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'b-or' => array('precedence' => 16, 'class' => 'Twig_Node_Expression_Binary_BitwiseOr', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'b-xor' => array('precedence' => 17, 'class' => 'Twig_Node_Expression_Binary_BitwiseXor', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + 'b-and' => array('precedence' => 18, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), '==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), '!=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), '<' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), diff --git a/test/Twig/Tests/Fixtures/expressions/bitwise.test b/test/Twig/Tests/Fixtures/expressions/bitwise.test index 911094c..369d48a 100644 --- a/test/Twig/Tests/Fixtures/expressions/bitwise.test +++ b/test/Twig/Tests/Fixtures/expressions/bitwise.test @@ -4,9 +4,11 @@ Twig supports bitwise operations {{ 1 b-and 5 }} {{ 1 b-or 5 }} {{ 1 b-xor 5 }} +{{ 1 b-and 1 + 1 }} == {{ band }} --DATA-- -return array() +return array('band' => (1 & 1 + 1)) --EXPECT-- 1 5 4 +1 == 1 -- 1.7.2.5