ThirdParty/Pygments/pygments/lexers/_luabuiltins.py

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

eric ide

mercurial