eric6/ThirdParty/Pygments/pygments/lexers/templates.py

changeset 7547
21b0534faebc
parent 6942
2602857055c5
child 7701
25f42e208e08
equal deleted inserted replaced
7546:bf5f777260a6 7547:21b0534faebc
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-2017 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2019 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
224 (r'(#\{?)(' + identifier + r')(\}?)(\s?\()', 224 (r'(#\{?)(' + identifier + r')(\}?)(\s?\()',
225 bygroups(Comment.Preproc, Name.Function, Comment.Preproc, Punctuation), 225 bygroups(Comment.Preproc, Name.Function, Comment.Preproc, Punctuation),
226 'directiveparams'), 226 'directiveparams'),
227 (r'(#\{?)(' + identifier + r')(\}|\b)', 227 (r'(#\{?)(' + identifier + r')(\}|\b)',
228 bygroups(Comment.Preproc, Name.Function, Comment.Preproc)), 228 bygroups(Comment.Preproc, Name.Function, Comment.Preproc)),
229 (r'\$\{?', Punctuation, 'variable') 229 (r'\$!?\{?', Punctuation, 'variable')
230 ], 230 ],
231 'variable': [ 231 'variable': [
232 (identifier, Name.Variable), 232 (identifier, Name.Variable),
233 (r'\(', Punctuation, 'funcparams'), 233 (r'\(', Punctuation, 'funcparams'),
234 (r'(\.)(' + identifier + r')', 234 (r'(\.)(' + identifier + r')',
247 (r'\.\.', Operator), 247 (r'\.\.', Operator),
248 include('funcparams'), 248 include('funcparams'),
249 (r'\]', Operator, '#pop') 249 (r'\]', Operator, '#pop')
250 ], 250 ],
251 'funcparams': [ 251 'funcparams': [
252 (r'\$\{?', Punctuation, 'variable'), 252 (r'\$!?\{?', Punctuation, 'variable'),
253 (r'\s+', Text), 253 (r'\s+', Text),
254 (r'[,:]', Punctuation), 254 (r'[,:]', Punctuation),
255 (r'"(\\\\|\\"|[^"])*"', String.Double), 255 (r'"(\\\\|\\"|[^"])*"', String.Double),
256 (r"'(\\\\|\\'|[^'])*'", String.Single), 256 (r"'(\\\\|\\'|[^'])*'", String.Single),
257 (r"0[xX][0-9a-fA-F]+[Ll]?", Number), 257 (r"0[xX][0-9a-fA-F]+[Ll]?", Number),
272 rv += 0.25 272 rv += 0.25
273 if re.search(r'#\{?if\}?\(.+?\).*?#\{?end\}?', text): 273 if re.search(r'#\{?if\}?\(.+?\).*?#\{?end\}?', text):
274 rv += 0.15 274 rv += 0.15
275 if re.search(r'#\{?foreach\}?\(.+?\).*?#\{?end\}?', text): 275 if re.search(r'#\{?foreach\}?\(.+?\).*?#\{?end\}?', text):
276 rv += 0.15 276 rv += 0.15
277 if re.search(r'\$\{?[a-zA-Z_]\w*(\([^)]*\))?' 277 if re.search(r'\$!?\{?[a-zA-Z_]\w*(\([^)]*\))?'
278 r'(\.\w+(\([^)]*\))?)*\}?', text): 278 r'(\.\w+(\([^)]*\))?)*\}?', text):
279 rv += 0.01 279 rv += 0.01
280 return rv 280 return rv
281 281
282 282
321 321
322 322
323 class DjangoLexer(RegexLexer): 323 class DjangoLexer(RegexLexer):
324 """ 324 """
325 Generic `django <http://www.djangoproject.com/documentation/templates/>`_ 325 Generic `django <http://www.djangoproject.com/documentation/templates/>`_
326 and `jinja <http://wsgiarea.pocoo.org/jinja/>`_ template lexer. 326 and `jinja <https://jinja.pocoo.org/jinja/>`_ template lexer.
327 327
328 It just highlights django/jinja code between the preprocessor directives, 328 It just highlights django/jinja code between the preprocessor directives,
329 other data is left untouched by the lexer. 329 other data is left untouched by the lexer.
330 """ 330 """
331 331
373 (r'(loop|block|super|forloop)\b', Name.Builtin), 373 (r'(loop|block|super|forloop)\b', Name.Builtin),
374 (r'[a-zA-Z_][\w-]*', Name.Variable), 374 (r'[a-zA-Z_][\w-]*', Name.Variable),
375 (r'\.\w+', Name.Variable), 375 (r'\.\w+', Name.Variable),
376 (r':?"(\\\\|\\"|[^"])*"', String.Double), 376 (r':?"(\\\\|\\"|[^"])*"', String.Double),
377 (r":?'(\\\\|\\'|[^'])*'", String.Single), 377 (r":?'(\\\\|\\'|[^'])*'", String.Single),
378 (r'([{}()\[\]+\-*/,:~]|[><=]=?)', Operator), 378 (r'([{}()\[\]+\-*/%,:~]|[><=]=?|!=)', Operator),
379 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" 379 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
380 r"0[xX][0-9a-fA-F]+[Ll]?", Number), 380 r"0[xX][0-9a-fA-F]+[Ll]?", Number),
381 ], 381 ],
382 'var': [ 382 'var': [
383 (r'\s+', Text), 383 (r'\s+', Text),
1800 1800
1801 tokens = { 1801 tokens = {
1802 'root': [ 1802 'root': [
1803 (r'[^{]+', Other), 1803 (r'[^{]+', Other),
1804 1804
1805 # Comment start {{! }} or {{!--
1805 (r'\{\{!.*\}\}', Comment), 1806 (r'\{\{!.*\}\}', Comment),
1806 1807
1808 # HTML Escaping open {{{expression
1807 (r'(\{\{\{)(\s*)', bygroups(Comment.Special, Text), 'tag'), 1809 (r'(\{\{\{)(\s*)', bygroups(Comment.Special, Text), 'tag'),
1810
1811 # {{blockOpen {{#blockOpen {{/blockClose with optional tilde ~
1812 (r'(\{\{)([#~/]+)([^\s}]*)',
1813 bygroups(Comment.Preproc, Number.Attribute, Number.Attribute), 'tag'),
1808 (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'tag'), 1814 (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'tag'),
1809 ], 1815 ],
1810 1816
1811 'tag': [ 1817 'tag': [
1812 (r'\s+', Text), 1818 (r'\s+', Text),
1819 # HTML Escaping close }}}
1813 (r'\}\}\}', Comment.Special, '#pop'), 1820 (r'\}\}\}', Comment.Special, '#pop'),
1814 (r'\}\}', Comment.Preproc, '#pop'), 1821 # blockClose}}, includes optional tilde ~
1815 1822 (r'(~?)(\}\})', bygroups(Number, Comment.Preproc), '#pop'),
1816 # Handlebars
1817 (r'([#/]*)(each|if|unless|else|with|log|in(line)?)', bygroups(Keyword,
1818 Keyword)),
1819 (r'#\*inline', Keyword),
1820
1821 # General {{#block}}
1822 (r'([#/])([\w-]+)', bygroups(Name.Function, Name.Function)),
1823 1823
1824 # {{opt=something}} 1824 # {{opt=something}}
1825 (r'([\w-]+)(=)', bygroups(Name.Attribute, Operator)), 1825 (r'([^\s}]+)(=)', bygroups(Name.Attribute, Operator)),
1826 1826
1827 # Partials {{> ...}} 1827 # Partials {{> ...}}
1828 (r'(>)(\s*)(@partial-block)', bygroups(Keyword, Text, Keyword)), 1828 (r'(>)(\s*)(@partial-block)', bygroups(Keyword, Text, Keyword)),
1829 (r'(#?>)(\s*)([\w-]+)', bygroups(Keyword, Text, Name.Variable)), 1829 (r'(#?>)(\s*)([\w-]+)', bygroups(Keyword, Text, Name.Variable)),
1830 (r'(>)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 1830 (r'(>)(\s*)(\()', bygroups(Keyword, Text, Punctuation),
1843 (r'[\w-]+', Name.Function), 1843 (r'[\w-]+', Name.Function),
1844 1844
1845 include('generic'), 1845 include('generic'),
1846 ], 1846 ],
1847 'variable': [ 1847 'variable': [
1848 (r'[a-zA-Z][\w-]*', Name.Variable), 1848 (r'[()/@a-zA-Z][\w-]*', Name.Variable),
1849 (r'\.[\w-]+', Name.Variable), 1849 (r'\.[\w-]+', Name.Variable),
1850 (r'(this\/|\.\/|(\.\.\/)+)[\w-]+', Name.Variable), 1850 (r'(this\/|\.\/|(\.\.\/)+)[\w-]+', Name.Variable),
1851 ], 1851 ],
1852 'generic': [ 1852 'generic': [
1853 include('variable'), 1853 include('variable'),

eric ide

mercurial