36 $stream = $this->parser->getStream();
37 $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
39 $seq = $this->parser->getExpressionParser()->parseExpression();
44 $ifexpr = $this->parser->getExpressionParser()->parseExpression();
48 $body = $this->parser->subparse(array($this,
'decideForFork'));
49 if ($stream->next()->getValue() ==
'else') {
51 $else = $this->parser->subparse(array($this,
'decideForEnd'),
true);
57 if (count($targets) > 1) {
58 $keyTarget = $targets->getNode(0);
60 $valueTarget = $targets->
getNode(1);
64 $valueTarget = $targets->getNode(0);
73 return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->
getTag());
78 return $token->
test(array(
'else',
'endfor'));
83 return $token->
test(
'endfor');
93 foreach ($node as $n) {
107 $attribute = $node->getNode(
'attribute');
108 if ($attribute instanceof
Twig_Node_Expression_Constant && in_array($attribute->getAttribute(
'value'), array(
'length',
'revindex0',
'revindex',
'last'))) {
109 throw new Twig_Error_Syntax(sprintf(
'The "loop.%s" variable is not defined when looping with a condition', $attribute->getAttribute(
'value')), $node->
getLine(), $stream->
getFilename());
118 foreach ($node as $n) {
Base class for all token parsers.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
decideForEnd(Twig_Token $token)
checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node)
getAttribute($name)
Gets an attribute.
parse(Twig_Token $token)
Parses a token and returns a node.
Represents a token stream.
getTag()
Gets the tag name associated with this token parser.
getFilename()
Gets the filename associated with this stream.
Loops over each item of a sequence.
Represents a node in the AST.
decideForFork(Twig_Token $token)
checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
test($type, $values=null)
Tests the current token for a type and/or a value.
getNode($name)
Gets a node by name.