protected function parseIf($token)
{
$line = $token->getLine();
$expr = $this->parseExpression();
$this->stream->expect(Token::BLOCK_END);
$body = $this->subparse(array('elseif', 'else', 'endif'));
$tests = array(array($expr, $body));
$else = null;
$end = false;
while (!$end) {
switch ($this->stream->next()->getValue()) {
case 'elseif':
$expr = $this->parseExpression();
$this->stream->expect(Token::BLOCK_END);
$body = $this->subparse(array('elseif', 'else', 'endif'));
$tests[] = array($expr, $body);
break;
case 'else':
$this->stream->expect(Token::BLOCK_END);
$else = $this->subparse(array('endif'));
break;
case 'endif':
$this->stream->expect(Token::BLOCK_END);
$end = true;
break;
default:
throw new SyntaxError('malformed if statement', $token);
break;
}
}
return new Node\IfNode($tests, $else, $line);
}