31 $stream = $this->parser->getStream();
32 $targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
34 $seq = $this->parser->getExpressionParser()->parseExpression();
38 $ifexpr = $this->parser->getExpressionParser()->parseExpression();
42 $body = $this->parser->subparse(array($this,
'decideForFork'));
43 if (
'else' ==
$stream->next()->getValue()) {
45 $else = $this->parser->subparse(array($this,
'decideForEnd'),
true);
51 if (count($targets) > 1) {
52 $keyTarget = $targets->getNode(0);
54 $valueTarget = $targets->
getNode(1);
58 $valueTarget = $targets->getNode(0);
67 return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->
getTag());
72 return $token->
test(array(
'else',
'endfor'));
77 return $token->
test(
'endfor');
87 foreach ($node as
$n) {
101 $attribute = $node->getNode(
'attribute');
102 if ($attribute instanceof
Twig_Node_Expression_Constant && in_array($attribute->getAttribute(
'value'), array(
'length',
'revindex0',
'revindex',
'last'))) {
103 throw new Twig_Error_Syntax(sprintf(
'The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute(
'value')), $node->getTemplateLine(), $stream->
getSourceContext());
112 foreach ($node as
$n) {
127 class_alias(
'Twig_TokenParser_For',
'Twig\TokenParser\ForTokenParser',
false);
Represents a node in the AST.
getSourceContext()
Gets the source associated with this stream.
test($type, $values=null)
Tests the current token for a type and/or a value.
Represents a token stream.
checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node)
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Base class for all token parsers.
checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
decideForFork(Twig_Token $token)
Loops over each item of a sequence.
parse(Twig_Token $token)
Parses a token and returns a node.
getTag()
Gets the tag name associated with this token parser.
decideForEnd(Twig_Token $token)