|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.unicon |
|
4 ~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for the Icon and Unicon languages, including ucode VM. |
|
7 |
|
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include, bygroups, words, using, this |
|
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
16 Number, Punctuation |
|
17 |
|
18 __all__ = ['IconLexer', 'UcodeLexer', 'UniconLexer'] |
|
19 |
|
20 |
|
21 class UniconLexer(RegexLexer): |
|
22 """ |
|
23 For Unicon source code. |
|
24 |
|
25 .. versionadded:: 2.4 |
|
26 """ |
|
27 |
|
28 name = 'Unicon' |
|
29 aliases = ['unicon'] |
|
30 filenames = ['*.icn'] |
|
31 mimetypes = ['text/unicon'] |
|
32 |
|
33 flags = re.MULTILINE |
|
34 |
|
35 tokens = { |
|
36 'root': [ |
|
37 (r'[^\S\n]+', Text), |
|
38 (r'#.*?\n', Comment.Single), |
|
39 (r'[^\S\n]+', Text), |
|
40 (r'class|method|procedure', Keyword.Declaration, 'subprogram'), |
|
41 (r'(record)(\s+)(\w+)', |
|
42 bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), |
|
43 (r'(#line|\$C|\$Cend|\$define|\$else|\$endif|\$error|\$ifdef|' |
|
44 r'\$ifndef|\$include|\$line|\$undef)\b', Keyword.PreProc), |
|
45 (r'(&null|&fail)\b', Keyword.Constant), |
|
46 (r'&allocated|&ascii|&clock|&collections|&column|&col|&control|' |
|
47 r'&cset|¤t|&dateline|&date|&digits|&dump|' |
|
48 r'&errno|&errornumber|&errortext|&errorvalue|&error|&errout|' |
|
49 r'&eventcode|&eventvalue|&eventsource|&e|' |
|
50 r'&features|&file|&host|&input|&interval|&lcase|&letters|' |
|
51 r'&level|&line|&ldrag|&lpress|&lrelease|' |
|
52 r'&main|&mdrag|&meta|&mpress|&mrelease|&now|&output|' |
|
53 r'&phi|&pick|&pi|&pos|&progname|' |
|
54 r'&random|&rdrag|®ions|&resize|&row|&rpress|&rrelease|' |
|
55 r'&shift|&source|&storage|&subject|' |
|
56 r'&time|&trace|&ucase|&version|' |
|
57 r'&window|&x|&y', Keyword.Reserved), |
|
58 (r'(by|of|not|to)\b', Keyword.Reserved), |
|
59 (r'(global|local|static|abstract)\b', Keyword.Reserved), |
|
60 (r'package|link|import', Keyword.Declaration), |
|
61 (words(( |
|
62 'break', 'case', 'create', 'critical', 'default', 'end', 'all', |
|
63 'do', 'else', 'every', 'fail', 'if', 'import', 'initial', |
|
64 'initially', 'invocable', 'next', |
|
65 'repeat', 'return', 'suspend', |
|
66 'then', 'thread', 'until', 'while'), prefix=r'\b', suffix=r'\b'), |
|
67 Keyword.Reserved), |
|
68 (words(( |
|
69 'Abort', 'abs', 'acos', 'Active', 'Alert', 'any', 'Any', 'Arb', |
|
70 'Arbno', 'args', 'array', 'asin', 'atan', 'atanh', 'Attrib', |
|
71 'Bal', 'bal', 'Bg', 'Break', 'Breakx', |
|
72 'callout', 'center', 'char', 'chdir', 'chmod', 'chown', 'chroot', |
|
73 'classname', 'Clip', 'Clone', 'close', 'cofail', 'collect', |
|
74 'Color', 'ColorValue', 'condvar', 'constructor', 'copy', |
|
75 'CopyArea', 'cos', 'Couple', 'crypt', 'cset', 'ctime', |
|
76 'dbcolumns', 'dbdriver', 'dbkeys', 'dblimits', 'dbproduct', |
|
77 'dbtables', 'delay', 'delete', 'detab', 'display', 'DrawArc', |
|
78 'DrawCircle', 'DrawCube', 'DrawCurve', 'DrawCylinder', |
|
79 'DrawDisk', 'DrawImage', 'DrawLine', 'DrawPoint', 'DrawPolygon', |
|
80 'DrawRectangle', 'DrawSegment', 'DrawSphere', 'DrawString', |
|
81 'DrawTorus', 'dtor', |
|
82 'entab', 'EraseArea', 'errorclear', 'Event', 'eventmask', |
|
83 'EvGet', 'EvSend', 'exec', 'exit', 'exp', 'Eye', |
|
84 'Fail', 'fcntl', 'fdup', 'Fence', 'fetch', 'Fg', 'fieldnames', |
|
85 'filepair', 'FillArc', 'FillCircle', 'FillPolygon', |
|
86 'FillRectangle', 'find', 'flock', 'flush', 'Font', 'fork', |
|
87 'FreeColor', 'FreeSpace', 'function', |
|
88 'get', 'getch', 'getche', 'getegid', 'getenv', 'geteuid', |
|
89 'getgid', 'getgr', 'gethost', 'getpgrp', 'getpid', 'getppid', |
|
90 'getpw', 'getrusage', 'getserv', 'GetSpace', 'gettimeofday', |
|
91 'getuid', 'globalnames', 'GotoRC', 'GotoXY', 'gtime', 'hardlink', |
|
92 'iand', 'icom', 'IdentityMatrix', 'image', 'InPort', 'insert', |
|
93 'Int86', 'integer', 'ioctl', 'ior', 'ishift', 'istate', 'ixor', |
|
94 'kbhit', 'key', 'keyword', 'kill', |
|
95 'left', 'Len', 'list', 'load', 'loadfunc', 'localnames', |
|
96 'lock', 'log', 'Lower', 'lstat', |
|
97 'many', 'map', 'match', 'MatrixMode', 'max', 'member', |
|
98 'membernames', 'methodnames', 'methods', 'min', 'mkdir', 'move', |
|
99 'MultMatrix', 'mutex', |
|
100 'name', 'NewColor', 'Normals', 'NotAny', 'numeric', |
|
101 'open', 'opencl', 'oprec', 'ord', 'OutPort', |
|
102 'PaletteChars', 'PaletteColor', 'PaletteKey', 'paramnames', |
|
103 'parent', 'Pattern', 'Peek', 'Pending', 'pipe', 'Pixel', |
|
104 'PlayAudio', 'Poke', 'pop', 'PopMatrix', 'Pos', 'pos', |
|
105 'proc', 'pull', 'push', 'PushMatrix', 'PushRotate', 'PushScale', |
|
106 'PushTranslate', 'put', |
|
107 'QueryPointer', |
|
108 'Raise', 'read', 'ReadImage', 'readlink', 'reads', 'ready', |
|
109 'real', 'receive', 'Refresh', 'Rem', 'remove', 'rename', |
|
110 'repl', 'reverse', 'right', 'rmdir', 'Rotate', 'Rpos', |
|
111 'Rtab', 'rtod', 'runerr', |
|
112 'save', 'Scale', 'seek', 'select', 'send', 'seq', |
|
113 'serial', 'set', 'setenv', 'setgid', 'setgrent', |
|
114 'sethostent', 'setpgrp', 'setpwent', 'setservent', |
|
115 'setuid', 'signal', 'sin', 'sort', 'sortf', 'Span', |
|
116 'spawn', 'sql', 'sqrt', 'stat', 'staticnames', 'stop', |
|
117 'StopAudio', 'string', 'structure', 'Succeed', 'Swi', |
|
118 'symlink', 'sys_errstr', 'system', 'syswrite', |
|
119 'Tab', 'tab', 'table', 'tan', |
|
120 'Texcoord', 'Texture', 'TextWidth', 'Translate', |
|
121 'trap', 'trim', 'truncate', 'trylock', 'type', |
|
122 'umask', 'Uncouple', 'unlock', 'upto', 'utime', |
|
123 'variable', 'VAttrib', |
|
124 'wait', 'WAttrib', 'WDefault', 'WFlush', 'where', |
|
125 'WinAssociate', 'WinButton', 'WinColorDialog', 'WindowContents', |
|
126 'WinEditRegion', 'WinFontDialog', 'WinMenuBar', 'WinOpenDialog', |
|
127 'WinPlayMedia', 'WinSaveDialog', 'WinScrollBar', 'WinSelectDialog', |
|
128 'write', 'WriteImage', 'writes', 'WSection', |
|
129 'WSync'), prefix=r'\b', suffix=r'\b'), |
|
130 Name.Function), |
|
131 include('numbers'), |
|
132 (r'<@|<<@|>@|>>@|\.>|\->', Operator), |
|
133 (r'\*\*|\+\+|\-\-|\.|\=|\~\=|<\=|>\=|\=\=|\~\=\=|<<|<<\=|>>|>>\=', Operator), |
|
134 (r':\=|:\=:|\->|<\->|\+:\=|\|', Operator), |
|
135 (r'\=\=\=|\~\=\=\=', Operator), |
|
136 (r'"(?:[^\\"]|\\.)*"', String), |
|
137 (r"'(?:[^\\']|\\.)*'", String.Character), |
|
138 (r'[*<>+=/&!?@~\\-]', Operator), |
|
139 (r'\^', Operator), |
|
140 (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), |
|
141 (r"([\[\]])", Punctuation), |
|
142 (r"(<>|=>|[()|:;,.'`]|[{}]|[%]|[&?])", Punctuation), |
|
143 (r'\n+', Text), |
|
144 ], |
|
145 'numbers': [ |
|
146 (r'\b([+-]?([2-9]|[12][0-9]|3[0-6])[rR][0-9a-zA-Z]+)\b', Number.Hex), |
|
147 (r'[+-]?[0-9]*\.([0-9]*)([Ee][+-]?[0-9]*)?', Number.Float), |
|
148 (r'\b([+-]?[0-9]+[KMGTPkmgtp]?)\b', Number.Integer), |
|
149 ], |
|
150 'subprogram': [ |
|
151 (r'\(', Punctuation, ('#pop', 'formal_part')), |
|
152 (r';', Punctuation, '#pop'), |
|
153 (r'"[^"]+"|\w+', Name.Function), |
|
154 include('root'), |
|
155 ], |
|
156 'type_def': [ |
|
157 (r'\(', Punctuation, 'formal_part'), |
|
158 ], |
|
159 'formal_part': [ |
|
160 (r'\)', Punctuation, '#pop'), |
|
161 (r'\w+', Name.Variable), |
|
162 (r',', Punctuation), |
|
163 (r'(:string|:integer|:real)\b', Keyword.Reserved), |
|
164 include('root'), |
|
165 ], |
|
166 } |
|
167 |
|
168 |
|
169 class IconLexer(RegexLexer): |
|
170 """ |
|
171 Lexer for Icon. |
|
172 |
|
173 .. versionadded:: 1.6 |
|
174 """ |
|
175 name = 'Icon' |
|
176 aliases = ['icon'] |
|
177 filenames = ['*.icon', '*.ICON'] |
|
178 mimetypes = [] |
|
179 flags = re.MULTILINE |
|
180 |
|
181 tokens = { |
|
182 'root': [ |
|
183 (r'[^\S\n]+', Text), |
|
184 (r'#.*?\n', Comment.Single), |
|
185 (r'[^\S\n]+', Text), |
|
186 (r'class|method|procedure', Keyword.Declaration, 'subprogram'), |
|
187 (r'(record)(\s+)(\w+)', |
|
188 bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), |
|
189 (r'(#line|\$C|\$Cend|\$define|\$else|\$endif|\$error|\$ifdef|' |
|
190 r'\$ifndef|\$include|\$line|\$undef)\b', Keyword.PreProc), |
|
191 (r'(&null|&fail)\b', Keyword.Constant), |
|
192 (r'&allocated|&ascii|&clock|&collections|&column|&col|&control|' |
|
193 r'&cset|¤t|&dateline|&date|&digits|&dump|' |
|
194 r'&errno|&errornumber|&errortext|&errorvalue|&error|&errout|' |
|
195 r'&eventcode|&eventvalue|&eventsource|&e|' |
|
196 r'&features|&file|&host|&input|&interval|&lcase|&letters|' |
|
197 r'&level|&line|&ldrag|&lpress|&lrelease|' |
|
198 r'&main|&mdrag|&meta|&mpress|&mrelease|&now|&output|' |
|
199 r'&phi|&pick|&pi|&pos|&progname|' |
|
200 r'&random|&rdrag|®ions|&resize|&row|&rpress|&rrelease|' |
|
201 r'&shift|&source|&storage|&subject|' |
|
202 r'&time|&trace|&ucase|&version|' |
|
203 r'&window|&x|&y', Keyword.Reserved), |
|
204 (r'(by|of|not|to)\b', Keyword.Reserved), |
|
205 (r'(global|local|static)\b', Keyword.Reserved), |
|
206 (r'link', Keyword.Declaration), |
|
207 (words(( |
|
208 'break', 'case', 'create', 'default', 'end', 'all', |
|
209 'do', 'else', 'every', 'fail', 'if', 'initial', |
|
210 'invocable', 'next', |
|
211 'repeat', 'return', 'suspend', |
|
212 'then', 'until', 'while'), prefix=r'\b', suffix=r'\b'), |
|
213 Keyword.Reserved), |
|
214 (words(( |
|
215 'abs', 'acos', 'Active', 'Alert', 'any', |
|
216 'args', 'array', 'asin', 'atan', 'atanh', 'Attrib', |
|
217 'bal', 'Bg', |
|
218 'callout', 'center', 'char', 'chdir', 'chmod', 'chown', 'chroot', |
|
219 'Clip', 'Clone', 'close', 'cofail', 'collect', |
|
220 'Color', 'ColorValue', 'condvar', 'copy', |
|
221 'CopyArea', 'cos', 'Couple', 'crypt', 'cset', 'ctime', |
|
222 'delay', 'delete', 'detab', 'display', 'DrawArc', |
|
223 'DrawCircle', 'DrawCube', 'DrawCurve', 'DrawCylinder', |
|
224 'DrawDisk', 'DrawImage', 'DrawLine', 'DrawPoint', 'DrawPolygon', |
|
225 'DrawRectangle', 'DrawSegment', 'DrawSphere', 'DrawString', |
|
226 'DrawTorus', 'dtor', |
|
227 'entab', 'EraseArea', 'errorclear', 'Event', 'eventmask', |
|
228 'EvGet', 'EvSend', 'exec', 'exit', 'exp', 'Eye', |
|
229 'fcntl', 'fdup', 'fetch', 'Fg', 'fieldnames', |
|
230 'FillArc', 'FillCircle', 'FillPolygon', |
|
231 'FillRectangle', 'find', 'flock', 'flush', 'Font', |
|
232 'FreeColor', 'FreeSpace', 'function', |
|
233 'get', 'getch', 'getche', 'getenv', |
|
234 'GetSpace', 'gettimeofday', |
|
235 'getuid', 'globalnames', 'GotoRC', 'GotoXY', 'gtime', 'hardlink', |
|
236 'iand', 'icom', 'IdentityMatrix', 'image', 'InPort', 'insert', |
|
237 'Int86', 'integer', 'ioctl', 'ior', 'ishift', 'istate', 'ixor', |
|
238 'kbhit', 'key', 'keyword', 'kill', |
|
239 'left', 'Len', 'list', 'load', 'loadfunc', 'localnames', |
|
240 'lock', 'log', 'Lower', 'lstat', |
|
241 'many', 'map', 'match', 'MatrixMode', 'max', 'member', |
|
242 'membernames', 'methodnames', 'methods', 'min', 'mkdir', 'move', |
|
243 'MultMatrix', 'mutex', |
|
244 'name', 'NewColor', 'Normals', 'numeric', |
|
245 'open', 'opencl', 'oprec', 'ord', 'OutPort', |
|
246 'PaletteChars', 'PaletteColor', 'PaletteKey', 'paramnames', |
|
247 'parent', 'Pattern', 'Peek', 'Pending', 'pipe', 'Pixel', |
|
248 'Poke', 'pop', 'PopMatrix', 'Pos', 'pos', |
|
249 'proc', 'pull', 'push', 'PushMatrix', 'PushRotate', 'PushScale', |
|
250 'PushTranslate', 'put', |
|
251 'QueryPointer', |
|
252 'Raise', 'read', 'ReadImage', 'readlink', 'reads', 'ready', |
|
253 'real', 'receive', 'Refresh', 'Rem', 'remove', 'rename', |
|
254 'repl', 'reverse', 'right', 'rmdir', 'Rotate', 'Rpos', |
|
255 'rtod', 'runerr', |
|
256 'save', 'Scale', 'seek', 'select', 'send', 'seq', |
|
257 'serial', 'set', 'setenv', |
|
258 'setuid', 'signal', 'sin', 'sort', 'sortf', |
|
259 'spawn', 'sql', 'sqrt', 'stat', 'staticnames', 'stop', |
|
260 'string', 'structure', 'Swi', |
|
261 'symlink', 'sys_errstr', 'system', 'syswrite', |
|
262 'tab', 'table', 'tan', |
|
263 'Texcoord', 'Texture', 'TextWidth', 'Translate', |
|
264 'trap', 'trim', 'truncate', 'trylock', 'type', |
|
265 'umask', 'Uncouple', 'unlock', 'upto', 'utime', |
|
266 'variable', |
|
267 'wait', 'WAttrib', 'WDefault', 'WFlush', 'where', |
|
268 'WinAssociate', 'WinButton', 'WinColorDialog', 'WindowContents', |
|
269 'WinEditRegion', 'WinFontDialog', 'WinMenuBar', 'WinOpenDialog', |
|
270 'WinPlayMedia', 'WinSaveDialog', 'WinScrollBar', 'WinSelectDialog', |
|
271 'write', 'WriteImage', 'writes', 'WSection', |
|
272 'WSync'), prefix=r'\b', suffix=r'\b'), |
|
273 Name.Function), |
|
274 include('numbers'), |
|
275 (r'\*\*|\+\+|\-\-|\.|\=|\~\=|<\=|>\=|\=\=|\~\=\=|<<|<<\=|>>|>>\=', Operator), |
|
276 (r':\=|:\=:|<\-|<\->|\+:\=|\||\|\|', Operator), |
|
277 (r'\=\=\=|\~\=\=\=', Operator), |
|
278 (r'"(?:[^\\"]|\\.)*"', String), |
|
279 (r"'(?:[^\\']|\\.)*'", String.Character), |
|
280 (r'[*<>+=/&!?@~\\-]', Operator), |
|
281 (r'(\w+)(\s*|[(,])', bygroups(Name, using(this))), |
|
282 (r"([\[\]])", Punctuation), |
|
283 (r"(<>|=>|[()|:;,.'`]|[{}]|[%^]|[&?])", Punctuation), |
|
284 (r'\n+', Text), |
|
285 ], |
|
286 'numbers': [ |
|
287 (r'\b([+-]?([2-9]|[12][0-9]|3[0-6])[rR][0-9a-zA-Z]+)\b', Number.Hex), |
|
288 (r'[+-]?[0-9]*\.([0-9]*)([Ee][+-]?[0-9]*)?', Number.Float), |
|
289 (r'\b([+-]?[0-9]+[KMGTPkmgtp]?)\b', Number.Integer), |
|
290 ], |
|
291 'subprogram': [ |
|
292 (r'\(', Punctuation, ('#pop', 'formal_part')), |
|
293 (r';', Punctuation, '#pop'), |
|
294 (r'"[^"]+"|\w+', Name.Function), |
|
295 include('root'), |
|
296 ], |
|
297 'type_def': [ |
|
298 (r'\(', Punctuation, 'formal_part'), |
|
299 ], |
|
300 'formal_part': [ |
|
301 (r'\)', Punctuation, '#pop'), |
|
302 (r'\w+', Name.Variable), |
|
303 (r',', Punctuation), |
|
304 (r'(:string|:integer|:real)\b', Keyword.Reserved), |
|
305 include('root'), |
|
306 ], |
|
307 } |
|
308 |
|
309 |
|
310 class UcodeLexer(RegexLexer): |
|
311 """ |
|
312 Lexer for Icon ucode files. |
|
313 |
|
314 .. versionadded:: 2.4 |
|
315 """ |
|
316 name = 'ucode' |
|
317 aliases = ['ucode'] |
|
318 filenames = ['*.u', '*.u1', '*.u2'] |
|
319 mimetypes = [] |
|
320 flags = re.MULTILINE |
|
321 |
|
322 tokens = { |
|
323 'root': [ |
|
324 (r'(#.*\n)', Comment), |
|
325 (words(( |
|
326 'con', 'declend', 'end', |
|
327 'global', |
|
328 'impl', 'invocable', |
|
329 'lab', 'link', 'local', |
|
330 'record', |
|
331 'uid', 'unions', |
|
332 'version'), |
|
333 prefix=r'\b', suffix=r'\b'), |
|
334 Name.Function), |
|
335 (words(( |
|
336 'colm', 'filen', 'line', 'synt'), |
|
337 prefix=r'\b', suffix=r'\b'), |
|
338 Comment), |
|
339 (words(( |
|
340 'asgn', |
|
341 'bang', 'bscan', |
|
342 'cat', 'ccase', 'chfail', |
|
343 'coact', 'cofail', 'compl', |
|
344 'coret', 'create', 'cset', |
|
345 'diff', 'div', 'dup', |
|
346 'efail', 'einit', 'end', 'eqv', 'eret', |
|
347 'error', 'escan', 'esusp', |
|
348 'field', |
|
349 'goto', |
|
350 'init', 'int', 'inter', |
|
351 'invoke', |
|
352 'keywd', |
|
353 'lconcat', 'lexeq', 'lexge', |
|
354 'lexgt', 'lexle', 'lexlt', 'lexne', |
|
355 'limit', 'llist', 'lsusp', |
|
356 'mark', 'mark0', 'minus', 'mod', 'mult', |
|
357 'neg', 'neqv', 'nonnull', 'noop', 'null', |
|
358 'number', 'numeq', 'numge', 'numgt', |
|
359 'numle', 'numlt', 'numne', |
|
360 'pfail', 'plus', 'pnull', 'pop', 'power', |
|
361 'pret', 'proc', 'psusp', 'push1', 'pushn1', |
|
362 'random', 'rasgn', 'rcv', 'rcvbk', 'real', |
|
363 'refresh', 'rswap', |
|
364 'sdup', 'sect', 'size', 'snd', 'sndbk', |
|
365 'str', 'subsc', 'swap', |
|
366 'tabmat', 'tally', 'toby', 'trace', |
|
367 'unmark', |
|
368 'value', 'var'), prefix=r'\b', suffix=r'\b'), |
|
369 Keyword.Declaration), |
|
370 (words(( |
|
371 'any', |
|
372 'case', |
|
373 'endcase', 'endevery', 'endif', |
|
374 'endifelse', 'endrepeat', 'endsuspend', |
|
375 'enduntil', 'endwhile', 'every', |
|
376 'if', 'ifelse', |
|
377 'repeat', |
|
378 'suspend', |
|
379 'until', |
|
380 'while'), |
|
381 prefix=r'\b', suffix=r'\b'), |
|
382 Name.Constant), |
|
383 (r'\d+(\s*|\.$|$)', Number.Integer), |
|
384 (r'[+-]?\d*\.\d+(E[-+]?\d+)?', Number.Float), |
|
385 (r'[+-]?\d+\.\d*(E[-+]?\d+)?', Number.Float), |
|
386 (r"(<>|=>|[()|:;,.'`]|[{}]|[%^]|[&?])", Punctuation), |
|
387 (r'\s+\b', Text), |
|
388 (r'[\w-]+', Text), |
|
389 ], |
|
390 } |