~stoq-dev/stoqnfe/master

« back to all changes in this revision

Viewing changes to external/mako/ext/pygmentplugin.py

  • Committer: georgeyk
  • Date: 2009-10-28 16:25:15 UTC
  • mfrom: (12.1.13 stoqnfe-danfe2)
  • Revision ID: georgeyk.dev@gmail.com-20091028162515-8ajv4cujuqnqa9k2
Initial implementation of the DANF-e report.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pygments.lexers.web import \
 
2
     HtmlLexer, XmlLexer, JavascriptLexer, CssLexer
 
3
from pygments.lexers.agile import PythonLexer
 
4
from pygments.lexer import DelegatingLexer, RegexLexer, bygroups, \
 
5
     include, using
 
6
from pygments.token import  \
 
7
     Text, Comment, Operator, Keyword, Name, String, Other
 
8
 
 
9
class MakoLexer(RegexLexer):
 
10
    name = 'Mako'
 
11
    aliases = ['mako']
 
12
    filenames = ['*.mao']
 
13
 
 
14
    tokens = {
 
15
        'root': [
 
16
            (r'(\s*)(\%)(\s*end(?:\w+))(\n|\Z)',
 
17
             bygroups(Text, Comment.Preproc, Keyword, Other)),
 
18
            (r'(\s*)(\%)([^\n]*)(\n|\Z)',
 
19
             bygroups(Text, Comment.Preproc, using(PythonLexer), Other)),
 
20
             (r'(\s*)(##[^\n]*)(\n|\Z)',
 
21
              bygroups(Text, Comment.Preproc, Other)),
 
22
              (r'''(?s)<%doc>.*?</%doc>''', Comment.Preproc),
 
23
            (r'(<%)(def|call|namespace|text)', bygroups(Comment.Preproc, Name.Builtin), 'tag'),
 
24
            (r'(</%)(def|call|namespace|text)(>)', bygroups(Comment.Preproc, Name.Builtin, Comment.Preproc)),
 
25
            (r'<%(?=(include|inherit|namespace|page))', Comment.Preproc, 'ondeftags'),
 
26
            (r'(<%(?:!?))(.*?)(%>)(?s)', bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
 
27
            (r'(\$\{)(.*?)(\})',
 
28
             bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
 
29
            (r'''(?sx)
 
30
                (.+?)               # anything, followed by:
 
31
                (?:
 
32
                 (?<=\n)(?=%|\#\#) |  # an eval or comment line
 
33
                 (?=\#\*) |          # multiline comment
 
34
                 (?=</?%) |         # a python block
 
35
                                    # call start or end
 
36
                 (?=\$\{) |         # a substitution
 
37
                 (?<=\n)(?=\s*%) |
 
38
                                    # - don't consume
 
39
                 (\\\n) |           # an escaped newline
 
40
                 \Z                 # end of string
 
41
                )
 
42
            ''', bygroups(Other, Operator)),
 
43
            (r'\s+', Text),
 
44
        ],
 
45
        'ondeftags': [
 
46
            (r'<%', Comment.Preproc),
 
47
            (r'(?<=<%)(include|inherit|namespace|page)', Name.Builtin),
 
48
            include('tag'),
 
49
        ],
 
50
        'tag': [
 
51
            (r'((?:\w+)\s*=)\s*(".*?")',
 
52
             bygroups(Name.Attribute, String)),
 
53
            (r'/?\s*>', Comment.Preproc, '#pop'),
 
54
            (r'\s+', Text),
 
55
        ],
 
56
        'attr': [
 
57
            ('".*?"', String, '#pop'),
 
58
            ("'.*?'", String, '#pop'),
 
59
            (r'[^\s>]+', String, '#pop'),
 
60
        ],
 
61
    }
 
62
 
 
63
 
 
64
class MakoHtmlLexer(DelegatingLexer):
 
65
    name = 'HTML+Mako'
 
66
    aliases = ['html+mako']
 
67
 
 
68
    def __init__(self, **options):
 
69
        super(MakoHtmlLexer, self).__init__(HtmlLexer, MakoLexer,
 
70
                                              **options)
 
71
 
 
72
class MakoXmlLexer(DelegatingLexer):
 
73
    name = 'XML+Mako'
 
74
    aliases = ['xml+mako']
 
75
 
 
76
    def __init__(self, **options):
 
77
        super(MakoXmlLexer, self).__init__(XmlLexer, MakoLexer,
 
78
                                             **options)
 
79
 
 
80
class MakoJavascriptLexer(DelegatingLexer):
 
81
    name = 'JavaScript+Mako'
 
82
    aliases = ['js+mako', 'javascript+mako']
 
83
 
 
84
    def __init__(self, **options):
 
85
        super(MakoJavascriptLexer, self).__init__(JavascriptLexer,
 
86
                                                    MakoLexer, **options)
 
87
 
 
88
class MakoCssLexer(DelegatingLexer):
 
89
    name = 'CSS+Mako'
 
90
    aliases = ['css+mako']
 
91
 
 
92
    def __init__(self, **options):
 
93
        super(MakoCssLexer, self).__init__(CssLexer, MakoLexer,
 
94
                                             **options)