private function lexData() { $match = NULL; // if no matches are left we return the rest of the template // as simple text token if (!preg_match('/(.*?)(\\{[%#]|\\$(?!\\$))/A', $this->code, $match, NULL, $this->cursor)) { $rv = Twig_Token::Text(substr($this->code, $this->cursor), $this->lineno); $this->cursor = $this->end; return $rv; } $this->cursor += strlen($match[0]); // update the lineno on the instance $lineno = $this->lineno; $this->lineno += substr_count($match[0], '\\n'); // push the template text first $text = $match[1]; if (!empty($text)) { $result = array(Twig_Token::Text($text, $lineno)); $lineno += substr_count($text, '\\n'); } else { $result = array(); } // block start token, let's return a token for that. if (($token = $match[2]) !== '$') { // if our section is a comment, just return the text if ($token[1] == '#') { if (!preg_match('/.*?#\\}/A', $this->code, $match, NULL, $this->cursor)) { throw new Twig_SyntaxError('unclosed comment', $this->lineno); } $this->cursor += strlen($match[0]); $this->lineno += substr_count($match[0], '\\n'); return $result; } $result[] = new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $lineno); $this->position = self::POSITION_BLOCK; } else { if (isset($this->code[$this->cursor]) && $this->code[$this->cursor] == '{') { $this->cursor++; $result[] = new Twig_Token(Twig_Token::VAR_START_TYPE, '', $lineno); $this->position = self::POSITION_VAR; } else { if (preg_match(self::REGEX_NAME, $this->code, $match, NULL, $this->cursor)) { $result[] = new Twig_Token(Twig_Token::VAR_START_TYPE, '', $lineno); $result[] = Twig_Token::Name($match[0], $lineno); $this->cursor += strlen($match[0]); // allow attribute lookup while (isset($this->code[$this->cursor]) && $this->code[$this->cursor] === '.') { ++$this->cursor; $result[] = Twig_Token::Operator('.', $this->lineno); if (preg_match(self::REGEX_NAME, $this->code, $match, NULL, $this->cursor)) { $this->cursor += strlen($match[0]); $result[] = Twig_Token::Name($match[0], $this->lineno); } else { if (preg_match(self::REGEX_NUMBER, $this->code, $match, NULL, $this->cursor)) { $this->cursor += strlen($match[0]); $result[] = Twig_Token::Number($match[0], $this->lineno); } else { --$this->cursor; break; } } } $result[] = new Twig_Token(Twig_Token::VAR_END_TYPE, '', $lineno); } } } return $result; }