ThirdParty/Pygments/pygments/lexers/_lua_builtins.py

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

eric ide

mercurial