protected function Twig_Lexer::lexString

1 call to Twig_Lexer::lexString()
Twig_Lexer::tokenize in drupal/core/vendor/twig/twig/lib/Twig/Lexer.php
Tokenizes a source code.

File

drupal/core/vendor/twig/twig/lib/Twig/Lexer.php, line 314

Class

Twig_Lexer
Lexes a template string.

Code

protected function lexString() {
  if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) {
    $this->brackets[] = array(
      $this->options['interpolation'][0],
      $this->lineno,
    );
    $this
      ->pushToken(Twig_Token::INTERPOLATION_START_TYPE);
    $this
      ->moveCursor($match[0]);
    $this
      ->pushState(self::STATE_INTERPOLATION);
  }
  elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && strlen($match[0]) > 0) {
    $this
      ->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[0]));
    $this
      ->moveCursor($match[0]);
  }
  elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
    list($expect, $lineno) = array_pop($this->brackets);
    if ($this->code[$this->cursor] != '"') {
      throw new Twig_Error_Syntax(sprintf('Unclosed "%s"', $expect), $lineno, $this->filename);
    }
    $this
      ->popState();
    ++$this->cursor;
  }
}