From c2c01dedf864fbd0a3811ba76ad933b6cb0290c4 Mon Sep 17 00:00:00 2001 From: Josh Turmel Date: Wed, 27 Jul 2011 02:10:01 -0500 Subject: [PATCH] Add bitwise operators to core * Added bitwise operators (and, xor, or) to core --- lib/Twig/Extension/Core.php | 3 +++ lib/Twig/Node/Expression/Binary/BitwiseAnd.php | 18 ++++++++++++++++++ lib/Twig/Node/Expression/Binary/BitwiseOr.php | 18 ++++++++++++++++++ lib/Twig/Node/Expression/Binary/BitwiseXor.php | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 0 deletions(-) create mode 100644 lib/Twig/Node/Expression/Binary/BitwiseAnd.php create mode 100644 lib/Twig/Node/Expression/Binary/BitwiseOr.php create mode 100644 lib/Twig/Node/Expression/Binary/BitwiseXor.php diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 2c9bdb6..bf3cd12 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -129,6 +129,9 @@ class Twig_Extension_Core extends Twig_Extension '+' => array('precedence' => 50, '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), '==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), diff --git a/lib/Twig/Node/Expression/Binary/BitwiseAnd.php b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php new file mode 100644 index 0000000..9a46d84 --- /dev/null +++ b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php @@ -0,0 +1,18 @@ +raw('&'); + } +} diff --git a/lib/Twig/Node/Expression/Binary/BitwiseOr.php b/lib/Twig/Node/Expression/Binary/BitwiseOr.php new file mode 100644 index 0000000..058a20b --- /dev/null +++ b/lib/Twig/Node/Expression/Binary/BitwiseOr.php @@ -0,0 +1,18 @@ +raw('|'); + } +} diff --git a/lib/Twig/Node/Expression/Binary/BitwiseXor.php b/lib/Twig/Node/Expression/Binary/BitwiseXor.php new file mode 100644 index 0000000..f4da73d --- /dev/null +++ b/lib/Twig/Node/Expression/Binary/BitwiseXor.php @@ -0,0 +1,18 @@ +raw('^'); + } +} -- 1.7.2.5