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

Breadcrumb

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

function Scanner::scanPunctuator

Punctuator scanning method

Return value

Token|null

1 call to Scanner::scanPunctuator()
Scanner::getToken in vendor/mck89/peast/lib/Peast/Syntax/Scanner.php
Returns the current token

File

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

Class

Scanner
Base class for scanners.

Namespace

Peast\Syntax

Code

protected function scanPunctuator() {
    $token = null;
    $char = $this->charAt();
    
    //Check if the next char is a bracket
    if (isset($this->brackets[$char])) {
        
        //Check if it is a closing bracket
        if ($this->brackets[$char]) {
            $openBracket = $this->brackets[$char];
            
            //Check if there is a corresponding open bracket
            if (!isset($this->openBrackets[$openBracket]) || !$this->openBrackets[$openBracket]) {
                if (!$this->isAfterSlash($this->getPosition(true))) {
                    $this->error();
                }
            }
            else {
                $this->openBrackets[$openBracket]--;
            }
        }
        else {
            if (!isset($this->openBrackets[$char])) {
                $this->openBrackets[$char] = 0;
            }
            $this->openBrackets[$char]++;
        }
        $this->index++;
        $this->column++;
        $token = new Token(Token::TYPE_PUNCTUATOR, $char);
    }
    elseif ($match = $this->punctuatorsLSM
        ->match($this, $this->index, $char)) {
        
        //Optional chaining punctuator cannot appear before a number, in this
        
        //case only the question mark must be consumed
        if ($match[1] === "?." && ($nextChar = $this->charAt($this->index + $match[0])) !== null && $nextChar >= "0" && $nextChar <= "9") {
            $match = array(
                1,
                "?",
            );
        }
        $this->index += $match[0];
        $this->column += $match[0];
        $token = new Token(Token::TYPE_PUNCTUATOR, $match[1]);
    }
    return $token;
}

API Navigation

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