ThirdParty/Pygments/pygments/lexers/_luabuiltins.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 684
2f29a0b6e1c7
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
147 'table.remove', 147 'table.remove',
148 'table.sort']} 148 'table.sort']}
149 149
150 if __name__ == '__main__': 150 if __name__ == '__main__':
151 import re 151 import re
152 import urllib 152 import urllib.request, urllib.parse, urllib.error
153 import pprint 153 import pprint
154 154
155 # you can't generally find out what module a function belongs to if you 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 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 157 # that recognize if a gioven function belongs to a specific module
193 'debug': is_in_debug_module} 193 'debug': is_in_debug_module}
194 194
195 195
196 196
197 def get_newest_version(): 197 def get_newest_version():
198 f = urllib.urlopen('http://www.lua.org/manual/') 198 f = urllib.request.urlopen('http://www.lua.org/manual/')
199 r = re.compile(r'^<A HREF="(\d\.\d)/">Lua \1</A>') 199 r = re.compile(r'^<A HREF="(\d\.\d)/">Lua \1</A>')
200 for line in f: 200 for line in f:
201 m = r.match(line) 201 m = r.match(line)
202 if m is not None: 202 if m is not None:
203 return m.groups()[0] 203 return m.groups()[0]
204 204
205 def get_lua_functions(version): 205 def get_lua_functions(version):
206 f = urllib.urlopen('http://www.lua.org/manual/%s/' % version) 206 f = urllib.request.urlopen('http://www.lua.org/manual/%s/' % version)
207 r = re.compile(r'^<A HREF="manual.html#pdf-(.+)">\1</A>') 207 r = re.compile(r'^<A HREF="manual.html#pdf-(.+)">\1</A>')
208 functions = [] 208 functions = []
209 for line in f: 209 for line in f:
210 m = r.match(line) 210 m = r.match(line)
211 if m is not None: 211 if m is not None:
212 functions.append(m.groups()[0]) 212 functions.append(m.groups()[0])
213 return functions 213 return functions
214 214
215 def get_function_module(name): 215 def get_function_module(name):
216 for mod, cb in module_callbacks().iteritems(): 216 for mod, cb in module_callbacks().items():
217 if cb(name): 217 if cb(name):
218 return mod 218 return mod
219 if '.' in name: 219 if '.' in name:
220 return name.split('.')[0] 220 return name.split('.')[0]
221 else: 221 else:
238 f.write(footer) 238 f.write(footer)
239 f.close() 239 f.close()
240 240
241 def run(): 241 def run():
242 version = get_newest_version() 242 version = get_newest_version()
243 print '> Downloading function index for Lua %s' % version 243 print('> Downloading function index for Lua %s' % version)
244 functions = get_lua_functions(version) 244 functions = get_lua_functions(version)
245 print '> %d functions found:' % len(functions) 245 print('> %d functions found:' % len(functions))
246 246
247 modules = {} 247 modules = {}
248 for full_function_name in functions: 248 for full_function_name in functions:
249 print '>> %s' % full_function_name 249 print('>> %s' % full_function_name)
250 m = get_function_module(full_function_name) 250 m = get_function_module(full_function_name)
251 modules.setdefault(m, []).append(full_function_name) 251 modules.setdefault(m, []).append(full_function_name)
252 252
253 regenerate(__file__, modules) 253 regenerate(__file__, modules)
254 254

eric ide

mercurial