33 $expr = $this->parser->getExpressionParser()->parseExpression();
34 $stream = $this->parser->getStream();
36 $body = $this->parser->subparse(array($this,
'decideIfFork'));
37 $tests = array($expr, $body);
42 switch (
$stream->next()->getValue()) {
45 $else = $this->parser->subparse(array($this,
'decideIfEnd'));
49 $expr = $this->parser->getExpressionParser()->parseExpression();
51 $body = $this->parser->subparse(array($this,
'decideIfFork'));
61 throw new Twig_Error_Syntax(sprintf(
'Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno),
$stream->getCurrent()->getLine(),
$stream->getSourceContext());
72 return $token->
test(array(
'elseif',
'else',
'endif'));
77 return $token->
test(array(
'endif'));
86 class_alias(
'Twig_TokenParser_If',
'Twig\TokenParser\IfTokenParser',
false);
Represents a node in the AST.
test($type, $values=null)
Tests the current token for a type and/or a value.
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
decideIfEnd(Twig_Token $token)
getTag()
Gets the tag name associated with this token parser.
Base class for all token parsers.
decideIfFork(Twig_Token $token)
parse(Twig_Token $token)
Parses a token and returns a node.