Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/_lua_builtins.py: 100%

1 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-01 06:54 +0000

1""" 

2 pygments.lexers._lua_builtins 

3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 This file contains the names and modules of lua functions 

6 It is able to re-generate itself, but for adding new functions you 

7 probably have to add some callbacks (see function module_callbacks). 

8 

9 Do not edit the MODULES dict by hand. 

10 

11 Run with `python -I` to regenerate. 

12 

13 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

14 :license: BSD, see LICENSE for details. 

15""" 

16 

17MODULES = {'basic': ('_G', 

18 '_VERSION', 

19 'assert', 

20 'collectgarbage', 

21 'dofile', 

22 'error', 

23 'getmetatable', 

24 'ipairs', 

25 'load', 

26 'loadfile', 

27 'next', 

28 'pairs', 

29 'pcall', 

30 'print', 

31 'rawequal', 

32 'rawget', 

33 'rawlen', 

34 'rawset', 

35 'select', 

36 'setmetatable', 

37 'tonumber', 

38 'tostring', 

39 'type', 

40 'warn', 

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'), 

54 'coroutine': ('coroutine.close', 

55 'coroutine.create', 

56 'coroutine.isyieldable', 

57 'coroutine.resume', 

58 'coroutine.running', 

59 'coroutine.status', 

60 'coroutine.wrap', 

61 'coroutine.yield'), 

62 'debug': ('debug.debug', 

63 'debug.gethook', 

64 'debug.getinfo', 

65 'debug.getlocal', 

66 'debug.getmetatable', 

67 'debug.getregistry', 

68 'debug.getupvalue', 

69 'debug.getuservalue', 

70 'debug.sethook', 

71 'debug.setlocal', 

72 'debug.setmetatable', 

73 'debug.setupvalue', 

74 'debug.setuservalue', 

75 'debug.traceback', 

76 'debug.upvalueid', 

77 'debug.upvaluejoin'), 

78 'io': ('io.close', 

79 'io.flush', 

80 'io.input', 

81 'io.lines', 

82 'io.open', 

83 'io.output', 

84 'io.popen', 

85 'io.read', 

86 'io.stderr', 

87 'io.stdin', 

88 'io.stdout', 

89 'io.tmpfile', 

90 'io.type', 

91 'io.write'), 

92 'math': ('math.abs', 

93 'math.acos', 

94 'math.asin', 

95 'math.atan', 

96 'math.atan2', 

97 'math.ceil', 

98 'math.cos', 

99 'math.cosh', 

100 'math.deg', 

101 'math.exp', 

102 'math.floor', 

103 'math.fmod', 

104 'math.frexp', 

105 'math.huge', 

106 'math.ldexp', 

107 'math.log', 

108 'math.max', 

109 'math.maxinteger', 

110 'math.min', 

111 'math.mininteger', 

112 'math.modf', 

113 'math.pi', 

114 'math.pow', 

115 'math.rad', 

116 'math.random', 

117 'math.randomseed', 

118 'math.sin', 

119 'math.sinh', 

120 'math.sqrt', 

121 'math.tan', 

122 'math.tanh', 

123 'math.tointeger', 

124 'math.type', 

125 'math.ult'), 

126 'modules': ('package.config', 

127 'package.cpath', 

128 'package.loaded', 

129 'package.loadlib', 

130 'package.path', 

131 'package.preload', 

132 'package.searchers', 

133 'package.searchpath', 

134 'require'), 

135 'os': ('os.clock', 

136 'os.date', 

137 'os.difftime', 

138 'os.execute', 

139 'os.exit', 

140 'os.getenv', 

141 'os.remove', 

142 'os.rename', 

143 'os.setlocale', 

144 'os.time', 

145 'os.tmpname'), 

146 'string': ('string.byte', 

147 'string.char', 

148 'string.dump', 

149 'string.find', 

150 'string.format', 

151 'string.gmatch', 

152 'string.gsub', 

153 'string.len', 

154 'string.lower', 

155 'string.match', 

156 'string.pack', 

157 'string.packsize', 

158 'string.rep', 

159 'string.reverse', 

160 'string.sub', 

161 'string.unpack', 

162 'string.upper'), 

163 'table': ('table.concat', 

164 'table.insert', 

165 'table.move', 

166 'table.pack', 

167 'table.remove', 

168 'table.sort', 

169 'table.unpack'), 

170 'utf8': ('utf8.char', 

171 'utf8.charpattern', 

172 'utf8.codepoint', 

173 'utf8.codes', 

174 'utf8.len', 

175 'utf8.offset')} 

176 

177if __name__ == '__main__': # pragma: no cover 

178 import re 

179 from urllib.request import urlopen 

180 import pprint 

181 

182 # you can't generally find out what module a function belongs to if you 

183 # have only its name. Because of this, here are some callback functions 

184 # that recognize if a gioven function belongs to a specific module 

185 def module_callbacks(): 

186 def is_in_coroutine_module(name): 

187 return name.startswith('coroutine.') 

188 

189 def is_in_modules_module(name): 

190 if name in ['require', 'module'] or name.startswith('package'): 

191 return True 

192 else: 

193 return False 

194 

195 def is_in_string_module(name): 

196 return name.startswith('string.') 

197 

198 def is_in_table_module(name): 

199 return name.startswith('table.') 

200 

201 def is_in_math_module(name): 

202 return name.startswith('math') 

203 

204 def is_in_io_module(name): 

205 return name.startswith('io.') 

206 

207 def is_in_os_module(name): 

208 return name.startswith('os.') 

209 

210 def is_in_debug_module(name): 

211 return name.startswith('debug.') 

212 

213 return {'coroutine': is_in_coroutine_module, 

214 'modules': is_in_modules_module, 

215 'string': is_in_string_module, 

216 'table': is_in_table_module, 

217 'math': is_in_math_module, 

218 'io': is_in_io_module, 

219 'os': is_in_os_module, 

220 'debug': is_in_debug_module} 

221 

222 

223 

224 def get_newest_version(): 

225 f = urlopen('http://www.lua.org/manual/') 

226 r = re.compile(r'^<A HREF="(\d\.\d)/">(Lua )?\1</A>') 

227 for line in f: 

228 m = r.match(line.decode('iso-8859-1')) 

229 if m is not None: 

230 return m.groups()[0] 

231 

232 def get_lua_functions(version): 

233 f = urlopen('http://www.lua.org/manual/%s/' % version) 

234 r = re.compile(r'^<A HREF="manual.html#pdf-(?!lua|LUA)([^:]+)">\1</A>') 

235 functions = [] 

236 for line in f: 

237 m = r.match(line.decode('iso-8859-1')) 

238 if m is not None: 

239 functions.append(m.groups()[0]) 

240 return functions 

241 

242 def get_function_module(name): 

243 for mod, cb in module_callbacks().items(): 

244 if cb(name): 

245 return mod 

246 if '.' in name: 

247 return name.split('.')[0] 

248 else: 

249 return 'basic' 

250 

251 def regenerate(filename, modules): 

252 with open(filename, encoding='utf-8') as fp: 

253 content = fp.read() 

254 

255 header = content[:content.find('MODULES = {')] 

256 footer = content[content.find("if __name__ == '__main__':"):] 

257 

258 

259 with open(filename, 'w', encoding='utf-8') as fp: 

260 fp.write(header) 

261 fp.write('MODULES = %s\n\n' % pprint.pformat(modules)) 

262 fp.write(footer) 

263 

264 def run(): 

265 version = get_newest_version() 

266 functions = set() 

267 for v in ('5.2', version): 

268 print('> Downloading function index for Lua %s' % v) 

269 f = get_lua_functions(v) 

270 print('> %d functions found, %d new:' % 

271 (len(f), len(set(f) - functions))) 

272 functions |= set(f) 

273 

274 functions = sorted(functions) 

275 

276 modules = {} 

277 for full_function_name in functions: 

278 print('>> %s' % full_function_name) 

279 m = get_function_module(full_function_name) 

280 modules.setdefault(m, []).append(full_function_name) 

281 modules = {k: tuple(v) for k, v in modules.items()} 

282 

283 regenerate(__file__, modules) 

284 

285 run()