Permalink
Browse files

added support for implicit string literal concatenation

--HG--
branch : trunk
  • Loading branch information...
1 parent 63fd798 commit 4778bda8312875a943e3f16df3efc5f6ffb1e586 @mitsuhiko mitsuhiko committed Jun 22, 2008
Showing with 17 additions and 1 deletion.
  1. +3 −0 CHANGES
  2. +9 −1 jinja2/parser.py
  3. +5 −0 tests/test_syntax.py
View
@@ -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)
View
@@ -461,7 +461,15 @@ def parse_primary(self, with_postfix=True):
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':
View
@@ -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'

0 comments on commit 4778bda

Please sign in to comment.