public function parseArrayExpression() {
$stream = $this->parser
->getStream();
$stream
->expect(Twig_Token::PUNCTUATION_TYPE, '[', 'An array element was expected');
$node = new Twig_Node_Expression_Array(array(), $stream
->getCurrent()
->getLine());
$first = true;
while (!$stream
->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
if (!$first) {
$stream
->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma');
// trailing ,?
if ($stream
->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
break;
}
}
$first = false;
$node
->addElement($this
->parseExpression());
}
$stream
->expect(Twig_Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed');
return $node;
}