ThirdParty/Pygments/pygments/lexers/_luabuiltins.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers._luabuiltins
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-2009 by the Pygments team, see AUTHORS.
13 :license: BSD, see LICENSE for details.
14 """
15
16 MODULES = {'basic': ['_G',
17 '_VERSION',
18 'assert',
19 'collectgarbage',
20 'dofile',
21 'error',
22 'getfenv',
23 'getmetatable',
24 'ipairs',
25 'load',
26 'loadfile',
27 'loadstring',
28 'next',
29 'pairs',
30 'pcall',
31 'print',
32 'rawequal',
33 'rawget',
34 'rawset',
35 'select',
36 'setfenv',
37 'setmetatable',
38 'tonumber',
39 'tostring',
40 'type',
41 'unpack',
42 'xpcall'],
43 'coroutine': ['coroutine.create',
44 'coroutine.resume',
45 'coroutine.running',
46 'coroutine.status',
47 'coroutine.wrap',
48 'coroutine.yield'],
49 'debug': ['debug.debug',
50 'debug.getfenv',
51 'debug.gethook',
52 'debug.getinfo',
53 'debug.getlocal',
54 'debug.getmetatable',
55 'debug.getregistry',
56 'debug.getupvalue',
57 'debug.setfenv',
58 'debug.sethook',
59 'debug.setlocal',
60 'debug.setmetatable',
61 'debug.setupvalue',
62 'debug.traceback'],
63 'io': ['file:close',
64 'file:flush',
65 'file:lines',
66 'file:read',
67 'file:seek',
68 'file:setvbuf',
69 'file:write',
70 'io.close',
71 'io.flush',
72 'io.input',
73 'io.lines',
74 'io.open',
75 'io.output',
76 'io.popen',
77 'io.read',
78 'io.tmpfile',
79 'io.type',
80 'io.write'],
81 'math': ['math.abs',
82 'math.acos',
83 'math.asin',
84 'math.atan2',
85 'math.atan',
86 'math.ceil',
87 'math.cosh',
88 'math.cos',
89 'math.deg',
90 'math.exp',
91 'math.floor',
92 'math.fmod',
93 'math.frexp',
94 'math.huge',
95 'math.ldexp',
96 'math.log10',
97 'math.log',
98 'math.max',
99 'math.min',
100 'math.modf',
101 'math.pi',
102 'math.pow',
103 'math.rad',
104 'math.random',
105 'math.randomseed',
106 'math.sinh',
107 'math.sin',
108 'math.sqrt',
109 'math.tanh',
110 'math.tan'],
111 'modules': ['module',
112 'require',
113 'package.cpath',
114 'package.loaded',
115 'package.loadlib',
116 'package.path',
117 'package.preload',
118 'package.seeall'],
119 'os': ['os.clock',
120 'os.date',
121 'os.difftime',
122 'os.execute',
123 'os.exit',
124 'os.getenv',
125 'os.remove',
126 'os.rename',
127 'os.setlocale',
128 'os.time',
129 'os.tmpname'],
130 'string': ['string.byte',
131 'string.char',
132 'string.dump',
133 'string.find',
134 'string.format',
135 'string.gmatch',
136 'string.gsub',
137 'string.len',
138 'string.lower',
139 'string.match',
140 'string.rep',
141 'string.reverse',
142 'string.sub',
143 'string.upper'],
144 'table': ['table.concat',
145 'table.insert',
146 'table.maxn',
147 'table.remove',
148 'table.sort']}
149
150 if __name__ == '__main__':
151 import re
152 import urllib
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.') or name.startswith('file:')
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 = urllib.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 = urllib.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().iteritems():
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 f = open(filename)
226 try:
227 content = f.read()
228 finally:
229 f.close()
230
231 header = content[:content.find('MODULES = {')]
232 footer = content[content.find("if __name__ == '__main__':"):]
233
234
235 f = open(filename, 'w')
236 f.write(header)
237 f.write('MODULES = %s\n\n' % pprint.pformat(modules))
238 f.write(footer)
239 f.close()
240
241 def run():
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)
246
247 modules = {}
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)
252
253 regenerate(__file__, modules)
254
255
256 run()

eric ide

mercurial