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

Breadcrumb

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

function Emulative::tokenize

Overrides Lexer::tokenize

File

vendor/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php, line 64

Class

Emulative

Namespace

PhpParser\Lexer

Code

public function tokenize(string $code, ?ErrorHandler $errorHandler = null) : array {
    $emulators = array_filter($this->emulators, function ($emulator) use ($code) {
        return $emulator->isEmulationNeeded($code);
    });
    if (empty($emulators)) {
        // Nothing to emulate, yay
        return parent::tokenize($code, $errorHandler);
    }
    if ($errorHandler === null) {
        $errorHandler = new ErrorHandler\Throwing();
    }
    $this->patches = [];
    foreach ($emulators as $emulator) {
        $code = $emulator->preprocessCode($code, $this->patches);
    }
    $collector = new ErrorHandler\Collecting();
    $tokens = parent::tokenize($code, $collector);
    $this->sortPatches();
    $tokens = $this->fixupTokens($tokens);
    $errors = $collector->getErrors();
    if (!empty($errors)) {
        $this->fixupErrors($errors);
        foreach ($errors as $error) {
            $errorHandler->handleError($error);
        }
    }
    foreach ($emulators as $emulator) {
        $tokens = $emulator->emulate($code, $tokens);
    }
    return $tokens;
}

API Navigation

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