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

Breadcrumb

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

function Scanner::scanTemplate

Template scanning method

Return value

Token|null

1 call to Scanner::scanTemplate()
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 1369

Class

Scanner
Base class for scanners.

Namespace

Peast\Syntax

Code

protected function scanTemplate() {
    $char = $this->charAt();
    
    //Get the current number of open curly brackets
    $openCurly = isset($this->openBrackets["{"]) ? $this->openBrackets["{"] : 0;
    
    //If the character is a curly bracket check and the number of open
    
    //curly brackets matches the last number in the open templates stack,
    
    //then the bracket closes the open template expression
    $endExpression = false;
    if ($char === "}") {
        $len = count($this->openTemplates);
        if ($len && $this->openTemplates[$len - 1] === $openCurly) {
            $endExpression = true;
            array_pop($this->openTemplates);
        }
    }
    if ($char === "`" || $endExpression) {
        $this->index++;
        $this->column++;
        $buffer = $char;
        while (true) {
            $tempBuffer = $this->consumeUntil(array(
                "`",
                "\$",
            ));
            if (!$tempBuffer) {
                $this->error("Unterminated template");
            }
            $buffer .= $tempBuffer[0];
            if ($tempBuffer[1] !== "\$" || $this->charAt() === "{") {
                
                //If "${" is found it's a new template expression, register
                
                //the current number of open curly brackets in the open
                
                //templates stack
                if ($tempBuffer[1] === "\$") {
                    $this->index++;
                    $this->column++;
                    $buffer .= "{";
                    $this->openTemplates[] = $openCurly;
                }
                break;
            }
        }
        return new Token(Token::TYPE_TEMPLATE, $buffer);
    }
    return null;
}

API Navigation

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