You are here

protected function Twig_Lexer::lexData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Lexer.php \Twig_Lexer::lexData()
1 call to Twig_Lexer::lexData()
Twig_Lexer::tokenize in vendor/twig/twig/lib/Twig/Lexer.php
Tokenizes a source code.

File

vendor/twig/twig/lib/Twig/Lexer.php, line 142

Class

Twig_Lexer
Lexes a template string.

Code

protected function lexData() {

  // if no matches are left we return the rest of the template as simple text token
  if ($this->position == count($this->positions[0]) - 1) {
    $this
      ->pushToken(Twig_Token::TEXT_TYPE, substr($this->code, $this->cursor));
    $this->cursor = $this->end;
    return;
  }

  // Find the first token after the current cursor
  $position = $this->positions[0][++$this->position];
  while ($position[1] < $this->cursor) {
    if ($this->position == count($this->positions[0]) - 1) {
      return;
    }
    $position = $this->positions[0][++$this->position];
  }

  // push the template text first
  $text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor);
  if (isset($this->positions[2][$this->position][0])) {
    $text = rtrim($text);
  }
  $this
    ->pushToken(Twig_Token::TEXT_TYPE, $text);
  $this
    ->moveCursor($textContent . $position[0]);
  switch ($this->positions[1][$this->position][0]) {
    case $this->options['tag_comment'][0]:
      $this
        ->lexComment();
      break;
    case $this->options['tag_block'][0]:

      // raw data?
      if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) {
        $this
          ->moveCursor($match[0]);
        $this
          ->lexRawData($match[1]);

        // {% line \d+ %}
      }
      elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) {
        $this
          ->moveCursor($match[0]);
        $this->lineno = (int) $match[1];
      }
      else {
        $this
          ->pushToken(Twig_Token::BLOCK_START_TYPE);
        $this
          ->pushState(self::STATE_BLOCK);
        $this->currentVarBlockLine = $this->lineno;
      }
      break;
    case $this->options['tag_variable'][0]:
      $this
        ->pushToken(Twig_Token::VAR_START_TYPE);
      $this
        ->pushState(self::STATE_VAR);
      $this->currentVarBlockLine = $this->lineno;
      break;
  }
}