From: Fabien Potencier Date: Tue, 8 Jun 2010 09:38:36 +0000 (+0200) Subject: made parseArguments autonomous X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=68b966516cb8ac3b0b2ca1eac6f54a3899ffff17;p=konrad%2Ftwig.git made parseArguments autonomous --- diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index b9d6723..3c85cdc 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -381,9 +381,10 @@ class Twig_ExpressionParser if ($this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '(')) { $type = Twig_Node_Expression_GetAttr::TYPE_METHOD; + $arguments = $this->parseArguments(); + } else { + $arguments = new Twig_Node(); } - - $arguments = $this->parseArguments(); } else { throw new Twig_SyntaxError('Expected name or number', $lineno); } @@ -413,7 +414,11 @@ class Twig_ExpressionParser $token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE); $filters[] = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine()); - $filters[] = $this->parseArguments(); + if (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '(')) { + $filters[] = new Twig_Node(); + } else { + $filters[] = $this->parseArguments(); + } if (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '|')) { break; @@ -427,19 +432,17 @@ class Twig_ExpressionParser public function parseArguments() { - if (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '(')) { - return new Twig_Node(); - } + $parser = $this->parser->getStream(); + $parser->expect(Twig_Token::OPERATOR_TYPE, '('); $args = array(); - $this->parser->getStream()->next(); - while (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, ')')) { + while (!$parser->test(Twig_Token::OPERATOR_TYPE, ')')) { if (!empty($args)) { - $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ','); + $parser->expect(Twig_Token::OPERATOR_TYPE, ','); } $args[] = $this->parseExpression(); } - $this->parser->getStream()->expect(Twig_Token::OPERATOR_TYPE, ')'); + $parser->expect(Twig_Token::OPERATOR_TYPE, ')'); return new Twig_Node($args); }