5 from sets import Set as set
7 from pygments.lexers.web import \
8 HtmlLexer, XmlLexer, JavascriptLexer, CssLexer
9 from pygments.lexers.agile import PythonLexer
10 from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \
12 from pygments.token import Error, Punctuation, \
13 Text, Comment, Operator, Keyword, Name, String, Number, Other, Literal
14 from pygments.util import html_doctype_matches, looks_like_xml
16 class MakoLexer(RegexLexer):
23 (r'(\s*)(\%)(\s*end(?:\w+))(\n|\Z)',
24 bygroups(Text, Comment.Preproc, Keyword, Other)),
25 (r'(\s*)(\%)([^\n]*)(\n|\Z)',
26 bygroups(Text, Comment.Preproc, using(PythonLexer), Other)),
27 (r'(\s*)(##[^\n]*)(\n|\Z)',
28 bygroups(Text, Comment.Preproc, Other)),
29 (r'''(?s)<%doc>.*?</%doc>''', Comment.Preproc),
30 (r'(<%)([\w\.\:]+)', bygroups(Comment.Preproc, Name.Builtin), 'tag'),
31 (r'(</%)([\w\.\:]+)(>)', bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)),
32 (r'<%(?=([\w\.\:]+))', Comment.Preproc, 'ondeftags'),
33 (r'(<%(?:!?))(.*?)(%>)(?s)', bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
35 bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
37 (.+?) # anything, followed by:
39 (?<=\n)(?=%|\#\#) | # an eval or comment line
40 (?=\#\*) | # multiline comment
41 (?=</?%) | # a python block
43 (?=\$\{) | # a substitution
46 (\\\n) | # an escaped newline
49 ''', bygroups(Other, Operator)),
53 (r'<%', Comment.Preproc),
54 (r'(?<=<%)(include|inherit|namespace|page)', Name.Builtin),
58 (r'((?:\w+)\s*=)\s*(".*?")',
59 bygroups(Name.Attribute, String)),
60 (r'/?\s*>', Comment.Preproc, '#pop'),
64 ('".*?"', String, '#pop'),
65 ("'.*?'", String, '#pop'),
66 (r'[^\s>]+', String, '#pop'),
71 class MakoHtmlLexer(DelegatingLexer):
73 aliases = ['html+mako']
75 def __init__(self, **options):
76 super(MakoHtmlLexer, self).__init__(HtmlLexer, MakoLexer,
79 class MakoXmlLexer(DelegatingLexer):
81 aliases = ['xml+mako']
83 def __init__(self, **options):
84 super(MakoXmlLexer, self).__init__(XmlLexer, MakoLexer,
87 class MakoJavascriptLexer(DelegatingLexer):
88 name = 'JavaScript+Mako'
89 aliases = ['js+mako', 'javascript+mako']
91 def __init__(self, **options):
92 super(MakoJavascriptLexer, self).__init__(JavascriptLexer,
95 class MakoCssLexer(DelegatingLexer):
97 aliases = ['css+mako']
99 def __init__(self, **options):
100 super(MakoCssLexer, self).__init__(CssLexer, MakoLexer,