added support for implicit string literal concatenation
authorArmin Ronacher <armin.ronacher@active-4.com>
Sun, 22 Jun 2008 10:48:37 +0000 (12:48 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sun, 22 Jun 2008 10:48:37 +0000 (12:48 +0200)
--HG--
branch : trunk

CHANGES
jinja2/parser.py
tests/test_syntax.py

diff --git a/CHANGES b/CHANGES
index 9d343818cf42dc28a37c1ed7095af60f6a16dbc0..1035a2ad6b4c7bbf52bbb12429932ddfe99e8e7c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,9 @@ Version 2.0
 
 - added :meth:`jinja2.environment.TemplateStream.dump`.
 
+- added support for implicit string literal concatenation.
+  ``{{ "foo" "bar" }}`` is equivalent to ``{{ "foobar" }}``
+
 Version 2.0rc1
 --------------
 (no codename, released on July 9th 2008)
index ea7391fe26967fbf37377cddaff23904dc309982..1e43ed8147821fdd95a638a6ad2ed5beb489c980 100644 (file)
@@ -461,7 +461,15 @@ class Parser(object):
             else:
                 node = nodes.Name(token.value, 'load', lineno=token.lineno)
             self.stream.next()
-        elif token.type in ('integer', 'float', 'string'):
+        elif token.type is 'string':
+            self.stream.next()
+            buf = [token.value]
+            lineno = token.lineno
+            while self.stream.current.type is 'string':
+                buf.append(self.stream.current.value)
+                self.stream.next()
+            node = nodes.Const(''.join(buf), lineno=lineno)
+        elif token.type in ('integer', 'float'):
             self.stream.next()
             node = nodes.Const(token.value, lineno=token.lineno)
         elif token.type is 'lparen':
index 986125c51d4105642035d67362a27c8ab109e6b8..4d28dbc7f197aae408a3e94d9305d6facc41c77a 100644 (file)
@@ -176,3 +176,8 @@ def test_contant_casing(env):
 def test_test_chaining(env):
     raises(TemplateSyntaxError, env.from_string, '{{ foo is string is sequence }}')
     env.from_string('{{ 42 is string or 42 is number }}').render() == 'True'
+
+
+def test_string_concatenation(env):
+    tmpl = env.from_string('{{ "foo" "bar" "baz" }}')
+    assert tmpl.render() == 'foobarbaz'