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

Breadcrumb

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

function Parser::parseFunctionOrGeneratorDeclaration

Parses function or generator declaration

Parameters

bool $default Default mode:

bool $allowGenerator True to allow parsing of generators:

Return value

Node\FunctionDeclaration|null

3 calls to Parser::parseFunctionOrGeneratorDeclaration()
Parser::parseDeclaration in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses a declaration
Parser::parseIfStatement in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses an if statement
Parser::parseLabelledStatement in vendor/mck89/peast/lib/Peast/Syntax/Parser.php
Parses a labelled statement

File

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

Class

Parser
Parser class

Namespace

Peast\Syntax

Code

protected function parseFunctionOrGeneratorDeclaration($default = false, $allowGenerator = true) {
    $async = null;
    if ($this->features->asyncAwait && ($async = $this->checkAsyncFunctionStart())) {
        $this->scanner
            ->consumeToken();
        if (!$this->features->asyncIterationGenerators) {
            $allowGenerator = false;
        }
    }
    if ($token = $this->scanner
        ->consume("function")) {
        $generator = $allowGenerator && $this->scanner
            ->consume("*");
        $id = $this->parseIdentifier(static::$bindingIdentifier);
        if ($generator || $async) {
            $flags = array(
                null,
            );
            if ($generator) {
                $flags["allowYield"] = true;
            }
            if ($async) {
                $flags["allowAwait"] = true;
            }
        }
        else {
            $flags = null;
        }
        if (($default || $id) && $this->scanner
            ->consume("(") && ($params = $this->isolateContext($flags, "parseFormalParameterList")) !== null && $this->scanner
            ->consume(")") && ($tokenBodyStart = $this->scanner
            ->consume("{")) && (($body = $this->isolateContext($flags, "parseFunctionBody")) || true) && $this->scanner
            ->consume("}")) {
            $body->location->start = $tokenBodyStart->location->start;
            $body->location->end = $this->scanner
                ->getPosition();
            $node = $this->createNode("FunctionDeclaration", $async ?: $token);
            if ($id) {
                $node->setId($id);
            }
            $node->setParams($params);
            $node->setBody($body);
            $node->setGenerator($generator);
            $node->setAsync((bool) $async);
            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