From 4778bda8312875a943e3f16df3efc5f6ffb1e586 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 22 Jun 2008 12:48:37 +0200 Subject: [PATCH] added support for implicit string literal concatenation --HG-- branch : trunk --- CHANGES | 3 +++ jinja2/parser.py | 10 +++++++++- tests/test_syntax.py | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 9d34381..1035a2a 100644 --- 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) diff --git a/jinja2/parser.py b/jinja2/parser.py index ea7391f..1e43ed8 100644 --- a/jinja2/parser.py +++ b/jinja2/parser.py @@ -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': diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 986125c..4d28dbc 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -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' -- 2.26.2