Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Parser.php

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\Syntax

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal