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

38 statements  

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

1""" 

2 pygments.lexers.unicon 

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

4 

5 Lexers for the Icon and Unicon languages, including ucode VM. 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import RegexLexer, include, bygroups, words, using, this 

14from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

15 Number, Punctuation 

16 

17__all__ = ['IconLexer', 'UcodeLexer', 'UniconLexer'] 

18 

19 

20class UniconLexer(RegexLexer): 

21 """ 

22 For Unicon source code. 

23 

24 .. versionadded:: 2.4 

25 """ 

26 

27 name = 'Unicon' 

28 aliases = ['unicon'] 

29 filenames = ['*.icn'] 

30 mimetypes = ['text/unicon'] 

31 

32 flags = re.MULTILINE 

33 

34 tokens = { 

35 'root': [ 

36 (r'[^\S\n]+', Text), 

37 (r'#.*?\n', Comment.Single), 

38 (r'[^\S\n]+', Text), 

39 (r'class|method|procedure', Keyword.Declaration, 'subprogram'), 

40 (r'(record)(\s+)(\w+)', 

41 bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), 

42 (r'(#line|\$C|\$Cend|\$define|\$else|\$endif|\$error|\$ifdef|' 

43 r'\$ifndef|\$include|\$line|\$undef)\b', Keyword.PreProc), 

44 (r'(&null|&fail)\b', Keyword.Constant), 

45 (r'&allocated|&ascii|&clock|&collections|&column|&col|&control|' 

46 r'&cset|&current|&dateline|&date|&digits|&dump|' 

47 r'&errno|&errornumber|&errortext|&errorvalue|&error|&errout|' 

48 r'&eventcode|&eventvalue|&eventsource|&e|' 

49 r'&features|&file|&host|&input|&interval|&lcase|&letters|' 

50 r'&level|&line|&ldrag|&lpress|&lrelease|' 

51 r'&main|&mdrag|&meta|&mpress|&mrelease|&now|&output|' 

52 r'&phi|&pick|&pi|&pos|&progname|' 

53 r'&random|&rdrag|&regions|&resize|&row|&rpress|&rrelease|' 

54 r'&shift|&source|&storage|&subject|' 

55 r'&time|&trace|&ucase|&version|' 

56 r'&window|&x|&y', Keyword.Reserved), 

57 (r'(by|of|not|to)\b', Keyword.Reserved), 

58 (r'(global|local|static|abstract)\b', Keyword.Reserved), 

59 (r'package|link|import', Keyword.Declaration), 

60 (words(( 

61 'break', 'case', 'create', 'critical', 'default', 'end', 'all', 

62 'do', 'else', 'every', 'fail', 'if', 'import', 'initial', 

63 'initially', 'invocable', 'next', 

64 'repeat', 'return', 'suspend', 

65 'then', 'thread', 'until', 'while'), prefix=r'\b', suffix=r'\b'), 

66 Keyword.Reserved), 

67 (words(( 

68 'Abort', 'abs', 'acos', 'Active', 'Alert', 'any', 'Any', 'Arb', 

69 'Arbno', 'args', 'array', 'asin', 'atan', 'atanh', 'Attrib', 

70 'Bal', 'bal', 'Bg', 'Break', 'Breakx', 

71 'callout', 'center', 'char', 'chdir', 'chmod', 'chown', 'chroot', 

72 'classname', 'Clip', 'Clone', 'close', 'cofail', 'collect', 

73 'Color', 'ColorValue', 'condvar', 'constructor', 'copy', 

74 'CopyArea', 'cos', 'Couple', 'crypt', 'cset', 'ctime', 

75 'dbcolumns', 'dbdriver', 'dbkeys', 'dblimits', 'dbproduct', 

76 'dbtables', 'delay', 'delete', 'detab', 'display', 'DrawArc', 

77 'DrawCircle', 'DrawCube', 'DrawCurve', 'DrawCylinder', 

78 'DrawDisk', 'DrawImage', 'DrawLine', 'DrawPoint', 'DrawPolygon', 

79 'DrawRectangle', 'DrawSegment', 'DrawSphere', 'DrawString', 

80 'DrawTorus', 'dtor', 

81 'entab', 'EraseArea', 'errorclear', 'Event', 'eventmask', 

82 'EvGet', 'EvSend', 'exec', 'exit', 'exp', 'Eye', 

83 'Fail', 'fcntl', 'fdup', 'Fence', 'fetch', 'Fg', 'fieldnames', 

84 'filepair', 'FillArc', 'FillCircle', 'FillPolygon', 

85 'FillRectangle', 'find', 'flock', 'flush', 'Font', 'fork', 

86 'FreeColor', 'FreeSpace', 'function', 

87 'get', 'getch', 'getche', 'getegid', 'getenv', 'geteuid', 

88 'getgid', 'getgr', 'gethost', 'getpgrp', 'getpid', 'getppid', 

89 'getpw', 'getrusage', 'getserv', 'GetSpace', 'gettimeofday', 

90 'getuid', 'globalnames', 'GotoRC', 'GotoXY', 'gtime', 'hardlink', 

91 'iand', 'icom', 'IdentityMatrix', 'image', 'InPort', 'insert', 

92 'Int86', 'integer', 'ioctl', 'ior', 'ishift', 'istate', 'ixor', 

93 'kbhit', 'key', 'keyword', 'kill', 

94 'left', 'Len', 'list', 'load', 'loadfunc', 'localnames', 

95 'lock', 'log', 'Lower', 'lstat', 

96 'many', 'map', 'match', 'MatrixMode', 'max', 'member', 

97 'membernames', 'methodnames', 'methods', 'min', 'mkdir', 'move', 

98 'MultMatrix', 'mutex', 

99 'name', 'NewColor', 'Normals', 'NotAny', 'numeric', 

100 'open', 'opencl', 'oprec', 'ord', 'OutPort', 

101 'PaletteChars', 'PaletteColor', 'PaletteKey', 'paramnames', 

102 'parent', 'Pattern', 'Peek', 'Pending', 'pipe', 'Pixel', 

103 'PlayAudio', 'Poke', 'pop', 'PopMatrix', 'Pos', 'pos', 

104 'proc', 'pull', 'push', 'PushMatrix', 'PushRotate', 'PushScale', 

105 'PushTranslate', 'put', 

106 'QueryPointer', 

107 'Raise', 'read', 'ReadImage', 'readlink', 'reads', 'ready', 

108 'real', 'receive', 'Refresh', 'Rem', 'remove', 'rename', 

109 'repl', 'reverse', 'right', 'rmdir', 'Rotate', 'Rpos', 

110 'Rtab', 'rtod', 'runerr', 

111 'save', 'Scale', 'seek', 'select', 'send', 'seq', 

112 'serial', 'set', 'setenv', 'setgid', 'setgrent', 

113 'sethostent', 'setpgrp', 'setpwent', 'setservent', 

114 'setuid', 'signal', 'sin', 'sort', 'sortf', 'Span', 

115 'spawn', 'sql', 'sqrt', 'stat', 'staticnames', 'stop', 

116 'StopAudio', 'string', 'structure', 'Succeed', 'Swi', 

117 'symlink', 'sys_errstr', 'system', 'syswrite', 

118 'Tab', 'tab', 'table', 'tan', 

119 'Texcoord', 'Texture', 'TextWidth', 'Translate', 

120 'trap', 'trim', 'truncate', 'trylock', 'type', 

121 'umask', 'Uncouple', 'unlock', 'upto', 'utime', 

122 'variable', 'VAttrib', 

123 'wait', 'WAttrib', 'WDefault', 'WFlush', 'where', 

124 'WinAssociate', 'WinButton', 'WinColorDialog', 'WindowContents', 

125 'WinEditRegion', 'WinFontDialog', 'WinMenuBar', 'WinOpenDialog', 

126 'WinPlayMedia', 'WinSaveDialog', 'WinScrollBar', 'WinSelectDialog', 

127 'write', 'WriteImage', 'writes', 'WSection', 

128 'WSync'), prefix=r'\b', suffix=r'\b'), 

129 Name.Function), 

130 include('numbers'), 

131 (r'<@|<<@|>@|>>@|\.>|->|===|~===|\*\*|\+\+|--|\.|~==|~=|<=|>=|==|' 

132 r'=|<<=|<<|>>=|>>|:=:|:=|->|<->|\+:=|\|', Operator), 

133 (r'"(?:[^\\"]|\\.)*"', String), 

134 (r"'(?:[^\\']|\\.)*'", String.Character), 

135 (r'[*<>+=/&!?@~\\-]', Operator), 

136 (r'\^', Operator), 

137 (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), 

138 (r"[\[\]]", Punctuation), 

139 (r"<>|=>|[()|:;,.'`{}%&?]", Punctuation), 

140 (r'\n+', Text), 

141 ], 

142 'numbers': [ 

143 (r'\b([+-]?([2-9]|[12][0-9]|3[0-6])[rR][0-9a-zA-Z]+)\b', Number.Hex), 

144 (r'[+-]?[0-9]*\.([0-9]*)([Ee][+-]?[0-9]*)?', Number.Float), 

145 (r'\b([+-]?[0-9]+[KMGTPkmgtp]?)\b', Number.Integer), 

146 ], 

147 'subprogram': [ 

148 (r'\(', Punctuation, ('#pop', 'formal_part')), 

149 (r';', Punctuation, '#pop'), 

150 (r'"[^"]+"|\w+', Name.Function), 

151 include('root'), 

152 ], 

153 'type_def': [ 

154 (r'\(', Punctuation, 'formal_part'), 

155 ], 

156 'formal_part': [ 

157 (r'\)', Punctuation, '#pop'), 

158 (r'\w+', Name.Variable), 

159 (r',', Punctuation), 

160 (r'(:string|:integer|:real)\b', Keyword.Reserved), 

161 include('root'), 

162 ], 

163 } 

164 

165 

166class IconLexer(RegexLexer): 

167 """ 

168 Lexer for Icon. 

169 

170 .. versionadded:: 1.6 

171 """ 

172 name = 'Icon' 

173 aliases = ['icon'] 

174 filenames = ['*.icon', '*.ICON'] 

175 mimetypes = [] 

176 flags = re.MULTILINE 

177 

178 tokens = { 

179 'root': [ 

180 (r'[^\S\n]+', Text), 

181 (r'#.*?\n', Comment.Single), 

182 (r'[^\S\n]+', Text), 

183 (r'class|method|procedure', Keyword.Declaration, 'subprogram'), 

184 (r'(record)(\s+)(\w+)', 

185 bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), 

186 (r'(#line|\$C|\$Cend|\$define|\$else|\$endif|\$error|\$ifdef|' 

187 r'\$ifndef|\$include|\$line|\$undef)\b', Keyword.PreProc), 

188 (r'(&null|&fail)\b', Keyword.Constant), 

189 (r'&allocated|&ascii|&clock|&collections|&column|&col|&control|' 

190 r'&cset|&current|&dateline|&date|&digits|&dump|' 

191 r'&errno|&errornumber|&errortext|&errorvalue|&error|&errout|' 

192 r'&eventcode|&eventvalue|&eventsource|&e|' 

193 r'&features|&file|&host|&input|&interval|&lcase|&letters|' 

194 r'&level|&line|&ldrag|&lpress|&lrelease|' 

195 r'&main|&mdrag|&meta|&mpress|&mrelease|&now|&output|' 

196 r'&phi|&pick|&pi|&pos|&progname|' 

197 r'&random|&rdrag|&regions|&resize|&row|&rpress|&rrelease|' 

198 r'&shift|&source|&storage|&subject|' 

199 r'&time|&trace|&ucase|&version|' 

200 r'&window|&x|&y', Keyword.Reserved), 

201 (r'(by|of|not|to)\b', Keyword.Reserved), 

202 (r'(global|local|static)\b', Keyword.Reserved), 

203 (r'link', Keyword.Declaration), 

204 (words(( 

205 'break', 'case', 'create', 'default', 'end', 'all', 

206 'do', 'else', 'every', 'fail', 'if', 'initial', 

207 'invocable', 'next', 

208 'repeat', 'return', 'suspend', 

209 'then', 'until', 'while'), prefix=r'\b', suffix=r'\b'), 

210 Keyword.Reserved), 

211 (words(( 

212 'abs', 'acos', 'Active', 'Alert', 'any', 

213 'args', 'array', 'asin', 'atan', 'atanh', 'Attrib', 

214 'bal', 'Bg', 

215 'callout', 'center', 'char', 'chdir', 'chmod', 'chown', 'chroot', 

216 'Clip', 'Clone', 'close', 'cofail', 'collect', 

217 'Color', 'ColorValue', 'condvar', 'copy', 

218 'CopyArea', 'cos', 'Couple', 'crypt', 'cset', 'ctime', 

219 'delay', 'delete', 'detab', 'display', 'DrawArc', 

220 'DrawCircle', 'DrawCube', 'DrawCurve', 'DrawCylinder', 

221 'DrawDisk', 'DrawImage', 'DrawLine', 'DrawPoint', 'DrawPolygon', 

222 'DrawRectangle', 'DrawSegment', 'DrawSphere', 'DrawString', 

223 'DrawTorus', 'dtor', 

224 'entab', 'EraseArea', 'errorclear', 'Event', 'eventmask', 

225 'EvGet', 'EvSend', 'exec', 'exit', 'exp', 'Eye', 

226 'fcntl', 'fdup', 'fetch', 'Fg', 'fieldnames', 

227 'FillArc', 'FillCircle', 'FillPolygon', 

228 'FillRectangle', 'find', 'flock', 'flush', 'Font', 

229 'FreeColor', 'FreeSpace', 'function', 

230 'get', 'getch', 'getche', 'getenv', 

231 'GetSpace', 'gettimeofday', 

232 'getuid', 'globalnames', 'GotoRC', 'GotoXY', 'gtime', 'hardlink', 

233 'iand', 'icom', 'IdentityMatrix', 'image', 'InPort', 'insert', 

234 'Int86', 'integer', 'ioctl', 'ior', 'ishift', 'istate', 'ixor', 

235 'kbhit', 'key', 'keyword', 'kill', 

236 'left', 'Len', 'list', 'load', 'loadfunc', 'localnames', 

237 'lock', 'log', 'Lower', 'lstat', 

238 'many', 'map', 'match', 'MatrixMode', 'max', 'member', 

239 'membernames', 'methodnames', 'methods', 'min', 'mkdir', 'move', 

240 'MultMatrix', 'mutex', 

241 'name', 'NewColor', 'Normals', 'numeric', 

242 'open', 'opencl', 'oprec', 'ord', 'OutPort', 

243 'PaletteChars', 'PaletteColor', 'PaletteKey', 'paramnames', 

244 'parent', 'Pattern', 'Peek', 'Pending', 'pipe', 'Pixel', 

245 'Poke', 'pop', 'PopMatrix', 'Pos', 'pos', 

246 'proc', 'pull', 'push', 'PushMatrix', 'PushRotate', 'PushScale', 

247 'PushTranslate', 'put', 

248 'QueryPointer', 

249 'Raise', 'read', 'ReadImage', 'readlink', 'reads', 'ready', 

250 'real', 'receive', 'Refresh', 'Rem', 'remove', 'rename', 

251 'repl', 'reverse', 'right', 'rmdir', 'Rotate', 'Rpos', 

252 'rtod', 'runerr', 

253 'save', 'Scale', 'seek', 'select', 'send', 'seq', 

254 'serial', 'set', 'setenv', 

255 'setuid', 'signal', 'sin', 'sort', 'sortf', 

256 'spawn', 'sql', 'sqrt', 'stat', 'staticnames', 'stop', 

257 'string', 'structure', 'Swi', 

258 'symlink', 'sys_errstr', 'system', 'syswrite', 

259 'tab', 'table', 'tan', 

260 'Texcoord', 'Texture', 'TextWidth', 'Translate', 

261 'trap', 'trim', 'truncate', 'trylock', 'type', 

262 'umask', 'Uncouple', 'unlock', 'upto', 'utime', 

263 'variable', 

264 'wait', 'WAttrib', 'WDefault', 'WFlush', 'where', 

265 'WinAssociate', 'WinButton', 'WinColorDialog', 'WindowContents', 

266 'WinEditRegion', 'WinFontDialog', 'WinMenuBar', 'WinOpenDialog', 

267 'WinPlayMedia', 'WinSaveDialog', 'WinScrollBar', 'WinSelectDialog', 

268 'write', 'WriteImage', 'writes', 'WSection', 

269 'WSync'), prefix=r'\b', suffix=r'\b'), 

270 Name.Function), 

271 include('numbers'), 

272 (r'===|~===|\*\*|\+\+|--|\.|==|~==|<=|>=|=|~=|<<=|<<|>>=|>>|' 

273 r':=:|:=|<->|<-|\+:=|\|\||\|', Operator), 

274 (r'"(?:[^\\"]|\\.)*"', String), 

275 (r"'(?:[^\\']|\\.)*'", String.Character), 

276 (r'[*<>+=/&!?@~\\-]', Operator), 

277 (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), 

278 (r"[\[\]]", Punctuation), 

279 (r"<>|=>|[()|:;,.'`{}%\^&?]", Punctuation), 

280 (r'\n+', Text), 

281 ], 

282 'numbers': [ 

283 (r'\b([+-]?([2-9]|[12][0-9]|3[0-6])[rR][0-9a-zA-Z]+)\b', Number.Hex), 

284 (r'[+-]?[0-9]*\.([0-9]*)([Ee][+-]?[0-9]*)?', Number.Float), 

285 (r'\b([+-]?[0-9]+[KMGTPkmgtp]?)\b', Number.Integer), 

286 ], 

287 'subprogram': [ 

288 (r'\(', Punctuation, ('#pop', 'formal_part')), 

289 (r';', Punctuation, '#pop'), 

290 (r'"[^"]+"|\w+', Name.Function), 

291 include('root'), 

292 ], 

293 'type_def': [ 

294 (r'\(', Punctuation, 'formal_part'), 

295 ], 

296 'formal_part': [ 

297 (r'\)', Punctuation, '#pop'), 

298 (r'\w+', Name.Variable), 

299 (r',', Punctuation), 

300 (r'(:string|:integer|:real)\b', Keyword.Reserved), 

301 include('root'), 

302 ], 

303 } 

304 

305 

306class UcodeLexer(RegexLexer): 

307 """ 

308 Lexer for Icon ucode files. 

309 

310 .. versionadded:: 2.4 

311 """ 

312 name = 'ucode' 

313 aliases = ['ucode'] 

314 filenames = ['*.u', '*.u1', '*.u2'] 

315 mimetypes = [] 

316 flags = re.MULTILINE 

317 

318 tokens = { 

319 'root': [ 

320 (r'(#.*\n)', Comment), 

321 (words(( 

322 'con', 'declend', 'end', 

323 'global', 

324 'impl', 'invocable', 

325 'lab', 'link', 'local', 

326 'record', 

327 'uid', 'unions', 

328 'version'), 

329 prefix=r'\b', suffix=r'\b'), 

330 Name.Function), 

331 (words(( 

332 'colm', 'filen', 'line', 'synt'), 

333 prefix=r'\b', suffix=r'\b'), 

334 Comment), 

335 (words(( 

336 'asgn', 

337 'bang', 'bscan', 

338 'cat', 'ccase', 'chfail', 

339 'coact', 'cofail', 'compl', 

340 'coret', 'create', 'cset', 

341 'diff', 'div', 'dup', 

342 'efail', 'einit', 'end', 'eqv', 'eret', 

343 'error', 'escan', 'esusp', 

344 'field', 

345 'goto', 

346 'init', 'int', 'inter', 

347 'invoke', 

348 'keywd', 

349 'lconcat', 'lexeq', 'lexge', 

350 'lexgt', 'lexle', 'lexlt', 'lexne', 

351 'limit', 'llist', 'lsusp', 

352 'mark', 'mark0', 'minus', 'mod', 'mult', 

353 'neg', 'neqv', 'nonnull', 'noop', 'null', 

354 'number', 'numeq', 'numge', 'numgt', 

355 'numle', 'numlt', 'numne', 

356 'pfail', 'plus', 'pnull', 'pop', 'power', 

357 'pret', 'proc', 'psusp', 'push1', 'pushn1', 

358 'random', 'rasgn', 'rcv', 'rcvbk', 'real', 

359 'refresh', 'rswap', 

360 'sdup', 'sect', 'size', 'snd', 'sndbk', 

361 'str', 'subsc', 'swap', 

362 'tabmat', 'tally', 'toby', 'trace', 

363 'unmark', 

364 'value', 'var'), prefix=r'\b', suffix=r'\b'), 

365 Keyword.Declaration), 

366 (words(( 

367 'any', 

368 'case', 

369 'endcase', 'endevery', 'endif', 

370 'endifelse', 'endrepeat', 'endsuspend', 

371 'enduntil', 'endwhile', 'every', 

372 'if', 'ifelse', 

373 'repeat', 

374 'suspend', 

375 'until', 

376 'while'), 

377 prefix=r'\b', suffix=r'\b'), 

378 Name.Constant), 

379 (r'\d+(\s*|\.$|$)', Number.Integer), 

380 (r'[+-]?\d*\.\d+(E[-+]?\d+)?', Number.Float), 

381 (r'[+-]?\d+\.\d*(E[-+]?\d+)?', Number.Float), 

382 (r"(<>|=>|[()|:;,.'`]|[{}]|[%^]|[&?])", Punctuation), 

383 (r'\s+\b', Text), 

384 (r'[\w-]+', Text), 

385 ], 

386 } 

387 

388 def analyse_text(text): 

389 """endsuspend and endrepeat are unique to this language, and 

390 \\self, /self doesn't seem to get used anywhere else either.""" 

391 result = 0 

392 

393 if 'endsuspend' in text: 

394 result += 0.1 

395 

396 if 'endrepeat' in text: 

397 result += 0.1 

398 

399 if ':=' in text: 

400 result += 0.01 

401 

402 if 'procedure' in text and 'end' in text: 

403 result += 0.01 

404 

405 # This seems quite unique to unicon -- doesn't appear in any other 

406 # example source we have (A quick search reveals that \SELF appears in 

407 # Perl/Raku code) 

408 if r'\self' in text and r'/self' in text: 

409 result += 0.5 

410 

411 return result