in src/Parser.php [497:625]
private function parseStatementFn() {
return function ($parentNode) {
$token = $this->getCurrentToken();
switch ($token->kind) {
// compound-statement
case TokenKind::OpenBraceToken:
return $this->parseCompoundStatement($parentNode);
// labeled-statement
case TokenKind::Name:
if ($this->lookahead(TokenKind::ColonToken)) {
return $this->parseNamedLabelStatement($parentNode);
}
break;
// selection-statement
case TokenKind::IfKeyword:
return $this->parseIfStatement($parentNode);
case TokenKind::SwitchKeyword:
return $this->parseSwitchStatement($parentNode);
// iteration-statement
case TokenKind::WhileKeyword: // while-statement
return $this->parseWhileStatement($parentNode);
case TokenKind::DoKeyword: // do-statement
return $this->parseDoStatement($parentNode);
case TokenKind::ForKeyword: // for-statement
return $this->parseForStatement($parentNode);
case TokenKind::ForeachKeyword: // foreach-statement
return $this->parseForeachStatement($parentNode);
// jump-statement
case TokenKind::GotoKeyword: // goto-statement
return $this->parseGotoStatement($parentNode);
case TokenKind::ContinueKeyword: // continue-statement
case TokenKind::BreakKeyword: // break-statement
return $this->parseBreakOrContinueStatement($parentNode);
case TokenKind::ReturnKeyword: // return-statement
return $this->parseReturnStatement($parentNode);
// try-statement
case TokenKind::TryKeyword:
return $this->parseTryStatement($parentNode);
// declare-statement
case TokenKind::DeclareKeyword:
return $this->parseDeclareStatement($parentNode);
// attribute before statement or anonymous function
case TokenKind::AttributeToken:
return $this->parseAttributeStatement($parentNode);
// function-declaration
case TokenKind::FunctionKeyword:
// Check that this is not an anonymous-function-creation-expression
if ($this->lookahead($this->nameOrKeywordOrReservedWordTokens) || $this->lookahead(TokenKind::AmpersandToken, $this->nameOrKeywordOrReservedWordTokens)) {
return $this->parseFunctionDeclaration($parentNode);
}
break;
// class-declaration
case TokenKind::FinalKeyword:
case TokenKind::AbstractKeyword:
if (!$this->lookahead(TokenKind::ClassKeyword)) {
$this->advanceToken();
return new SkippedToken($token);
}
case TokenKind::ClassKeyword:
return $this->parseClassDeclaration($parentNode);
// interface-declaration
case TokenKind::InterfaceKeyword:
return $this->parseInterfaceDeclaration($parentNode);
// namespace-definition
case TokenKind::NamespaceKeyword:
if (!$this->lookahead(TokenKind::BackslashToken)) {
// TODO add error handling for the case where a namespace definition does not occur in the outer-most scope
return $this->parseNamespaceDefinition($parentNode);
}
break;
// namespace-use-declaration
case TokenKind::UseKeyword:
return $this->parseNamespaceUseDeclaration($parentNode);
case TokenKind::SemicolonToken:
return $this->parseEmptyStatement($parentNode);
case TokenKind::EchoKeyword:
return $this->parseEchoStatement($parentNode);
// trait-declaration
case TokenKind::TraitKeyword:
return $this->parseTraitDeclaration($parentNode);
case TokenKind::EnumKeyword:
return $this->parseEnumDeclaration($parentNode);
// global-declaration
case TokenKind::GlobalKeyword:
return $this->parseGlobalDeclaration($parentNode);
// const-declaration
case TokenKind::ConstKeyword:
return $this->parseConstDeclaration($parentNode);
// function-static-declaration
case TokenKind::StaticKeyword:
// Check that this is not an anonymous-function-creation-expression
if (!$this->lookahead([TokenKind::FunctionKeyword, TokenKind::FnKeyword, TokenKind::OpenParenToken, TokenKind::ColonColonToken])) {
return $this->parseFunctionStaticDeclaration($parentNode);
}
break;
case TokenKind::ScriptSectionEndTag:
return $this->parseInlineHtml($parentNode);
case TokenKind::UnsetKeyword:
return $this->parseUnsetStatement($parentNode);
}
$expressionStatement = new ExpressionStatement();
$expressionStatement->parent = $parentNode;
$expressionStatement->expression = $this->parseExpression($expressionStatement, true);
$expressionStatement->semicolon = $this->eatSemicolonOrAbortStatement();
return $expressionStatement;
};
}