function Parser::parseIfStatement
Parses an if statement
Return value
Node\IfStatement|null
1 call to Parser::parseIfStatement()
- Parser::parseStatement in vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php - Parses a statement
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ Parser.php, line 531
Class
- Parser
- Parser class
Namespace
Peast\SyntaxCode
protected function parseIfStatement() {
if ($token = $this->scanner
->consume("if")) {
if ($this->scanner
->consume("(") && ($test = $this->isolateContext(array(
"allowIn" => true,
), "parseExpression")) && $this->scanner
->consume(")") && (($consequent = $this->parseStatement()) || !$this->scanner
->getStrictMode() && ($consequent = $this->parseFunctionOrGeneratorDeclaration(false, false)))) {
$node = $this->createNode("IfStatement", $token);
$node->setTest($test);
$node->setConsequent($consequent);
if ($this->scanner
->consume("else")) {
if (($alternate = $this->parseStatement()) || !$this->scanner
->getStrictMode() && ($alternate = $this->parseFunctionOrGeneratorDeclaration(false, false))) {
$node->setAlternate($alternate);
return $this->completeNode($node);
}
}
else {
return $this->completeNode($node);
}
}
$this->error();
}
return null;
}