if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) {
$stream->next();
+ if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
+ $length = new Twig_Node_Expression_Constant(null, $token->getLine());
+ } else {
+ $length = $this->parseExpression();
+ }
+
$class = $this->getFilterNodeClass('slice');
- $arguments = new Twig_Node(array($arg, $this->parseExpression()));
+ $arguments = new Twig_Node(array($arg, $length));
$filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine());
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
--TEST--
"slice" filter
--TEMPLATE--
-{{ [1, 2, 3, 4][1:2]|join('')}}
+{{ [1, 2, 3, 4][1:2]|join('') }}
{{ {a: 1, b: 2, c: 3, d: 4}[1:2]|join('') }}
{{ [1, 2, 3, 4][start:length]|join('') }}
{{ [1, 2, 3, 4]|slice(1, 2)|join('') }}
{{ '1234'[1:2] }}
{{ arr|slice(1, 2)|join('') }}
{{ arr[1:2]|join('') }}
+
+{{ [1, 2, 3, 4]|slice(1)|join('') }}
+{{ [1, 2, 3, 4][1:]|join('') }}
--DATA--
return array('start' => 1, 'length' => 2, 'arr' => new ArrayObject(array(1, 2, 3, 4)))
--EXPECT--
23
23
23
+
+234
+234