return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]);
}
- public function parsePrimaryExpression($assignment = false)
+ public function parsePrimaryExpression()
{
$token = $this->parser->getCurrentToken();
switch ($token->getType()) {
break;
default:
- $cls = $assignment ? 'Twig_Node_Expression_AssignName' : 'Twig_Node_Expression_Name';
- $node = new $cls($token->getValue(), $token->getLine());
+ $node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine());
}
break;
}
}
- if (!$assignment) {
- $node = $this->parsePostfixExpression($node);
- }
-
- return $node;
+ return $this->parsePostfixExpression($node);
}
public function parseArrayExpression()
public function parseAssignmentExpression()
{
- $lineno = $this->parser->getCurrentToken()->getLine();
$targets = array();
while (true) {
- if (!empty($targets)) {
- $this->parser->getStream()->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'Multiple assignments must be separated by a comma (,)');
- }
if ($this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, ')') ||
$this->parser->getStream()->test(Twig_Token::VAR_END_TYPE) ||
$this->parser->getStream()->test(Twig_Token::BLOCK_END_TYPE))
{
break;
}
- $targets[] = $this->parsePrimaryExpression(true);
+
+ $token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to');
+ if (in_array($token->getValue(), array('true', 'false', 'none'))) {
+ throw new Twig_Error_Syntax($token->getValue() . ' cannot be assigned to');
+ }
+ $targets[] = new Twig_Node_Expression_AssignName($token->getValue(), $token->getLine());
+
if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, ',')) {
break;
}
+ $this->parser->getStream()->next();
}
return new Twig_Node($targets);