default:
if ($token->test(Twig_Token::OPERATOR_TYPE, '[')) {
- $this->parser->getStream()->next();
$node = $this->parseArrayExpression();
- $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ']');
} elseif ($token->test(Twig_Token::OPERATOR_TYPE, '(')) {
$this->parser->getStream()->next();
$node = $this->parseExpression();
public function parseArrayExpression()
{
+ $stream = $this->parser->getStream();
+ $stream->expect(Twig_Token::OPERATOR_TYPE, '[');
$elements = array();
- while (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, ']')) {
+ while (!$stream->test(Twig_Token::OPERATOR_TYPE, ']')) {
if (!empty($elements)) {
- $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ',');
+ $stream->expect(Twig_Token::OPERATOR_TYPE, ',');
// trailing ,?
- if ($this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, ']')) {
+ if ($stream->test(Twig_Token::OPERATOR_TYPE, ']')) {
+ $stream->expect(Twig_Token::OPERATOR_TYPE, ']');
+
return new Twig_Node_Expression_Array($elements, $this->parser->getCurrentToken()->getLine());
}
}
// hash or array element?
if (
- $this->parser->getStream()->test(Twig_Token::STRING_TYPE)
+ $stream->test(Twig_Token::STRING_TYPE)
||
- $this->parser->getStream()->test(Twig_Token::NUMBER_TYPE)
+ $stream->test(Twig_Token::NUMBER_TYPE)
)
{
- if ($this->parser->getStream()->look()->test(Twig_Token::OPERATOR_TYPE, ':')) {
+ if ($stream->look()->test(Twig_Token::OPERATOR_TYPE, ':')) {
// hash
- $key = $this->parser->getStream()->next()->getValue();
- $this->parser->getStream()->next();
+ $key = $stream->next()->getValue();
+ $stream->next();
$elements[$key] = $this->parseExpression();
continue;
}
- $this->parser->getStream()->rewind();
+ $stream->rewind();
}
$elements[] = $this->parseExpression();
}
+ $stream->expect(Twig_Token::OPERATOR_TYPE, ']');
return new Twig_Node_Expression_Array($elements, $this->parser->getCurrentToken()->getLine());
}