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

Breadcrumb

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

function Scanner::__construct

Same name in this branch
  1. 11.1.x vendor/masterminds/html5/src/HTML5/Parser/Scanner.php \Masterminds\HTML5\Parser\Scanner::__construct()

Class constructor

Parameters

string $source Source code:

Features $features Scanner features:

array $options Parsing options:

File

vendor/mck89/peast/lib/Peast/Syntax/Scanner.php, line 320

Class

Scanner
Base class for scanners.

Namespace

Peast\Syntax

Code

function __construct($source, Features $features, $options) {
    $this->features = $features;
    $encoding = isset($options["sourceEncoding"]) ? $options["sourceEncoding"] : null;
    
    //Strip BOM characters from the source
    $this->stripBOM($source, $encoding);
    
    //Convert to UTF8 if needed
    if ($encoding && !preg_match("/UTF-?8/i", $encoding)) {
        $source = mb_convert_encoding($source, "UTF-8", $encoding);
    }
    
    //Instead of using mb_substr for each character, split the source
    
    //into an array of UTF8 characters for performance reasons
    $this->source = Utils::stringToUTF8Array($source, !isset($options["strictEncoding"]) || $options["strictEncoding"]);
    $this->length = count($this->source);
    
    //Convert character codes to UTF8 characters in whitespaces and line
    
    //terminators
    $this->lineTerminators = array_merge(self::$lineTerminatorsSequences, self::$lineTerminatorsChars);
    foreach (array(
        "whitespaces",
        "lineTerminators",
    ) as $key) {
        foreach ($this->{$key} as $i => $char) {
            if (is_int($char)) {
                $this->{$key}[$i] = Utils::unicodeToUtf8($char);
            }
        }
    }
    
    //Remove exponentiation operator if the feature
    
    //is not enabled
    if (!$this->features->exponentiationOperator) {
        Utils::removeArrayValue($this->punctuators, "**");
        Utils::removeArrayValue($this->punctuators, "**=");
    }
    if (!$this->features->optionalChaining) {
        Utils::removeArrayValue($this->punctuators, "?.");
    }
    
    //Remove logical assignment operators if the feature
    
    //is not enabled
    if (!$this->features->logicalAssignmentOperators) {
        Utils::removeArrayValue($this->punctuators, "&&=");
        Utils::removeArrayValue($this->punctuators, "||=");
        Utils::removeArrayValue($this->punctuators, "??=");
    }
    
    //Create a LSM for punctuators array
    $this->punctuatorsLSM = new LSM($this->punctuators);
    
    //Create a LSM for strings stops
    $this->stringsStopsLSM = new LSM($this->lineTerminators, true);
    
    //Allow paragraph and line separators in strings
    if ($this->features->paragraphLineSepInStrings) {
        $this->stringsStopsLSM
            ->remove(Utils::unicodeToUtf8(0x2028));
        $this->stringsStopsLSM
            ->remove(Utils::unicodeToUtf8(0x2029));
    }
    
    //Remove await as keyword if async/await is enabled
    if ($this->features->asyncAwait) {
        Utils::removeArrayValue($this->keywords, "await");
    }
    $this->linesSplitter = "/" . implode("|", $this->lineTerminators) . "/uS";
    $this->position = new Position(0, 0, 0);
}

API Navigation

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