added support for a trailing , when defining arrays

git-svn-id: http://svn.twig-project.org/trunk@196 93ef8e89-cb99-4229-a87c-7fa0fa45744b
This commit is contained in:
fabien
2009-12-22 07:35:57 +00:00
parent 8a9401ca74
commit 7f6f7bb287
2 changed files with 17 additions and 0 deletions
+6
View 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?
+11
View 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