fixed is operator (lexer did not tokenize 'foo.isactive' properly -- closes #102)

This commit is contained in:
Fabien Potencier
2010-08-17 07:49:57 +02:00
parent 7fc7180c29
commit 47c44e477c
2 changed files with 14 additions and 21 deletions
+13 -20
View File
@@ -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;
}
}
+1 -1
View File
@@ -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())
{