1
# -*- coding: utf-8 -*-
3
pygments.lexers._luabuiltins
4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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).
10
Do not edit the MODULES dict by hand.
12
:copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
13
:license: BSD, see LICENSE for details.
16
MODULES = {'basic': ['_G',
43
'coroutine': ['coroutine.create',
49
'debug': ['debug.debug',
111
'modules': ['module',
130
'string': ['string.byte',
144
'table': ['table.concat',
150
if __name__ == '__main__':
155
# you can't generally find out what module a function belongs to if you
156
# have only its name. Because of this, here are some callback functions
157
# that recognize if a gioven function belongs to a specific module
158
def module_callbacks():
159
def is_in_coroutine_module(name):
160
return name.startswith('coroutine.')
162
def is_in_modules_module(name):
163
if name in ['require', 'module'] or name.startswith('package'):
168
def is_in_string_module(name):
169
return name.startswith('string.')
171
def is_in_table_module(name):
172
return name.startswith('table.')
174
def is_in_math_module(name):
175
return name.startswith('math')
177
def is_in_io_module(name):
178
return name.startswith('io.') or name.startswith('file:')
180
def is_in_os_module(name):
181
return name.startswith('os.')
183
def is_in_debug_module(name):
184
return name.startswith('debug.')
186
return {'coroutine': is_in_coroutine_module,
187
'modules': is_in_modules_module,
188
'string': is_in_string_module,
189
'table': is_in_table_module,
190
'math': is_in_math_module,
191
'io': is_in_io_module,
192
'os': is_in_os_module,
193
'debug': is_in_debug_module}
197
def get_newest_version():
198
f = urllib.urlopen('http://www.lua.org/manual/')
199
r = re.compile(r'^<A HREF="(\d\.\d)/">Lua \1</A>')
205
def get_lua_functions(version):
206
f = urllib.urlopen('http://www.lua.org/manual/%s/' % version)
207
r = re.compile(r'^<A HREF="manual.html#pdf-(.+)">\1</A>')
212
functions.append(m.groups()[0])
215
def get_function_module(name):
216
for mod, cb in module_callbacks().iteritems():
220
return name.split('.')[0]
224
def regenerate(filename, modules):
231
header = content[:content.find('MODULES = {')]
232
footer = content[content.find("if __name__ == '__main__':"):]
235
f = open(filename, 'w')
237
f.write('MODULES = %s\n\n' % pprint.pformat(modules))
242
version = get_newest_version()
243
print '> Downloading function index for Lua %s' % version
244
functions = get_lua_functions(version)
245
print '> %d functions found:' % len(functions)
248
for full_function_name in functions:
249
print '>> %s' % full_function_name
250
m = get_function_module(full_function_name)
251
modules.setdefault(m, []).append(full_function_name)
253
regenerate(__file__, modules)