2013-09-22 20:39:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2014-12-01 06:10:30 +00:00
|
|
|
pygments.lexers._lua_builtins
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
This file contains the names and modules of lua functions
|
|
|
|
It is able to re-generate itself, but for adding new functions you
|
|
|
|
probably have to add some callbacks (see function module_callbacks).
|
|
|
|
|
|
|
|
Do not edit the MODULES dict by hand.
|
|
|
|
|
2017-02-14 07:25:51 +00:00
|
|
|
:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
|
2013-09-22 20:39:16 +00:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
MODULES = {'basic': ('_G',
|
2013-09-22 20:39:16 +00:00
|
|
|
'_VERSION',
|
|
|
|
'assert',
|
|
|
|
'collectgarbage',
|
|
|
|
'dofile',
|
|
|
|
'error',
|
|
|
|
'getmetatable',
|
|
|
|
'ipairs',
|
|
|
|
'load',
|
|
|
|
'loadfile',
|
|
|
|
'next',
|
|
|
|
'pairs',
|
|
|
|
'pcall',
|
|
|
|
'print',
|
|
|
|
'rawequal',
|
|
|
|
'rawget',
|
2017-02-14 07:25:51 +00:00
|
|
|
'rawlen',
|
2013-09-22 20:39:16 +00:00
|
|
|
'rawset',
|
|
|
|
'select',
|
|
|
|
'setmetatable',
|
|
|
|
'tonumber',
|
|
|
|
'tostring',
|
|
|
|
'type',
|
2014-12-01 06:10:30 +00:00
|
|
|
'xpcall'),
|
2017-02-14 07:25:51 +00:00
|
|
|
'bit32': ('bit32.arshift',
|
|
|
|
'bit32.band',
|
|
|
|
'bit32.bnot',
|
|
|
|
'bit32.bor',
|
|
|
|
'bit32.btest',
|
|
|
|
'bit32.bxor',
|
|
|
|
'bit32.extract',
|
|
|
|
'bit32.lrotate',
|
|
|
|
'bit32.lshift',
|
|
|
|
'bit32.replace',
|
|
|
|
'bit32.rrotate',
|
|
|
|
'bit32.rshift'),
|
2014-12-01 06:10:30 +00:00
|
|
|
'coroutine': ('coroutine.create',
|
2017-02-14 07:25:51 +00:00
|
|
|
'coroutine.isyieldable',
|
2013-09-22 20:39:16 +00:00
|
|
|
'coroutine.resume',
|
|
|
|
'coroutine.running',
|
|
|
|
'coroutine.status',
|
|
|
|
'coroutine.wrap',
|
2014-12-01 06:10:30 +00:00
|
|
|
'coroutine.yield'),
|
|
|
|
'debug': ('debug.debug',
|
2013-09-22 20:39:16 +00:00
|
|
|
'debug.gethook',
|
|
|
|
'debug.getinfo',
|
|
|
|
'debug.getlocal',
|
|
|
|
'debug.getmetatable',
|
|
|
|
'debug.getregistry',
|
|
|
|
'debug.getupvalue',
|
2017-02-14 07:25:51 +00:00
|
|
|
'debug.getuservalue',
|
2013-09-22 20:39:16 +00:00
|
|
|
'debug.sethook',
|
|
|
|
'debug.setlocal',
|
|
|
|
'debug.setmetatable',
|
|
|
|
'debug.setupvalue',
|
2017-02-14 07:25:51 +00:00
|
|
|
'debug.setuservalue',
|
|
|
|
'debug.traceback',
|
|
|
|
'debug.upvalueid',
|
|
|
|
'debug.upvaluejoin'),
|
2014-12-01 06:10:30 +00:00
|
|
|
'io': ('io.close',
|
2013-09-22 20:39:16 +00:00
|
|
|
'io.flush',
|
|
|
|
'io.input',
|
|
|
|
'io.lines',
|
|
|
|
'io.open',
|
|
|
|
'io.output',
|
|
|
|
'io.popen',
|
|
|
|
'io.read',
|
2017-02-14 07:25:51 +00:00
|
|
|
'io.stderr',
|
|
|
|
'io.stdin',
|
|
|
|
'io.stdout',
|
2013-09-22 20:39:16 +00:00
|
|
|
'io.tmpfile',
|
|
|
|
'io.type',
|
2014-12-01 06:10:30 +00:00
|
|
|
'io.write'),
|
|
|
|
'math': ('math.abs',
|
2013-09-22 20:39:16 +00:00
|
|
|
'math.acos',
|
|
|
|
'math.asin',
|
|
|
|
'math.atan',
|
2017-02-14 07:25:51 +00:00
|
|
|
'math.atan2',
|
2013-09-22 20:39:16 +00:00
|
|
|
'math.ceil',
|
|
|
|
'math.cos',
|
2017-02-14 07:25:51 +00:00
|
|
|
'math.cosh',
|
2013-09-22 20:39:16 +00:00
|
|
|
'math.deg',
|
|
|
|
'math.exp',
|
|
|
|
'math.floor',
|
|
|
|
'math.fmod',
|
|
|
|
'math.frexp',
|
|
|
|
'math.huge',
|
|
|
|
'math.ldexp',
|
|
|
|
'math.log',
|
|
|
|
'math.max',
|
2017-02-14 07:25:51 +00:00
|
|
|
'math.maxinteger',
|
2013-09-22 20:39:16 +00:00
|
|
|
'math.min',
|
2017-02-14 07:25:51 +00:00
|
|
|
'math.mininteger',
|
2013-09-22 20:39:16 +00:00
|
|
|
'math.modf',
|
|
|
|
'math.pi',
|
|
|
|
'math.pow',
|
|
|
|
'math.rad',
|
|
|
|
'math.random',
|
|
|
|
'math.randomseed',
|
|
|
|
'math.sin',
|
2017-02-14 07:25:51 +00:00
|
|
|
'math.sinh',
|
2013-09-22 20:39:16 +00:00
|
|
|
'math.sqrt',
|
2017-02-14 07:25:51 +00:00
|
|
|
'math.tan',
|
2013-09-22 20:39:16 +00:00
|
|
|
'math.tanh',
|
2017-02-14 07:25:51 +00:00
|
|
|
'math.tointeger',
|
|
|
|
'math.type',
|
|
|
|
'math.ult'),
|
|
|
|
'modules': ('package.config',
|
2013-09-22 20:39:16 +00:00
|
|
|
'package.cpath',
|
|
|
|
'package.loaded',
|
|
|
|
'package.loadlib',
|
|
|
|
'package.path',
|
|
|
|
'package.preload',
|
2017-02-14 07:25:51 +00:00
|
|
|
'package.searchers',
|
|
|
|
'package.searchpath',
|
|
|
|
'require'),
|
2014-12-01 06:10:30 +00:00
|
|
|
'os': ('os.clock',
|
2013-09-22 20:39:16 +00:00
|
|
|
'os.date',
|
|
|
|
'os.difftime',
|
|
|
|
'os.execute',
|
|
|
|
'os.exit',
|
|
|
|
'os.getenv',
|
|
|
|
'os.remove',
|
|
|
|
'os.rename',
|
|
|
|
'os.setlocale',
|
|
|
|
'os.time',
|
2014-12-01 06:10:30 +00:00
|
|
|
'os.tmpname'),
|
|
|
|
'string': ('string.byte',
|
2013-09-22 20:39:16 +00:00
|
|
|
'string.char',
|
|
|
|
'string.dump',
|
|
|
|
'string.find',
|
|
|
|
'string.format',
|
|
|
|
'string.gmatch',
|
|
|
|
'string.gsub',
|
|
|
|
'string.len',
|
|
|
|
'string.lower',
|
|
|
|
'string.match',
|
2017-02-14 07:25:51 +00:00
|
|
|
'string.pack',
|
|
|
|
'string.packsize',
|
2013-09-22 20:39:16 +00:00
|
|
|
'string.rep',
|
|
|
|
'string.reverse',
|
|
|
|
'string.sub',
|
2017-02-14 07:25:51 +00:00
|
|
|
'string.unpack',
|
2014-12-01 06:10:30 +00:00
|
|
|
'string.upper'),
|
|
|
|
'table': ('table.concat',
|
2013-09-22 20:39:16 +00:00
|
|
|
'table.insert',
|
2017-02-14 07:25:51 +00:00
|
|
|
'table.move',
|
|
|
|
'table.pack',
|
2013-09-22 20:39:16 +00:00
|
|
|
'table.remove',
|
2017-02-14 07:25:51 +00:00
|
|
|
'table.sort',
|
|
|
|
'table.unpack'),
|
|
|
|
'utf8': ('utf8.char',
|
|
|
|
'utf8.charpattern',
|
|
|
|
'utf8.codepoint',
|
|
|
|
'utf8.codes',
|
|
|
|
'utf8.len',
|
|
|
|
'utf8.offset')}
|
2016-06-13 14:41:17 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__': # pragma: no cover
|
2013-09-22 20:39:16 +00:00
|
|
|
import re
|
2017-02-14 07:25:51 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
# urllib ends up wanting to import a module called 'math' -- if
|
|
|
|
# pygments/lexers is in the path, this ends badly.
|
|
|
|
for i in range(len(sys.path)-1, -1, -1):
|
|
|
|
if sys.path[i].endswith('/lexers'):
|
|
|
|
del sys.path[i]
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
try:
|
|
|
|
from urllib import urlopen
|
|
|
|
except ImportError:
|
|
|
|
from urllib.request import urlopen
|
2013-09-22 20:39:16 +00:00
|
|
|
import pprint
|
|
|
|
|
|
|
|
# you can't generally find out what module a function belongs to if you
|
|
|
|
# have only its name. Because of this, here are some callback functions
|
|
|
|
# that recognize if a gioven function belongs to a specific module
|
|
|
|
def module_callbacks():
|
|
|
|
def is_in_coroutine_module(name):
|
|
|
|
return name.startswith('coroutine.')
|
|
|
|
|
|
|
|
def is_in_modules_module(name):
|
|
|
|
if name in ['require', 'module'] or name.startswith('package'):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def is_in_string_module(name):
|
|
|
|
return name.startswith('string.')
|
|
|
|
|
|
|
|
def is_in_table_module(name):
|
|
|
|
return name.startswith('table.')
|
|
|
|
|
|
|
|
def is_in_math_module(name):
|
|
|
|
return name.startswith('math')
|
|
|
|
|
|
|
|
def is_in_io_module(name):
|
|
|
|
return name.startswith('io.')
|
|
|
|
|
|
|
|
def is_in_os_module(name):
|
|
|
|
return name.startswith('os.')
|
|
|
|
|
|
|
|
def is_in_debug_module(name):
|
|
|
|
return name.startswith('debug.')
|
|
|
|
|
|
|
|
return {'coroutine': is_in_coroutine_module,
|
|
|
|
'modules': is_in_modules_module,
|
|
|
|
'string': is_in_string_module,
|
|
|
|
'table': is_in_table_module,
|
|
|
|
'math': is_in_math_module,
|
|
|
|
'io': is_in_io_module,
|
|
|
|
'os': is_in_os_module,
|
|
|
|
'debug': is_in_debug_module}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_newest_version():
|
2014-12-01 06:10:30 +00:00
|
|
|
f = urlopen('http://www.lua.org/manual/')
|
2017-02-14 07:25:51 +00:00
|
|
|
r = re.compile(r'^<A HREF="(\d\.\d)/">(Lua )?\1</A>')
|
2013-09-22 20:39:16 +00:00
|
|
|
for line in f:
|
|
|
|
m = r.match(line)
|
|
|
|
if m is not None:
|
|
|
|
return m.groups()[0]
|
|
|
|
|
|
|
|
def get_lua_functions(version):
|
2014-12-01 06:10:30 +00:00
|
|
|
f = urlopen('http://www.lua.org/manual/%s/' % version)
|
2017-02-14 07:25:51 +00:00
|
|
|
r = re.compile(r'^<A HREF="manual.html#pdf-(?!lua|LUA)([^:]+)">\1</A>')
|
2013-09-22 20:39:16 +00:00
|
|
|
functions = []
|
|
|
|
for line in f:
|
|
|
|
m = r.match(line)
|
|
|
|
if m is not None:
|
|
|
|
functions.append(m.groups()[0])
|
|
|
|
return functions
|
|
|
|
|
|
|
|
def get_function_module(name):
|
2013-09-22 21:48:55 +00:00
|
|
|
for mod, cb in module_callbacks().items():
|
2013-09-22 20:39:16 +00:00
|
|
|
if cb(name):
|
|
|
|
return mod
|
|
|
|
if '.' in name:
|
|
|
|
return name.split('.')[0]
|
|
|
|
else:
|
|
|
|
return 'basic'
|
|
|
|
|
|
|
|
def regenerate(filename, modules):
|
2014-12-01 06:10:30 +00:00
|
|
|
with open(filename) as fp:
|
|
|
|
content = fp.read()
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
header = content[:content.find('MODULES = {')]
|
|
|
|
footer = content[content.find("if __name__ == '__main__':"):]
|
|
|
|
|
|
|
|
|
2014-12-01 06:10:30 +00:00
|
|
|
with open(filename, 'w') as fp:
|
|
|
|
fp.write(header)
|
|
|
|
fp.write('MODULES = %s\n\n' % pprint.pformat(modules))
|
|
|
|
fp.write(footer)
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
def run():
|
|
|
|
version = get_newest_version()
|
2017-02-14 07:25:51 +00:00
|
|
|
functions = set()
|
|
|
|
for v in ('5.2', version):
|
|
|
|
print('> Downloading function index for Lua %s' % v)
|
|
|
|
f = get_lua_functions(v)
|
|
|
|
print('> %d functions found, %d new:' %
|
|
|
|
(len(f), len(set(f) - functions)))
|
|
|
|
functions |= set(f)
|
|
|
|
|
|
|
|
functions = sorted(functions)
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
modules = {}
|
|
|
|
for full_function_name in functions:
|
2013-09-22 21:29:16 +00:00
|
|
|
print('>> %s' % full_function_name)
|
2013-09-22 20:39:16 +00:00
|
|
|
m = get_function_module(full_function_name)
|
|
|
|
modules.setdefault(m, []).append(full_function_name)
|
2017-02-14 07:25:51 +00:00
|
|
|
modules = {k: tuple(v) for k, v in modules.iteritems()}
|
2013-09-22 20:39:16 +00:00
|
|
|
|
|
|
|
regenerate(__file__, modules)
|
|
|
|
|
|
|
|
run()
|