~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/wx/tools/Editra/src/extern/pygments/lexers/_luabuiltins.py

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
    pygments.lexers._luabuiltins
 
4
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
5
 
 
6
    This file contains the names and modules of lua functions
 
7
    It is able to re-generate itself, but for adding new functions you
 
8
    probably have to add some callbacks (see function module_callbacks).
 
9
 
 
10
    Do not edit the MODULES dict by hand.
 
11
 
 
12
    :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
 
13
    :license: BSD, see LICENSE for details.
 
14
"""
 
15
 
 
16
MODULES = {'basic': ['_G',
 
17
           '_VERSION',
 
18
           'assert',
 
19
           'collectgarbage',
 
20
           'dofile',
 
21
           'error',
 
22
           'getfenv',
 
23
           'getmetatable',
 
24
           'ipairs',
 
25
           'load',
 
26
           'loadfile',
 
27
           'loadstring',
 
28
           'next',
 
29
           'pairs',
 
30
           'pcall',
 
31
           'print',
 
32
           'rawequal',
 
33
           'rawget',
 
34
           'rawset',
 
35
           'select',
 
36
           'setfenv',
 
37
           'setmetatable',
 
38
           'tonumber',
 
39
           'tostring',
 
40
           'type',
 
41
           'unpack',
 
42
           'xpcall'],
 
43
 'coroutine': ['coroutine.create',
 
44
               'coroutine.resume',
 
45
               'coroutine.running',
 
46
               'coroutine.status',
 
47
               'coroutine.wrap',
 
48
               'coroutine.yield'],
 
49
 'debug': ['debug.debug',
 
50
           'debug.getfenv',
 
51
           'debug.gethook',
 
52
           'debug.getinfo',
 
53
           'debug.getlocal',
 
54
           'debug.getmetatable',
 
55
           'debug.getregistry',
 
56
           'debug.getupvalue',
 
57
           'debug.setfenv',
 
58
           'debug.sethook',
 
59
           'debug.setlocal',
 
60
           'debug.setmetatable',
 
61
           'debug.setupvalue',
 
62
           'debug.traceback'],
 
63
 'io': ['io.close',
 
64
        'io.flush',
 
65
        'io.input',
 
66
        'io.lines',
 
67
        'io.open',
 
68
        'io.output',
 
69
        'io.popen',
 
70
        'io.read',
 
71
        'io.tmpfile',
 
72
        'io.type',
 
73
        'io.write'],
 
74
 'math': ['math.abs',
 
75
          'math.acos',
 
76
          'math.asin',
 
77
          'math.atan2',
 
78
          'math.atan',
 
79
          'math.ceil',
 
80
          'math.cosh',
 
81
          'math.cos',
 
82
          'math.deg',
 
83
          'math.exp',
 
84
          'math.floor',
 
85
          'math.fmod',
 
86
          'math.frexp',
 
87
          'math.huge',
 
88
          'math.ldexp',
 
89
          'math.log10',
 
90
          'math.log',
 
91
          'math.max',
 
92
          'math.min',
 
93
          'math.modf',
 
94
          'math.pi',
 
95
          'math.pow',
 
96
          'math.rad',
 
97
          'math.random',
 
98
          'math.randomseed',
 
99
          'math.sinh',
 
100
          'math.sin',
 
101
          'math.sqrt',
 
102
          'math.tanh',
 
103
          'math.tan'],
 
104
 'modules': ['module',
 
105
             'require',
 
106
             'package.cpath',
 
107
             'package.loaded',
 
108
             'package.loadlib',
 
109
             'package.path',
 
110
             'package.preload',
 
111
             'package.seeall'],
 
112
 'os': ['os.clock',
 
113
        'os.date',
 
114
        'os.difftime',
 
115
        'os.execute',
 
116
        'os.exit',
 
117
        'os.getenv',
 
118
        'os.remove',
 
119
        'os.rename',
 
120
        'os.setlocale',
 
121
        'os.time',
 
122
        'os.tmpname'],
 
123
 'string': ['string.byte',
 
124
            'string.char',
 
125
            'string.dump',
 
126
            'string.find',
 
127
            'string.format',
 
128
            'string.gmatch',
 
129
            'string.gsub',
 
130
            'string.len',
 
131
            'string.lower',
 
132
            'string.match',
 
133
            'string.rep',
 
134
            'string.reverse',
 
135
            'string.sub',
 
136
            'string.upper'],
 
137
 'table': ['table.concat',
 
138
           'table.insert',
 
139
           'table.maxn',
 
140
           'table.remove',
 
141
           'table.sort']}
 
142
 
 
143
if __name__ == '__main__':
 
144
    import re
 
145
    import urllib
 
146
    import pprint
 
147
 
 
148
    # you can't generally find out what module a function belongs to if you
 
149
    # have only its name. Because of this, here are some callback functions
 
150
    # that recognize if a gioven function belongs to a specific module
 
151
    def module_callbacks():
 
152
        def is_in_coroutine_module(name):
 
153
            return name.startswith('coroutine.')
 
154
 
 
155
        def is_in_modules_module(name):
 
156
            if name in ['require', 'module'] or name.startswith('package'):
 
157
                return True
 
158
            else:
 
159
                return False
 
160
 
 
161
        def is_in_string_module(name):
 
162
            return name.startswith('string.')
 
163
 
 
164
        def is_in_table_module(name):
 
165
            return name.startswith('table.')
 
166
 
 
167
        def is_in_math_module(name):
 
168
            return name.startswith('math')
 
169
 
 
170
        def is_in_io_module(name):
 
171
            return name.startswith('io.')
 
172
 
 
173
        def is_in_os_module(name):
 
174
            return name.startswith('os.')
 
175
 
 
176
        def is_in_debug_module(name):
 
177
            return name.startswith('debug.')
 
178
 
 
179
        return {'coroutine': is_in_coroutine_module,
 
180
                'modules': is_in_modules_module,
 
181
                'string': is_in_string_module,
 
182
                'table': is_in_table_module,
 
183
                'math': is_in_math_module,
 
184
                'io': is_in_io_module,
 
185
                'os': is_in_os_module,
 
186
                'debug': is_in_debug_module}
 
187
 
 
188
 
 
189
 
 
190
    def get_newest_version():
 
191
        f = urllib.urlopen('http://www.lua.org/manual/')
 
192
        r = re.compile(r'^<A HREF="(\d\.\d)/">Lua \1</A>')
 
193
        for line in f:
 
194
            m = r.match(line)
 
195
            if m is not None:
 
196
                return m.groups()[0]
 
197
 
 
198
    def get_lua_functions(version):
 
199
        f = urllib.urlopen('http://www.lua.org/manual/%s/' % version)
 
200
        r = re.compile(r'^<A HREF="manual.html#pdf-(.+)">\1</A>')
 
201
        functions = []
 
202
        for line in f:
 
203
            m = r.match(line)
 
204
            if m is not None:
 
205
                functions.append(m.groups()[0])
 
206
        return functions
 
207
 
 
208
    def get_function_module(name):
 
209
        for mod, cb in module_callbacks().iteritems():
 
210
            if cb(name):
 
211
                return mod
 
212
        if '.' in name:
 
213
            return name.split('.')[0]
 
214
        else:
 
215
            return 'basic'
 
216
 
 
217
    def regenerate(filename, modules):
 
218
        f = open(filename)
 
219
        try:
 
220
            content = f.read()
 
221
        finally:
 
222
            f.close()
 
223
 
 
224
        header = content[:content.find('MODULES = {')]
 
225
        footer = content[content.find("if __name__ == '__main__':"):]
 
226
 
 
227
 
 
228
        f = open(filename, 'w')
 
229
        f.write(header)
 
230
        f.write('MODULES = %s\n\n' % pprint.pformat(modules))
 
231
        f.write(footer)
 
232
        f.close()
 
233
 
 
234
    def run():
 
235
        version = get_newest_version()
 
236
        print '> Downloading function index for Lua %s' % version
 
237
        functions = get_lua_functions(version)
 
238
        print '> %d functions found:' % len(functions)
 
239
 
 
240
        modules = {}
 
241
        for full_function_name in functions:
 
242
            print '>> %s' % full_function_name
 
243
            m = get_function_module(full_function_name)
 
244
            modules.setdefault(m, []).append(full_function_name)
 
245
 
 
246
        regenerate(__file__, modules)
 
247
 
 
248
 
 
249
    run()