fixed is operator (lexer did not tokenize 'foo.isactive' properly -- closes #102)
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 17 Aug 2010 05:49:57 +0000 (07:49 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 17 Aug 2010 05:50:52 +0000 (07:50 +0200)
lib/Twig/ExpressionParser.php
lib/Twig/Lexer.php

index 19e24a1..290c972 100644 (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;
             }
         }
 
index be0c55c..f1c304b 100644 (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())
     {