7 It is able to re-generate itself, but for adding new functions you |
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). |
8 probably have to add some callbacks (see function module_callbacks). |
9 |
9 |
10 Do not edit the MODULES dict by hand. |
10 Do not edit the MODULES dict by hand. |
11 |
11 |
12 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
12 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
13 :license: BSD, see LICENSE for details. |
13 :license: BSD, see LICENSE for details. |
14 """ |
14 """ |
15 |
15 |
16 from __future__ import print_function |
16 from __future__ import print_function |
17 |
|
18 |
17 |
19 MODULES = {'basic': ('_G', |
18 MODULES = {'basic': ('_G', |
20 '_VERSION', |
19 '_VERSION', |
21 'assert', |
20 'assert', |
22 'collectgarbage', |
21 'collectgarbage', |
23 'dofile', |
22 'dofile', |
24 'error', |
23 'error', |
25 'getfenv', |
|
26 'getmetatable', |
24 'getmetatable', |
27 'ipairs', |
25 'ipairs', |
28 'load', |
26 'load', |
29 'loadfile', |
27 'loadfile', |
30 'loadstring', |
|
31 'next', |
28 'next', |
32 'pairs', |
29 'pairs', |
33 'pcall', |
30 'pcall', |
34 'print', |
31 'print', |
35 'rawequal', |
32 'rawequal', |
36 'rawget', |
33 'rawget', |
|
34 'rawlen', |
37 'rawset', |
35 'rawset', |
38 'select', |
36 'select', |
39 'setfenv', |
|
40 'setmetatable', |
37 'setmetatable', |
41 'tonumber', |
38 'tonumber', |
42 'tostring', |
39 'tostring', |
43 'type', |
40 'type', |
44 'unpack', |
|
45 'xpcall'), |
41 'xpcall'), |
|
42 'bit32': ('bit32.arshift', |
|
43 'bit32.band', |
|
44 'bit32.bnot', |
|
45 'bit32.bor', |
|
46 'bit32.btest', |
|
47 'bit32.bxor', |
|
48 'bit32.extract', |
|
49 'bit32.lrotate', |
|
50 'bit32.lshift', |
|
51 'bit32.replace', |
|
52 'bit32.rrotate', |
|
53 'bit32.rshift'), |
46 'coroutine': ('coroutine.create', |
54 'coroutine': ('coroutine.create', |
|
55 'coroutine.isyieldable', |
47 'coroutine.resume', |
56 'coroutine.resume', |
48 'coroutine.running', |
57 'coroutine.running', |
49 'coroutine.status', |
58 'coroutine.status', |
50 'coroutine.wrap', |
59 'coroutine.wrap', |
51 'coroutine.yield'), |
60 'coroutine.yield'), |
52 'debug': ('debug.debug', |
61 'debug': ('debug.debug', |
53 'debug.getfenv', |
|
54 'debug.gethook', |
62 'debug.gethook', |
55 'debug.getinfo', |
63 'debug.getinfo', |
56 'debug.getlocal', |
64 'debug.getlocal', |
57 'debug.getmetatable', |
65 'debug.getmetatable', |
58 'debug.getregistry', |
66 'debug.getregistry', |
59 'debug.getupvalue', |
67 'debug.getupvalue', |
60 'debug.setfenv', |
68 'debug.getuservalue', |
61 'debug.sethook', |
69 'debug.sethook', |
62 'debug.setlocal', |
70 'debug.setlocal', |
63 'debug.setmetatable', |
71 'debug.setmetatable', |
64 'debug.setupvalue', |
72 'debug.setupvalue', |
65 'debug.traceback'), |
73 'debug.setuservalue', |
|
74 'debug.traceback', |
|
75 'debug.upvalueid', |
|
76 'debug.upvaluejoin'), |
66 'io': ('io.close', |
77 'io': ('io.close', |
67 'io.flush', |
78 'io.flush', |
68 'io.input', |
79 'io.input', |
69 'io.lines', |
80 'io.lines', |
70 'io.open', |
81 'io.open', |
71 'io.output', |
82 'io.output', |
72 'io.popen', |
83 'io.popen', |
73 'io.read', |
84 'io.read', |
|
85 'io.stderr', |
|
86 'io.stdin', |
|
87 'io.stdout', |
74 'io.tmpfile', |
88 'io.tmpfile', |
75 'io.type', |
89 'io.type', |
76 'io.write'), |
90 'io.write'), |
77 'math': ('math.abs', |
91 'math': ('math.abs', |
78 'math.acos', |
92 'math.acos', |
79 'math.asin', |
93 'math.asin', |
|
94 'math.atan', |
80 'math.atan2', |
95 'math.atan2', |
81 'math.atan', |
|
82 'math.ceil', |
96 'math.ceil', |
|
97 'math.cos', |
83 'math.cosh', |
98 'math.cosh', |
84 'math.cos', |
|
85 'math.deg', |
99 'math.deg', |
86 'math.exp', |
100 'math.exp', |
87 'math.floor', |
101 'math.floor', |
88 'math.fmod', |
102 'math.fmod', |
89 'math.frexp', |
103 'math.frexp', |
90 'math.huge', |
104 'math.huge', |
91 'math.ldexp', |
105 'math.ldexp', |
92 'math.log10', |
|
93 'math.log', |
106 'math.log', |
94 'math.max', |
107 'math.max', |
|
108 'math.maxinteger', |
95 'math.min', |
109 'math.min', |
|
110 'math.mininteger', |
96 'math.modf', |
111 'math.modf', |
97 'math.pi', |
112 'math.pi', |
98 'math.pow', |
113 'math.pow', |
99 'math.rad', |
114 'math.rad', |
100 'math.random', |
115 'math.random', |
101 'math.randomseed', |
116 'math.randomseed', |
|
117 'math.sin', |
102 'math.sinh', |
118 'math.sinh', |
103 'math.sin', |
|
104 'math.sqrt', |
119 'math.sqrt', |
|
120 'math.tan', |
105 'math.tanh', |
121 'math.tanh', |
106 'math.tan'), |
122 'math.tointeger', |
107 'modules': ('module', |
123 'math.type', |
108 'require', |
124 'math.ult'), |
|
125 'modules': ('package.config', |
109 'package.cpath', |
126 'package.cpath', |
110 'package.loaded', |
127 'package.loaded', |
111 'package.loadlib', |
128 'package.loadlib', |
112 'package.path', |
129 'package.path', |
113 'package.preload', |
130 'package.preload', |
114 'package.seeall'), |
131 'package.searchers', |
|
132 'package.searchpath', |
|
133 'require'), |
115 'os': ('os.clock', |
134 'os': ('os.clock', |
116 'os.date', |
135 'os.date', |
117 'os.difftime', |
136 'os.difftime', |
118 'os.execute', |
137 'os.execute', |
119 'os.exit', |
138 'os.exit', |
131 'string.gmatch', |
150 'string.gmatch', |
132 'string.gsub', |
151 'string.gsub', |
133 'string.len', |
152 'string.len', |
134 'string.lower', |
153 'string.lower', |
135 'string.match', |
154 'string.match', |
|
155 'string.pack', |
|
156 'string.packsize', |
136 'string.rep', |
157 'string.rep', |
137 'string.reverse', |
158 'string.reverse', |
138 'string.sub', |
159 'string.sub', |
|
160 'string.unpack', |
139 'string.upper'), |
161 'string.upper'), |
140 'table': ('table.concat', |
162 'table': ('table.concat', |
141 'table.insert', |
163 'table.insert', |
142 'table.maxn', |
164 'table.move', |
|
165 'table.pack', |
143 'table.remove', |
166 'table.remove', |
144 'table.sort')} |
167 'table.sort', |
145 |
168 'table.unpack'), |
|
169 'utf8': ('utf8.char', |
|
170 'utf8.charpattern', |
|
171 'utf8.codepoint', |
|
172 'utf8.codes', |
|
173 'utf8.len', |
|
174 'utf8.offset')} |
146 |
175 |
147 if __name__ == '__main__': # pragma: no cover |
176 if __name__ == '__main__': # pragma: no cover |
148 import re |
177 import re |
|
178 import sys |
|
179 |
|
180 # urllib ends up wanting to import a module called 'math' -- if |
|
181 # pygments/lexers is in the path, this ends badly. |
|
182 for i in range(len(sys.path)-1, -1, -1): |
|
183 if sys.path[i].endswith('/lexers'): |
|
184 del sys.path[i] |
|
185 |
149 try: |
186 try: |
150 from urllib import urlopen |
187 from urllib import urlopen |
151 except ImportError: |
188 except ImportError: |
152 from urllib.request import urlopen |
189 from urllib.request import urlopen |
153 import pprint |
190 import pprint |
194 |
231 |
195 |
232 |
196 |
233 |
197 def get_newest_version(): |
234 def get_newest_version(): |
198 f = urlopen('http://www.lua.org/manual/') |
235 f = urlopen('http://www.lua.org/manual/') |
199 r = re.compile(r'^<A HREF="(\d\.\d)/">Lua \1</A>') |
236 r = re.compile(r'^<A HREF="(\d\.\d)/">(Lua )?\1</A>') |
200 for line in f: |
237 for line in f: |
201 m = r.match(line) |
238 m = r.match(line) |
202 if m is not None: |
239 if m is not None: |
203 return m.groups()[0] |
240 return m.groups()[0] |
204 |
241 |
205 def get_lua_functions(version): |
242 def get_lua_functions(version): |
206 f = urlopen('http://www.lua.org/manual/%s/' % version) |
243 f = urlopen('http://www.lua.org/manual/%s/' % version) |
207 r = re.compile(r'^<A HREF="manual.html#pdf-(.+)">\1</A>') |
244 r = re.compile(r'^<A HREF="manual.html#pdf-(?!lua|LUA)([^:]+)">\1</A>') |
208 functions = [] |
245 functions = [] |
209 for line in f: |
246 for line in f: |
210 m = r.match(line) |
247 m = r.match(line) |
211 if m is not None: |
248 if m is not None: |
212 functions.append(m.groups()[0]) |
249 functions.append(m.groups()[0]) |
234 fp.write('MODULES = %s\n\n' % pprint.pformat(modules)) |
271 fp.write('MODULES = %s\n\n' % pprint.pformat(modules)) |
235 fp.write(footer) |
272 fp.write(footer) |
236 |
273 |
237 def run(): |
274 def run(): |
238 version = get_newest_version() |
275 version = get_newest_version() |
239 print('> Downloading function index for Lua %s' % version) |
276 functions = set() |
240 functions = get_lua_functions(version) |
277 for v in ('5.2', version): |
241 print('> %d functions found:' % len(functions)) |
278 print('> Downloading function index for Lua %s' % v) |
|
279 f = get_lua_functions(v) |
|
280 print('> %d functions found, %d new:' % |
|
281 (len(f), len(set(f) - functions))) |
|
282 functions |= set(f) |
|
283 |
|
284 functions = sorted(functions) |
242 |
285 |
243 modules = {} |
286 modules = {} |
244 for full_function_name in functions: |
287 for full_function_name in functions: |
245 print('>> %s' % full_function_name) |
288 print('>> %s' % full_function_name) |
246 m = get_function_module(full_function_name) |
289 m = get_function_module(full_function_name) |
247 modules.setdefault(m, []).append(full_function_name) |
290 modules.setdefault(m, []).append(full_function_name) |
|
291 modules = {k: tuple(v) for k, v in modules.iteritems()} |
248 |
292 |
249 regenerate(__file__, modules) |
293 regenerate(__file__, modules) |
250 |
294 |
251 run() |
295 run() |