diff options
author | Tim Hatch <tim@timhatch.com> | 2014-05-12 13:33:48 -0700 |
---|---|---|
committer | Tim Hatch <tim@timhatch.com> | 2014-05-12 13:33:48 -0700 |
commit | 16b39eea26af87813151b03992f2ed4738057eaa (patch) | |
tree | b5651a83535cc46bbc3faf3b96fc497262305807 | |
parent | c6f9868a4aef43beec4f80c582dad9c69c34c231 (diff) | |
parent | e1f88dcdb9733044ab793866e25f1a5810c926fa (diff) | |
download | pygments-16b39eea26af87813151b03992f2ed4738057eaa.tar.gz |
Merged in jaingaurav2/pygments-main-978 (pull request #339)
ColdFusion: Add Support for nested comments
-rw-r--r-- | pygments/lexers/templates.py | 8 | ||||
-rw-r--r-- | tests/examplefiles/demo.cfm | 12 | ||||
-rw-r--r-- | tests/test_cfm.py | 46 |
3 files changed, 65 insertions, 1 deletions
diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index d06ea288..9ed1c635 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -1534,7 +1534,7 @@ class ColdfusionMarkupLexer(RegexLexer): (r'<[^<>]*', Other), ], 'tags': [ - (r'(?s)<!---.*?--->', Comment.Multiline), + (r'<!---', Comment.Multiline, 'cfcomment'), (r'(?s)<!--.*?-->', Comment), (r'<cfoutput.*?>', Name.Builtin, 'cfoutput'), (r'(?s)(<cfscript.*?>)(.+?)(</cfscript.*?>)', @@ -1556,6 +1556,12 @@ class ColdfusionMarkupLexer(RegexLexer): (r'(?s)<[^<>]*', Other), (r'#', Other), ], + 'cfcomment': [ + (r'(?s)(.*?)(<!---)', + bygroups(Comment.Multiline, Comment.Multiline), '#push'), + (r'(?s)(.*?)(--->)', + bygroups(Comment.Multiline, Comment.Multiline), '#pop'), + ], } diff --git a/tests/examplefiles/demo.cfm b/tests/examplefiles/demo.cfm index d94a06a0..49690484 100644 --- a/tests/examplefiles/demo.cfm +++ b/tests/examplefiles/demo.cfm @@ -1,4 +1,11 @@ <!--- cfcomment ---> +<!--- nested <!--- cfcomment ---> ---> +<!--- multi-line +nested +<!--- +cfcomment +---> +---> <!-- html comment --> <html> <head> @@ -17,6 +24,9 @@ #IsDate("foo")#<br /> #DaysInMonth(RightNow)# </cfoutput> +<cfset x="x"> +<cfset y="y"> +<cfset z="z"> <cfoutput group="x"> #x# <cfoutput>#y#</cfoutput> @@ -29,6 +39,8 @@ <cfset greeting = "Hello #person#"> <cfset greeting = "Hello" & " world!"> +<cfset a = 5> +<cfset b = 10> <cfset c = a^b> <cfset c = a MOD b> <cfset c = a / b> diff --git a/tests/test_cfm.py b/tests/test_cfm.py new file mode 100644 index 00000000..2ff25bd6 --- /dev/null +++ b/tests/test_cfm.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +""" + Basic ColdfusionHtmlLexer Test + ~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest +import os + +from pygments.token import Token +from pygments.lexers import ColdfusionHtmlLexer + + +class ColdfusionHtmlLexerTest(unittest.TestCase): + + def setUp(self): + self.lexer = ColdfusionHtmlLexer() + + def testBasicComment(self): + fragment = u'<!--- cfcomment --->' + expected = [ + (Token.Text, u''), + (Token.Comment.Multiline, u'<!---'), + (Token.Comment.Multiline, u' cfcomment '), + (Token.Comment.Multiline, u'--->'), + (Token.Text, u'\n'), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) + + def testNestedComment(self): + fragment = u'<!--- nested <!--- cfcomment ---> --->' + expected = [ + (Token.Text, u''), + (Token.Comment.Multiline, u'<!---'), + (Token.Comment.Multiline, u' nested '), + (Token.Comment.Multiline, u'<!---'), + (Token.Comment.Multiline, u' cfcomment '), + (Token.Comment.Multiline, u'--->'), + (Token.Comment.Multiline, u' '), + (Token.Comment.Multiline, u'--->'), + (Token.Text, u'\n'), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) |