added support for a trailing , when defining arrays
authorfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Tue, 22 Dec 2009 07:35:57 +0000 (07:35 +0000)
committerfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Tue, 22 Dec 2009 07:35:57 +0000 (07:35 +0000)
git-svn-id: http://svn.twig-project.org/trunk@196 93ef8e89-cb99-4229-a87c-7fa0fa45744b

lib/Twig/ExpressionParser.php
test/fixtures/expressions/array.test

index 57d3030..8e5e81a 100644 (file)
@@ -302,6 +302,12 @@ class Twig_ExpressionParser
       if (!empty($elements))
       {
         $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ',');
+
+        // trailing ,?
+        if ($this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, ']'))
+        {
+          return new Twig_Node_Expression_Array($elements, $this->parser->getCurrentToken()->getLine());
+        }
       }
 
       // hash or array element?
index 21bff14..3ebdeaa 100644 (file)
@@ -19,6 +19,14 @@ Twig supports array notation
 
 {# elements can be any expression #}
 {{ ['foo'|upper, bar|upper, bar == foo]|join(',') }}
+
+{# arrays can have a trailing , like in PHP #}
+{{
+  [
+    1,
+    2,
+  ]|join(',')
+}}
 --DATA--
 return array('bar' => 'bar', 'foo' => array('bar' => 'bar'))
 --EXPECT--
@@ -36,3 +44,6 @@ bar
 
 
 FOO,BAR,
+
+
+1,2