public function Twig_ExpressionParser::parseArrayExpression in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/twig/twig/lib/Twig/ExpressionParser.php \Twig_ExpressionParser::parseArrayExpression()
1 call to Twig_ExpressionParser::parseArrayExpression()
- Twig_ExpressionParser::parsePrimaryExpression in vendor/
twig/ twig/ lib/ Twig/ ExpressionParser.php
File
- vendor/
twig/ twig/ lib/ Twig/ ExpressionParser.php, line 225
Class
- Twig_ExpressionParser
- Parses expressions.
Code
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;
}