fixed SimpleTokenParser accepts comma(",") in grammar
authorfivestar <ko.fivestar@gmail.com>
Tue, 31 Aug 2010 02:32:37 +0000 (11:32 +0900)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 31 Aug 2010 05:40:36 +0000 (07:40 +0200)
lib/Twig/SimpleTokenParser.php
test/Twig/Tests/SimpleTokenParserTest.php

index d95f2b1..4962484 100644 (file)
@@ -108,7 +108,7 @@ abstract class Twig_SimpleTokenParser extends Twig_TokenParser
                 }
                 $grammar->addGrammar(new $class($match[1]));
                 $cursor += strlen($match[0]);
-            } elseif (preg_match('/(\w+)/A', $str, $match, null, $cursor)) {
+            } elseif (preg_match('/(\w+|,)/A', $str, $match, null, $cursor)) {
                 $grammar->addGrammar(new Twig_Grammar_Constant($match[1]));
                 $cursor += strlen($match[0]);
             } elseif (preg_match('/\[/A', $str, $match, null, $cursor)) {
index b15638f..8ccb4c7 100644 (file)
@@ -96,6 +96,17 @@ class Twig_Tests_SimpleTokenParserTest extends PHPUnit_Framework_TestCase
                     )
                 )
             )),
+            array('<expr:expression> [with <arguments:array> [, <optional:expression>]]', new Twig_Grammar_Tag(
+                new Twig_Grammar_Expression('expr'),
+                new Twig_Grammar_Optional(
+                    new Twig_Grammar_Constant('with'),
+                    new Twig_Grammar_Array('arguments'),
+                    new Twig_Grammar_Optional(
+                        new Twig_Grammar_Constant(','),
+                        new Twig_Grammar_Expression('optional')
+                    )
+                )
+            )),
         );
     }
 }