summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2014-10-06 19:56:15 -0700
committerTim Hatch <tim@timhatch.com>2014-10-06 19:56:15 -0700
commit594d4043564cd44bc652b1b484ef6ceb5afdd36a (patch)
treea956823d258ea2118ac6a69179a7e870b2516ec6
parentdb54045f07300a47e4a603687fdcef89f29a2b12 (diff)
downloadpygments-594d4043564cd44bc652b1b484ef6ceb5afdd36a.tar.gz
SmartyLexer: Support nested curly braces.
Fixes #1039
-rw-r--r--pygments/lexers/templates.py5
-rw-r--r--tests/test_smarty.py40
2 files changed, 43 insertions, 2 deletions
diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py
index 67dbc4a7..4a8a89a2 100644
--- a/pygments/lexers/templates.py
+++ b/pygments/lexers/templates.py
@@ -170,10 +170,11 @@ class SmartyLexer(RegexLexer):
],
'smarty': [
(r'\s+', Text),
- (r'\}', Comment.Preproc, '#pop'),
+ (r'{', Comment.Preproc, '#push'),
+ (r'}', Comment.Preproc, '#pop'),
(r'#[a-zA-Z_]\w*#', Name.Variable),
(r'\$[a-zA-Z_]\w*(\.\w+)*', Name.Variable),
- (r'[~!%^&*()+=|\[\]:;,.<>/?{}@-]', Operator),
+ (r'[~!%^&*()+=|\[\]:;,.<>/?@-]', Operator),
(r'(true|false|null)\b', Keyword.Constant),
(r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
r"0[xX][0-9a-fA-F]+[Ll]?", Number),
diff --git a/tests/test_smarty.py b/tests/test_smarty.py
new file mode 100644
index 00000000..20346afd
--- /dev/null
+++ b/tests/test_smarty.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+"""
+ Basic SmartyLexer Test
+ ~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import unittest
+
+from pygments.token import Operator, Number, Text, Token
+from pygments.lexers import SmartyLexer
+
+
+class SmartyTest(unittest.TestCase):
+
+ def setUp(self):
+ self.lexer = SmartyLexer()
+
+ def testNestedCurly(self):
+ fragment = u'{templateFunction param={anotherFunction} param2=$something}\n'
+ tokens = [
+ (Token.Comment.Preproc, u'{'),
+ (Token.Name.Function, u'templateFunction'),
+ (Token.Text, u' '),
+ (Token.Name.Attribute, u'param'),
+ (Token.Operator, u'='),
+ (Token.Comment.Preproc, u'{'),
+ (Token.Name.Attribute, u'anotherFunction'),
+ (Token.Comment.Preproc, u'}'),
+ (Token.Text, u' '),
+ (Token.Name.Attribute, u'param2'),
+ (Token.Operator, u'='),
+ (Token.Name.Variable, u'$something'),
+ (Token.Comment.Preproc, u'}'),
+ (Token.Other, u'\n'),
+ ]
+ self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
+