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

Breadcrumb

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

function Parser::parseForLetConstStatement

Parses a for(let ...) or for(const ...) statement

Parameters

Token $forToken Token that corresponds to the "for" keyword:

Return value

Node\Node|null

1 call to Parser::parseForLetConstStatement()
Parser::parseIterationStatement in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses do-while, while, for, for-in and for-of statements

File

vendor/mck89/peast/lib/Peast/Syntax/Parser.php, line 1187

Class

Parser
Parser class

Namespace

Peast\Syntax

Code

protected function parseForLetConstStatement($forToken) {
    $afterBracketState = $this->scanner
        ->getState();
    if (!($init = $this->parseForDeclaration())) {
        return null;
    }
    if ($this->scanner
        ->consume("in")) {
        if (($right = $this->isolateContext(array(
            "allowIn" => true,
        ), "parseExpression")) && $this->scanner
            ->consume(")") && ($body = $this->parseStatement())) {
            $node = $this->createNode("ForInStatement", $forToken);
            $node->setLeft($init);
            $node->setRight($right);
            $node->setBody($body);
            return $this->completeNode($node);
        }
    }
    elseif ($this->scanner
        ->consume("of")) {
        if (($right = $this->isolateContext(array(
            "allowIn" => true,
        ), "parseAssignmentExpression")) && $this->scanner
            ->consume(")") && ($body = $this->parseStatement())) {
            $node = $this->createNode("ForOfStatement", $forToken);
            $node->setLeft($init);
            $node->setRight($right);
            $node->setBody($body);
            return $this->completeNode($node);
        }
    }
    else {
        $this->scanner
            ->setState($afterBracketState);
        if ($init = $this->isolateContext(array(
            "allowIn" => false,
        ), "parseLexicalDeclaration")) {
            $test = $this->isolateContext(array(
                "allowIn" => true,
            ), "parseExpression");
            if ($this->scanner
                ->consume(";")) {
                $update = $this->isolateContext(array(
                    "allowIn" => true,
                ), "parseExpression");
                if ($this->scanner
                    ->consume(")") && ($body = $this->parseStatement())) {
                    $node = $this->createNode("ForStatement", $forToken);
                    $node->setInit($init);
                    $node->setTest($test);
                    $node->setUpdate($update);
                    $node->setBody($body);
                    return $this->completeNode($node);
                }
            }
        }
    }
    $this->error();
}

API Navigation

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