From: Fabien Potencier Date: Tue, 17 Aug 2010 05:49:57 +0000 (+0200) Subject: fixed is operator (lexer did not tokenize 'foo.isactive' properly -- closes #102) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=47c44e477c8b42df9f4c6b58c59d03d47c331bcd;p=konrad%2Ftwig.git fixed is operator (lexer did not tokenize 'foo.isactive' properly -- closes #102) --- diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 19e24a1..290c972 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -331,30 +331,23 @@ class Twig_ExpressionParser public function parsePostfixExpression($node) { - $stop = false; - while (!$stop && $this->parser->getCurrentToken()->getType() == Twig_Token::OPERATOR_TYPE) { - switch ($this->parser->getCurrentToken()->getValue()) { - case '..': + while (1) { + $token = $this->parser->getCurrentToken(); + if ($token->getType() == Twig_Token::OPERATOR_TYPE) { + if ('..' == $token->getValue()) { $node = $this->parseRangeExpression($node); - break; - - case '.': - case '[': + } elseif ('.' == $token->getValue() || '[' == $token->getValue()) { $node = $this->parseSubscriptExpression($node); - break; - - case '|': + } elseif ('|' == $token->getValue()) { $node = $this->parseFilterExpression($node); + } else { break; - - case 'is': - $stop = true; - $node = $this->parseTestExpression($node); - break; - - default: - $stop = true; - break; + } + } elseif ($token->getType() == Twig_Token::NAME_TYPE && 'is' == $token->getValue()) { + $node = $this->parseTestExpression($node); + break; + } else { + break; } } diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index be0c55c..f1c304b 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -36,7 +36,7 @@ class Twig_Lexer implements Twig_LexerInterface const REGEX_NAME = '/[A-Za-z_][A-Za-z0-9_]*/A'; const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A'; const REGEX_STRING = '/(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')/Asm'; - const REGEX_OPERATOR = '/<=? | >=? | [!=]= | = | \/\/ | \.\. | is | [(){}.,%*\/+~|-] | \[ | \] | \? | \:/Ax'; + const REGEX_OPERATOR = '/<=? | >=? | [!=]= | = | \/\/ | \.\. | [(){}.,%*\/+~|-] | \[ | \] | \? | \:/Ax'; public function __construct(Twig_Environment $env = null, array $options = array()) {