3 pygments.lexers.templates |
3 pygments.lexers.templates |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for various template engines' markup. |
6 Lexers for various template engines' markup. |
7 |
7 |
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 try: |
|
14 set |
|
15 except NameError: |
|
16 from sets import Set as set |
|
17 |
13 |
18 from pygments.lexers.web import \ |
14 from pygments.lexers.web import \ |
19 PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer |
15 PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer |
20 from pygments.lexers.agile import PythonLexer |
16 from pygments.lexers.agile import PythonLexer |
21 from pygments.lexers.compiled import JavaLexer |
17 from pygments.lexers.compiled import JavaLexer |
36 'MyghtyLexer', 'MyghtyHtmlLexer', 'MyghtyXmlLexer', |
32 'MyghtyLexer', 'MyghtyHtmlLexer', 'MyghtyXmlLexer', |
37 'MyghtyCssLexer', 'MyghtyJavascriptLexer', 'MakoLexer', |
33 'MyghtyCssLexer', 'MyghtyJavascriptLexer', 'MakoLexer', |
38 'MakoHtmlLexer', 'MakoXmlLexer', 'MakoJavascriptLexer', |
34 'MakoHtmlLexer', 'MakoXmlLexer', 'MakoJavascriptLexer', |
39 'MakoCssLexer', 'JspLexer', 'CheetahLexer', 'CheetahHtmlLexer', |
35 'MakoCssLexer', 'JspLexer', 'CheetahLexer', 'CheetahHtmlLexer', |
40 'CheetahXmlLexer', 'CheetahJavascriptLexer', |
36 'CheetahXmlLexer', 'CheetahJavascriptLexer', |
41 'EvoqueLexer', 'EvoqueHtmlLexer', 'EvoqueXmlLexer'] |
37 'EvoqueLexer', 'EvoqueHtmlLexer', 'EvoqueXmlLexer', |
|
38 'ColdfusionLexer', 'ColdfusionHtmlLexer'] |
42 |
39 |
43 |
40 |
44 class ErbLexer(Lexer): |
41 class ErbLexer(Lexer): |
45 """ |
42 """ |
46 Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating) |
43 Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating) |
244 (r'(loop|block|super|forloop)\b', Name.Builtin), |
241 (r'(loop|block|super|forloop)\b', Name.Builtin), |
245 (r'[a-zA-Z][a-zA-Z0-9_]*', Name.Variable), |
242 (r'[a-zA-Z][a-zA-Z0-9_]*', Name.Variable), |
246 (r'\.[a-zA-Z0-9_]+', Name.Variable), |
243 (r'\.[a-zA-Z0-9_]+', Name.Variable), |
247 (r':?"(\\\\|\\"|[^"])*"', String.Double), |
244 (r':?"(\\\\|\\"|[^"])*"', String.Double), |
248 (r":?'(\\\\|\\'|[^'])*'", String.Single), |
245 (r":?'(\\\\|\\'|[^'])*'", String.Single), |
249 (r'([{}()\[\]+\-*/,:]|[><=]=?)', Operator), |
246 (r'([{}()\[\]+\-*/,:~]|[><=]=?)', Operator), |
250 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" |
247 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" |
251 r"0[xX][0-9a-fA-F]+[Ll]?", Number), |
248 r"0[xX][0-9a-fA-F]+[Ll]?", Number), |
252 ], |
249 ], |
253 'var': [ |
250 'var': [ |
254 (r'\s+', Text), |
251 (r'\s+', Text), |
1292 mimetypes = ['application/xml+evoque'] |
1289 mimetypes = ['application/xml+evoque'] |
1293 |
1290 |
1294 def __init__(self, **options): |
1291 def __init__(self, **options): |
1295 super(EvoqueXmlLexer, self).__init__(XmlLexer, EvoqueLexer, |
1292 super(EvoqueXmlLexer, self).__init__(XmlLexer, EvoqueLexer, |
1296 **options) |
1293 **options) |
|
1294 |
|
1295 class ColdfusionLexer(RegexLexer): |
|
1296 """ |
|
1297 Coldfusion statements |
|
1298 """ |
|
1299 name = 'cfstatement' |
|
1300 aliases = ['cfs'] |
|
1301 filenames = [] |
|
1302 mimetypes = [] |
|
1303 flags = re.IGNORECASE | re.MULTILINE |
|
1304 |
|
1305 tokens = { |
|
1306 'root': [ |
|
1307 (r'//.*', Comment), |
|
1308 (r'\+\+|--', Operator), |
|
1309 (r'[-+*/^&=!]', Operator), |
|
1310 (r'<=|>=|<|>', Operator), |
|
1311 (r'mod\b', Operator), |
|
1312 (r'(eq|lt|gt|lte|gte|not|is|and|or)\b', Operator), |
|
1313 (r'\|\||&&', Operator), |
|
1314 (r'"', String.Double, 'string'), |
|
1315 # There is a special rule for allowing html in single quoted |
|
1316 # strings, evidently. |
|
1317 (r"'.*?'", String.Single), |
|
1318 (r'\d+', Number), |
|
1319 (r'(if|else|len|var|case|default|break|switch)\b', Keyword), |
|
1320 (r'([A-Za-z_$][A-Za-z0-9_.]*)\s*(\()', bygroups(Name.Function, Punctuation)), |
|
1321 (r'[A-Za-z_$][A-Za-z0-9_.]*', Name.Variable), |
|
1322 (r'[()\[\]{};:,.\\]', Punctuation), |
|
1323 (r'\s+', Text), |
|
1324 ], |
|
1325 'string': [ |
|
1326 (r'""', String.Double), |
|
1327 (r'#.+?#', String.Interp), |
|
1328 (r'[^"#]+', String.Double), |
|
1329 (r'#', String.Double), |
|
1330 (r'"', String.Double, '#pop'), |
|
1331 ], |
|
1332 } |
|
1333 |
|
1334 class ColdfusionMarkupLexer(RegexLexer): |
|
1335 """ |
|
1336 Coldfusion markup only |
|
1337 """ |
|
1338 name = 'Coldfusion' |
|
1339 aliases = ['cf'] |
|
1340 filenames = [] |
|
1341 mimetypes = [] |
|
1342 |
|
1343 tokens = { |
|
1344 'root': [ |
|
1345 (r'[^<]+', Other), |
|
1346 include('tags'), |
|
1347 (r'<[^<>]*', Other), |
|
1348 ], |
|
1349 'tags': [ |
|
1350 (r'(?s)<!---.*?--->', Comment.Multiline), |
|
1351 (r'(?s)<!--.*?-->', Comment), |
|
1352 (r'<cfoutput.*?>', Name.Builtin, 'cfoutput'), |
|
1353 (r'(?s)(<cfscript.*?>)(.+?)(</cfscript.*?>)', |
|
1354 bygroups(Name.Builtin, using(ColdfusionLexer), Name.Builtin)), |
|
1355 # negative lookbehind is for strings with embedded > |
|
1356 (r'(?s)(</?cf(?:component|include|if|else|elseif|loop|return|' |
|
1357 r'dbinfo|dump|abort|location|invoke|throw|file|savecontent|' |
|
1358 r'mailpart|mail|header|content|zip|image|lock|argument|try|' |
|
1359 r'catch|break|directory|http|set|function|param)\b)(.*?)((?<!\\)>)', |
|
1360 bygroups(Name.Builtin, using(ColdfusionLexer), Name.Builtin)), |
|
1361 ], |
|
1362 'cfoutput': [ |
|
1363 (r'[^#<]+', Other), |
|
1364 (r'(#)(.*?)(#)', bygroups(Punctuation, using(ColdfusionLexer), |
|
1365 Punctuation)), |
|
1366 #(r'<cfoutput.*?>', Name.Builtin, '#push'), |
|
1367 (r'</cfoutput.*?>', Name.Builtin, '#pop'), |
|
1368 include('tags'), |
|
1369 (r'(?s)<[^<>]*', Other), |
|
1370 (r'#', Other), |
|
1371 ], |
|
1372 } |
|
1373 |
|
1374 |
|
1375 class ColdfusionHtmlLexer(DelegatingLexer): |
|
1376 """ |
|
1377 Coldfusion markup in html |
|
1378 """ |
|
1379 name = 'Coldufsion HTML' |
|
1380 aliases = ['cfm'] |
|
1381 filenames = ['*.cfm', '*.cfml', '*.cfc'] |
|
1382 mimetypes = ['application/x-coldfusion'] |
|
1383 |
|
1384 def __init__(self, **options): |
|
1385 super(ColdfusionHtmlLexer, self).__init__(HtmlLexer, ColdfusionMarkupLexer, |
|
1386 **options) |
|
1387 |