phpbb/phpBB/includes/template/twig/lexer.php
Nathan Guse b775f67128 [feature/twig] More work on the lexer
Committing what I have now to save it as I'm trying another method next

PHPBB3-11598
2013-06-10 10:00:22 -05:00

78 lines
2 KiB
PHP

<?php
/**
*
* @package phpBB3
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class phpbb_template_twig_lexer extends Twig_Lexer
{
protected function lexExpression()
{
var_dump(substr($this->code, $this->cursor, 40), $this->states);
parent::lexExpression();
// Last element parsed
$last_element = end($this->tokens);
/**
* Check for old fashioned INCLUDE statements without enclosed quotes
*/
if ($last_element->getValue() === 'INCLUDE')
{
if (preg_match('#^\s*([a-zA-Z0-9_]+\.[a-zA-Z0-9]+)#', substr($this->code, $this->cursor), $match))
{
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
$this->moveCursor($match[0]);
}
}
/**
* This is some compatibility code to continue supporting expressions such as:
* <!-- IF .blah -->
*/
if ($last_element->getValue() === 'IF')
{
if (preg_match('#^\s*(not\s)?\.([a-zA-Z0-9_\.]+)#', substr($this->code, $this->cursor), $match))
{
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
$this->moveCursor($match[0]);
}
}
/**
* This is some compatibility code to continue supporting expressions such as:
* <!-- DEFINE $VAR = 'foo' -->
*/
if ($last_element->getValue() === 'DEFINE')
{
if (preg_match('#^\s*\$([A-Z0-9]+)#', substr($this->code, $this->cursor), $match))
{
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
$this->moveCursor($match[1]);
}
}
/**
* Check for old fashioned INCLUDE statements without enclosed quotes
*/
if ($last_element->getValue() === 'INCLUDE')
{
if (preg_match('#^\s*([a-zA-Z0-9_]+\.[a-zA-Z0-9]+)#', substr($this->code, $this->cursor), $match))
{
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
$this->moveCursor($match[0]);
}
}
}
}