From 10c799fd90bf61abb4ac43d5fc0e7b48ecb8c61a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 5 Nov 2011 08:30:08 +0100 Subject: [PATCH] changed the precedence of the .. operator --- CHANGELOG | 1 + lib/Twig/Extension/Core.php | 2 +- test/Twig/Tests/Fixtures/expressions/dotdot.test | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1de83b5..da1e22a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.4.0 + * changed the precedence of the .. operator to be more consistent with languages that implements such a feature like Ruby * added an Exception to Twig_Loader_Array::isFresh() method when the template does not exist to be consistent with other loaders * added Twig_Function_Node to allow more complex functions to have their own Node class * added Twig_Filter_Node to allow more complex filters to have their own Node class diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 465818d..27f20a9 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -149,6 +149,7 @@ class Twig_Extension_Core extends Twig_Extension '<=' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), 'not in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotIn', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), 'in' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_In', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), + '..' => array('precedence' => 25, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), '+' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Add', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), '-' => array('precedence' => 30, 'class' => 'Twig_Node_Expression_Binary_Sub', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), '~' => array('precedence' => 40, 'class' => 'Twig_Node_Expression_Binary_Concat', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), @@ -158,7 +159,6 @@ class Twig_Extension_Core extends Twig_Extension '%' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), 'is' => array('precedence' => 100, 'callable' => array($this, 'parseTestExpression'), 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), 'is not' => array('precedence' => 100, 'callable' => array($this, 'parseNotTestExpression'), 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), - '..' => array('precedence' => 110, 'class' => 'Twig_Node_Expression_Binary_Range', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), '**' => array('precedence' => 200, 'class' => 'Twig_Node_Expression_Binary_Power', 'associativity' => Twig_ExpressionParser::OPERATOR_RIGHT), ), ); diff --git a/test/Twig/Tests/Fixtures/expressions/dotdot.test b/test/Twig/Tests/Fixtures/expressions/dotdot.test index b3ee396..9cd0676 100644 --- a/test/Twig/Tests/Fixtures/expressions/dotdot.test +++ b/test/Twig/Tests/Fixtures/expressions/dotdot.test @@ -8,10 +8,13 @@ Twig supports the .. operator {% for letter in 'a'|upper..'z'|upper %}{{ letter }} {% endfor %} {% for i in foo[0]..foo[1] %}{{ i }} {% endfor %} + +{% for i in 0 + 1 .. 10 - 1 %}{{ i }} {% endfor %} --DATA-- return array('foo' => array(1, 10)) --EXPECT-- 0 1 2 3 4 5 6 7 8 9 10 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z -1 2 3 4 5 6 7 8 9 10 +1 2 3 4 5 6 7 8 9 10 +1 2 3 4 5 6 7 8 9 -- 1.7.2.5