ThirdParty/Pygments/pygments/lexers/templates.py

changeset 2426
da76c71624de
parent 1705
b0fbc9300f2b
child 2525
8b507a9a2d40
equal deleted inserted replaced
2425:ace8a08028f3 2426:da76c71624de
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-2012 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2013 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 13
14 from pygments.lexers.web import \ 14 from pygments.lexers.web import \
15 PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer 15 PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer, LassoLexer
16 from pygments.lexers.agile import PythonLexer, PerlLexer 16 from pygments.lexers.agile import PythonLexer, PerlLexer
17 from pygments.lexers.compiled import JavaLexer 17 from pygments.lexers.compiled import JavaLexer
18 from pygments.lexers.jvm import TeaLangLexer 18 from pygments.lexers.jvm import TeaLangLexer
19 from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \ 19 from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \
20 include, using, this 20 include, using, this
35 'MakoHtmlLexer', 'MakoXmlLexer', 'MakoJavascriptLexer', 35 'MakoHtmlLexer', 'MakoXmlLexer', 'MakoJavascriptLexer',
36 'MakoCssLexer', 'JspLexer', 'CheetahLexer', 'CheetahHtmlLexer', 36 'MakoCssLexer', 'JspLexer', 'CheetahLexer', 'CheetahHtmlLexer',
37 'CheetahXmlLexer', 'CheetahJavascriptLexer', 'EvoqueLexer', 37 'CheetahXmlLexer', 'CheetahJavascriptLexer', 'EvoqueLexer',
38 'EvoqueHtmlLexer', 'EvoqueXmlLexer', 'ColdfusionLexer', 38 'EvoqueHtmlLexer', 'EvoqueXmlLexer', 'ColdfusionLexer',
39 'ColdfusionHtmlLexer', 'VelocityLexer', 'VelocityHtmlLexer', 39 'ColdfusionHtmlLexer', 'VelocityLexer', 'VelocityHtmlLexer',
40 'VelocityXmlLexer', 'SspLexer', 'TeaTemplateLexer'] 40 'VelocityXmlLexer', 'SspLexer', 'TeaTemplateLexer', 'LassoHtmlLexer',
41 'LassoXmlLexer', 'LassoCssLexer', 'LassoJavascriptLexer']
41 42
42 43
43 class ErbLexer(Lexer): 44 class ErbLexer(Lexer):
44 """ 45 """
45 Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating) 46 Generic `ERB <http://ruby-doc.org/core/classes/ERB.html>`_ (Ruby Templating)
221 (r'\$\{?', Punctuation, 'variable') 222 (r'\$\{?', Punctuation, 'variable')
222 ], 223 ],
223 'variable': [ 224 'variable': [
224 (identifier, Name.Variable), 225 (identifier, Name.Variable),
225 (r'\(', Punctuation, 'funcparams'), 226 (r'\(', Punctuation, 'funcparams'),
226 (r'(\.)(' + identifier + r')', bygroups(Punctuation, Name.Variable), '#push'), 227 (r'(\.)(' + identifier + r')',
228 bygroups(Punctuation, Name.Variable), '#push'),
227 (r'\}', Punctuation, '#pop'), 229 (r'\}', Punctuation, '#pop'),
228 (r'', Other, '#pop') 230 (r'', Other, '#pop')
229 ], 231 ],
230 'directiveparams': [ 232 'directiveparams': [
231 (r'(&&|\|\||==?|!=?|[-<>+*%&\|\^/])|\b(eq|ne|gt|lt|ge|le|not|in)\b', Operator), 233 (r'(&&|\|\||==?|!=?|[-<>+*%&\|\^/])|\b(eq|ne|gt|lt|ge|le|not|in)\b',
234 Operator),
232 (r'\[', Operator, 'rangeoperator'), 235 (r'\[', Operator, 'rangeoperator'),
233 (r'\b' + identifier + r'\b', Name.Function), 236 (r'\b' + identifier + r'\b', Name.Function),
234 include('funcparams') 237 include('funcparams')
235 ], 238 ],
236 'rangeoperator': [ 239 'rangeoperator': [
258 rv += 0.25 261 rv += 0.25
259 if re.search(r'#\{?if\}?\(.+?\).*?#\{?end\}?', text): 262 if re.search(r'#\{?if\}?\(.+?\).*?#\{?end\}?', text):
260 rv += 0.15 263 rv += 0.15
261 if re.search(r'#\{?foreach\}?\(.+?\).*?#\{?end\}?', text): 264 if re.search(r'#\{?foreach\}?\(.+?\).*?#\{?end\}?', text):
262 rv += 0.15 265 rv += 0.15
263 if re.search(r'\$\{?[a-zA-Z_][a-zA-Z0-9_]*(\([^)]*\))?(\.[a-zA-Z0-9_]+(\([^)]*\))?)*\}?', text): 266 if re.search(r'\$\{?[a-zA-Z_][a-zA-Z0-9_]*(\([^)]*\))?'
267 r'(\.[a-zA-Z0-9_]+(\([^)]*\))?)*\}?', text):
264 rv += 0.01 268 rv += 0.01
265 return rv 269 return rv
266 270
267 271
268 class VelocityHtmlLexer(DelegatingLexer): 272 class VelocityHtmlLexer(DelegatingLexer):
1502 (r'#', String.Double), 1506 (r'#', String.Double),
1503 (r'"', String.Double, '#pop'), 1507 (r'"', String.Double, '#pop'),
1504 ], 1508 ],
1505 } 1509 }
1506 1510
1511
1507 class ColdfusionMarkupLexer(RegexLexer): 1512 class ColdfusionMarkupLexer(RegexLexer):
1508 """ 1513 """
1509 Coldfusion markup only 1514 Coldfusion markup only
1510 """ 1515 """
1511 name = 'Coldfusion' 1516 name = 'Coldfusion'
1626 if looks_like_xml(text): 1631 if looks_like_xml(text):
1627 rv += 0.4 1632 rv += 0.4
1628 if '<%' in text and '%>' in text: 1633 if '<%' in text and '%>' in text:
1629 rv += 0.1 1634 rv += 0.1
1630 return rv 1635 return rv
1636
1637
1638 class LassoHtmlLexer(DelegatingLexer):
1639 """
1640 Subclass of the `LassoLexer` which highlights unhandled data with the
1641 `HtmlLexer`.
1642
1643 Nested JavaScript and CSS is also highlighted.
1644
1645 *New in Pygments 1.6.*
1646 """
1647
1648 name = 'HTML+Lasso'
1649 aliases = ['html+lasso']
1650 alias_filenames = ['*.html', '*.htm', '*.xhtml', '*.lasso', '*.lasso[89]',
1651 '*.incl', '*.inc', '*.las']
1652 mimetypes = ['text/html+lasso',
1653 'application/x-httpd-lasso',
1654 'application/x-httpd-lasso[89]']
1655
1656 def __init__(self, **options):
1657 super(LassoHtmlLexer, self).__init__(HtmlLexer, LassoLexer, **options)
1658
1659 def analyse_text(text):
1660 rv = LassoLexer.analyse_text(text)
1661 if re.search(r'<\w+>', text, re.I):
1662 rv += 0.2
1663 if html_doctype_matches(text):
1664 rv += 0.5
1665 return rv
1666
1667
1668 class LassoXmlLexer(DelegatingLexer):
1669 """
1670 Subclass of the `LassoLexer` which highlights unhandled data with the
1671 `XmlLexer`.
1672
1673 *New in Pygments 1.6.*
1674 """
1675
1676 name = 'XML+Lasso'
1677 aliases = ['xml+lasso']
1678 alias_filenames = ['*.xml', '*.lasso', '*.lasso[89]',
1679 '*.incl', '*.inc', '*.las']
1680 mimetypes = ['application/xml+lasso']
1681
1682 def __init__(self, **options):
1683 super(LassoXmlLexer, self).__init__(XmlLexer, LassoLexer, **options)
1684
1685 def analyse_text(text):
1686 rv = LassoLexer.analyse_text(text)
1687 if looks_like_xml(text):
1688 rv += 0.5
1689 return rv
1690
1691
1692 class LassoCssLexer(DelegatingLexer):
1693 """
1694 Subclass of the `LassoLexer` which highlights unhandled data with the
1695 `CssLexer`.
1696
1697 *New in Pygments 1.6.*
1698 """
1699
1700 name = 'CSS+Lasso'
1701 aliases = ['css+lasso']
1702 alias_filenames = ['*.css']
1703 mimetypes = ['text/css+lasso']
1704
1705 def __init__(self, **options):
1706 options['requiredelimiters'] = True
1707 super(LassoCssLexer, self).__init__(CssLexer, LassoLexer, **options)
1708
1709 def analyse_text(text):
1710 rv = LassoLexer.analyse_text(text)
1711 if re.search(r'\w+:.+;', text):
1712 rv += 0.1
1713 if 'padding:' in text:
1714 rv += 0.1
1715 return rv
1716
1717
1718 class LassoJavascriptLexer(DelegatingLexer):
1719 """
1720 Subclass of the `LassoLexer` which highlights unhandled data with the
1721 `JavascriptLexer`.
1722
1723 *New in Pygments 1.6.*
1724 """
1725
1726 name = 'JavaScript+Lasso'
1727 aliases = ['js+lasso', 'javascript+lasso']
1728 alias_filenames = ['*.js']
1729 mimetypes = ['application/x-javascript+lasso',
1730 'text/x-javascript+lasso',
1731 'text/javascript+lasso']
1732
1733 def __init__(self, **options):
1734 options['requiredelimiters'] = True
1735 super(LassoJavascriptLexer, self).__init__(JavascriptLexer, LassoLexer,
1736 **options)
1737
1738 def analyse_text(text):
1739 rv = LassoLexer.analyse_text(text)
1740 if 'function' in text:
1741 rv += 0.2
1742 return rv

eric ide

mercurial