mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[feature/twig] More work on the lexer
Committing what I have now to save it as I'm trying another method next PHPBB3-11598
This commit is contained in:
parent
9f8f500ba3
commit
b775f67128
3 changed files with 41 additions and 2 deletions
|
@ -39,6 +39,7 @@ class phpbb_template_twig_extension extends Twig_Extension
|
||||||
array(),
|
array(),
|
||||||
array(
|
array(
|
||||||
'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
|
//'and' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
'!==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
'!==' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,11 +19,12 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||||
{
|
{
|
||||||
protected function lexExpression()
|
protected function lexExpression()
|
||||||
{
|
{
|
||||||
|
var_dump(substr($this->code, $this->cursor, 40), $this->states);
|
||||||
parent::lexExpression();
|
parent::lexExpression();
|
||||||
|
|
||||||
// Last element parsed
|
// Last element parsed
|
||||||
$last_element = end($this->tokens);
|
$last_element = end($this->tokens);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for old fashioned INCLUDE statements without enclosed quotes
|
* Check for old fashioned INCLUDE statements without enclosed quotes
|
||||||
*/
|
*/
|
||||||
|
@ -42,7 +43,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||||
*/
|
*/
|
||||||
if ($last_element->getValue() === 'IF')
|
if ($last_element->getValue() === 'IF')
|
||||||
{
|
{
|
||||||
if (preg_match('#^\s*\.([a-zA-Z0-9_\.]+)#', substr($this->code, $this->cursor), $match))
|
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->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[1]));
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
|
@ -61,5 +62,17 @@ class phpbb_template_twig_lexer extends Twig_Lexer
|
||||||
$this->moveCursor($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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,31 @@
|
||||||
*/
|
*/
|
||||||
class phpbb_template_twig_tokenparser_event extends Twig_TokenParser_Include
|
class phpbb_template_twig_tokenparser_event extends Twig_TokenParser_Include
|
||||||
{
|
{
|
||||||
|
protected function parseArguments()
|
||||||
|
{
|
||||||
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
|
$ignoreMissing = true;
|
||||||
|
|
||||||
|
$variables = null;
|
||||||
|
if ($stream->test(Twig_Token::NAME_TYPE, 'with')) {
|
||||||
|
$stream->next();
|
||||||
|
|
||||||
|
$variables = $this->parser->getExpressionParser()->parseExpression();
|
||||||
|
}
|
||||||
|
|
||||||
|
$only = false;
|
||||||
|
if ($stream->test(Twig_Token::NAME_TYPE, 'only')) {
|
||||||
|
$stream->next();
|
||||||
|
|
||||||
|
$only = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||||
|
|
||||||
|
return array($variables, $only, $ignoreMissing);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the tag name associated with this token parser.
|
* Gets the tag name associated with this token parser.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue