1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 """ |
2 """ |
3 pygments.lexers.compiled |
3 pygments.lexers.compiled |
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for compiled languages. |
6 Just export lexer classes previously contained in this module. |
7 |
7 |
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 from __future__ import unicode_literals |
12 from pygments.lexers.jvm import JavaLexer, ScalaLexer |
|
13 from pygments.lexers.c_cpp import CLexer, CppLexer |
|
14 from pygments.lexers.d import DLexer |
|
15 from pygments.lexers.objective import ObjectiveCLexer, \ |
|
16 ObjectiveCppLexer, LogosLexer |
|
17 from pygments.lexers.go import GoLexer |
|
18 from pygments.lexers.rust import RustLexer |
|
19 from pygments.lexers.c_like import ECLexer, ValaLexer, CudaLexer |
|
20 from pygments.lexers.pascal import DelphiLexer, Modula2Lexer, AdaLexer |
|
21 from pygments.lexers.business import CobolLexer, CobolFreeformatLexer |
|
22 from pygments.lexers.fortran import FortranLexer |
|
23 from pygments.lexers.prolog import PrologLexer |
|
24 from pygments.lexers.python import CythonLexer |
|
25 from pygments.lexers.graphics import GLShaderLexer |
|
26 from pygments.lexers.ml import OcamlLexer |
|
27 from pygments.lexers.basic import BlitzBasicLexer, BlitzMaxLexer, MonkeyLexer |
|
28 from pygments.lexers.dylan import DylanLexer, DylanLidLexer, DylanConsoleLexer |
|
29 from pygments.lexers.ooc import OocLexer |
|
30 from pygments.lexers.felix import FelixLexer |
|
31 from pygments.lexers.nimrod import NimrodLexer |
13 |
32 |
14 import re |
33 __all__ = [] |
15 from string import Template |
|
16 |
|
17 from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \ |
|
18 this, combined, inherit, do_insertions |
|
19 from pygments.util import get_bool_opt, get_list_opt |
|
20 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
21 Number, Punctuation, Error, Literal, Generic |
|
22 from pygments.scanner import Scanner |
|
23 |
|
24 # backwards compatibility |
|
25 from pygments.lexers.functional import OcamlLexer |
|
26 from pygments.lexers.jvm import JavaLexer, ScalaLexer |
|
27 |
|
28 __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLexer', |
|
29 'ObjectiveCLexer', 'ObjectiveCppLexer', 'FortranLexer', 'GLShaderLexer', |
|
30 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer', |
|
31 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer', |
|
32 'NimrodLexer', 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer', |
|
33 'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer', |
|
34 'CobolFreeformatLexer', 'LogosLexer'] |
|
35 |
|
36 |
|
37 class CFamilyLexer(RegexLexer): |
|
38 """ |
|
39 For C family source code. This is used as a base class to avoid repetitious |
|
40 definitions. |
|
41 """ |
|
42 |
|
43 #: optional Comment or Whitespace |
|
44 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' |
|
45 #: only one /* */ style comment |
|
46 _ws1 = r':\s*/[*].*?[*]/\s*' |
|
47 |
|
48 tokens = { |
|
49 'whitespace': [ |
|
50 # preprocessor directives: without whitespace |
|
51 ('^#if\s+0', Comment.Preproc, 'if0'), |
|
52 ('^#', Comment.Preproc, 'macro'), |
|
53 # or with whitespace |
|
54 ('^(' + _ws1 + r')(#if\s+0)', |
|
55 bygroups(using(this), Comment.Preproc), 'if0'), |
|
56 ('^(' + _ws1 + ')(#)', |
|
57 bygroups(using(this), Comment.Preproc), 'macro'), |
|
58 (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', |
|
59 bygroups(Text, Name.Label)), |
|
60 (r'\n', Text), |
|
61 (r'\s+', Text), |
|
62 (r'\\\n', Text), # line continuation |
|
63 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), |
|
64 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
65 ], |
|
66 'statements': [ |
|
67 (r'L?"', String, 'string'), |
|
68 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), |
|
69 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float), |
|
70 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
71 (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex), |
|
72 (r'0[0-7]+[LlUu]*', Number.Oct), |
|
73 (r'\d+[LlUu]*', Number.Integer), |
|
74 (r'\*/', Error), |
|
75 (r'[~!%^&*+=|?:<>/-]', Operator), |
|
76 (r'[()\[\],.]', Punctuation), |
|
77 (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)), |
|
78 (r'(auto|break|case|const|continue|default|do|else|enum|extern|' |
|
79 r'for|goto|if|register|restricted|return|sizeof|static|struct|' |
|
80 r'switch|typedef|union|volatile|while)\b', Keyword), |
|
81 (r'(bool|int|long|float|short|double|char|unsigned|signed|void|' |
|
82 r'[a-z_][a-z0-9_]*_t)\b', |
|
83 Keyword.Type), |
|
84 (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved), |
|
85 # Vector intrinsics |
|
86 (r'(__(m128i|m128d|m128|m64))\b', Keyword.Reserved), |
|
87 # Microsoft-isms |
|
88 (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|' |
|
89 r'declspec|finally|int64|try|leave|wchar_t|w64|unaligned|' |
|
90 r'raise|noop|identifier|forceinline|assume)\b', Keyword.Reserved), |
|
91 (r'(true|false|NULL)\b', Name.Builtin), |
|
92 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
93 ], |
|
94 'root': [ |
|
95 include('whitespace'), |
|
96 # functions |
|
97 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments |
|
98 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name |
|
99 r'(\s*\([^;]*?\))' # signature |
|
100 r'(' + _ws + r')?({)', |
|
101 bygroups(using(this), Name.Function, using(this), using(this), |
|
102 Punctuation), |
|
103 'function'), |
|
104 # function declarations |
|
105 (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments |
|
106 r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name |
|
107 r'(\s*\([^;]*?\))' # signature |
|
108 r'(' + _ws + r')?(;)', |
|
109 bygroups(using(this), Name.Function, using(this), using(this), |
|
110 Punctuation)), |
|
111 ('', Text, 'statement'), |
|
112 ], |
|
113 'statement' : [ |
|
114 include('whitespace'), |
|
115 include('statements'), |
|
116 ('[{}]', Punctuation), |
|
117 (';', Punctuation, '#pop'), |
|
118 ], |
|
119 'function': [ |
|
120 include('whitespace'), |
|
121 include('statements'), |
|
122 (';', Punctuation), |
|
123 ('{', Punctuation, '#push'), |
|
124 ('}', Punctuation, '#pop'), |
|
125 ], |
|
126 'string': [ |
|
127 (r'"', String, '#pop'), |
|
128 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|' |
|
129 r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape), |
|
130 (r'[^\\"\n]+', String), # all other characters |
|
131 (r'\\\n', String), # line continuation |
|
132 (r'\\', String), # stray backslash |
|
133 ], |
|
134 'macro': [ |
|
135 (r'[^/\n]+', Comment.Preproc), |
|
136 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
|
137 (r'//.*?\n', Comment.Single, '#pop'), |
|
138 (r'/', Comment.Preproc), |
|
139 (r'(?<=\\)\n', Comment.Preproc), |
|
140 (r'\n', Comment.Preproc, '#pop'), |
|
141 ], |
|
142 'if0': [ |
|
143 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), |
|
144 (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'), |
|
145 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), |
|
146 (r'.*?\n', Comment), |
|
147 ] |
|
148 } |
|
149 |
|
150 stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t', |
|
151 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list', |
|
152 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t', |
|
153 'wctrans_t', 'wint_t', 'wctype_t'] |
|
154 c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t', |
|
155 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t', |
|
156 'int_least16_t', 'int_least32_t', 'int_least64_t', |
|
157 'uint_least8_t', 'uint_least16_t', 'uint_least32_t', |
|
158 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t', |
|
159 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t', |
|
160 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t', |
|
161 'uintmax_t'] |
|
162 |
|
163 def __init__(self, **options): |
|
164 self.stdlibhighlighting = get_bool_opt(options, |
|
165 'stdlibhighlighting', True) |
|
166 self.c99highlighting = get_bool_opt(options, |
|
167 'c99highlighting', True) |
|
168 RegexLexer.__init__(self, **options) |
|
169 |
|
170 def get_tokens_unprocessed(self, text): |
|
171 for index, token, value in \ |
|
172 RegexLexer.get_tokens_unprocessed(self, text): |
|
173 if token is Name: |
|
174 if self.stdlibhighlighting and value in self.stdlib_types: |
|
175 token = Keyword.Type |
|
176 elif self.c99highlighting and value in self.c99_types: |
|
177 token = Keyword.Type |
|
178 yield index, token, value |
|
179 |
|
180 |
|
181 class CLexer(CFamilyLexer): |
|
182 """ |
|
183 For C source code with preprocessor directives. |
|
184 """ |
|
185 name = 'C' |
|
186 aliases = ['c'] |
|
187 filenames = ['*.c', '*.h', '*.idc'] |
|
188 mimetypes = ['text/x-chdr', 'text/x-csrc'] |
|
189 priority = 0.1 |
|
190 |
|
191 def analyse_text(text): |
|
192 return 0.1 |
|
193 |
|
194 |
|
195 class CppLexer(CFamilyLexer): |
|
196 """ |
|
197 For C++ source code with preprocessor directives. |
|
198 """ |
|
199 name = 'C++' |
|
200 aliases = ['cpp', 'c++'] |
|
201 filenames = ['*.cpp', '*.hpp', '*.c++', '*.h++', |
|
202 '*.cc', '*.hh', '*.cxx', '*.hxx', |
|
203 '*.C', '*.H', '*.cp', '*.CPP'] |
|
204 mimetypes = ['text/x-c++hdr', 'text/x-c++src'] |
|
205 priority = 0.1 |
|
206 |
|
207 tokens = { |
|
208 'statements': [ |
|
209 (r'(asm|catch|const_cast|delete|dynamic_cast|explicit|' |
|
210 r'export|friend|mutable|namespace|new|operator|' |
|
211 r'private|protected|public|reinterpret_cast|' |
|
212 r'restrict|static_cast|template|this|throw|throws|' |
|
213 r'typeid|typename|using|virtual)\b', Keyword), |
|
214 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), |
|
215 inherit, |
|
216 ], |
|
217 'root': [ |
|
218 inherit, |
|
219 # C++ Microsoft-isms |
|
220 (r'__(virtual_inheritance|uuidof|super|single_inheritance|' |
|
221 r'multiple_inheritance|interface|event)\b', Keyword.Reserved), |
|
222 # Offload C++ extensions, http://offload.codeplay.com/ |
|
223 (r'(__offload|__blockingoffload|__outer)\b', Keyword.Pseudo), |
|
224 ], |
|
225 'classname': [ |
|
226 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'), |
|
227 # template specification |
|
228 (r'\s*(?=>)', Text, '#pop'), |
|
229 ], |
|
230 } |
|
231 |
|
232 def analyse_text(text): |
|
233 return 0.1 |
|
234 |
|
235 |
|
236 class ECLexer(CLexer): |
|
237 """ |
|
238 For eC source code with preprocessor directives. |
|
239 |
|
240 *New in Pygments 1.5.* |
|
241 """ |
|
242 name = 'eC' |
|
243 aliases = ['ec'] |
|
244 filenames = ['*.ec', '*.eh'] |
|
245 mimetypes = ['text/x-echdr', 'text/x-ecsrc'] |
|
246 |
|
247 tokens = { |
|
248 'statements': [ |
|
249 (r'(virtual|class|private|public|property|import|delete|new|new0|' |
|
250 r'renew|renew0|define|get|set|remote|dllexport|dllimport|stdcall|' |
|
251 r'subclass|__on_register_module|namespace|using|typed_object|' |
|
252 r'any_object|incref|register|watch|stopwatching|firewatchers|' |
|
253 r'watchable|class_designer|class_fixed|class_no_expansion|isset|' |
|
254 r'class_default_property|property_category|class_data|' |
|
255 r'class_property|virtual|thisclass|' |
|
256 r'dbtable|dbindex|database_open|dbfield)\b', Keyword), |
|
257 (r'(uint|uint16|uint32|uint64|bool|byte|unichar|int64)\b', |
|
258 Keyword.Type), |
|
259 (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), |
|
260 (r'(null|value|this)\b', Name.Builtin), |
|
261 inherit, |
|
262 ], |
|
263 'classname': [ |
|
264 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'), |
|
265 # template specification |
|
266 (r'\s*(?=>)', Text, '#pop'), |
|
267 ], |
|
268 } |
|
269 |
|
270 |
|
271 class DLexer(RegexLexer): |
|
272 """ |
|
273 For D source. |
|
274 |
|
275 *New in Pygments 1.2.* |
|
276 """ |
|
277 name = 'D' |
|
278 filenames = ['*.d', '*.di'] |
|
279 aliases = ['d'] |
|
280 mimetypes = ['text/x-dsrc'] |
|
281 |
|
282 tokens = { |
|
283 'root': [ |
|
284 (r'\n', Text), |
|
285 (r'\s+', Text), |
|
286 #(r'\\\n', Text), # line continuations |
|
287 # Comments |
|
288 (r'//(.*?)\n', Comment.Single), |
|
289 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
290 (r'/\+', Comment.Multiline, 'nested_comment'), |
|
291 # Keywords |
|
292 (r'(abstract|alias|align|asm|assert|auto|body|break|case|cast' |
|
293 r'|catch|class|const|continue|debug|default|delegate|delete' |
|
294 r'|deprecated|do|else|enum|export|extern|finally|final' |
|
295 r'|foreach_reverse|foreach|for|function|goto|if|import|inout' |
|
296 r'|interface|invariant|in|is|lazy|mixin|module|new|nothrow|out' |
|
297 r'|override|package|pragma|private|protected|public|pure|ref|return' |
|
298 r'|scope|static|struct|super|switch|synchronized|template|this' |
|
299 r'|throw|try|typedef|typeid|typeof|union|unittest|version|volatile' |
|
300 r'|while|with|__traits)\b', Keyword |
|
301 ), |
|
302 (r'(bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|float' |
|
303 r'|idouble|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong' |
|
304 r'|ushort|void|wchar)\b', Keyword.Type |
|
305 ), |
|
306 (r'(false|true|null)\b', Keyword.Constant), |
|
307 (r'macro\b', Keyword.Reserved), |
|
308 (r'(string|wstring|dstring)\b', Name.Builtin), |
|
309 # FloatLiteral |
|
310 # -- HexFloat |
|
311 (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)' |
|
312 r'[pP][+\-]?[0-9_]+[fFL]?[i]?', Number.Float), |
|
313 # -- DecimalFloat |
|
314 (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|' |
|
315 r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?', Number.Float), |
|
316 (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?', Number.Float), |
|
317 # IntegerLiteral |
|
318 # -- Binary |
|
319 (r'0[Bb][01_]+', Number), |
|
320 # -- Octal |
|
321 (r'0[0-7_]+', Number.Oct), |
|
322 # -- Hexadecimal |
|
323 (r'0[xX][0-9a-fA-F_]+', Number.Hex), |
|
324 # -- Decimal |
|
325 (r'(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?', Number.Integer), |
|
326 # CharacterLiteral |
|
327 (r"""'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" |
|
328 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'""", |
|
329 String.Char |
|
330 ), |
|
331 # StringLiteral |
|
332 # -- WysiwygString |
|
333 (r'r"[^"]*"[cwd]?', String), |
|
334 # -- AlternateWysiwygString |
|
335 (r'`[^`]*`[cwd]?', String), |
|
336 # -- DoubleQuotedString |
|
337 (r'"(\\\\|\\"|[^"])*"[cwd]?', String), |
|
338 # -- EscapeSequence |
|
339 (r"\\(['\"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}" |
|
340 r"|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)", |
|
341 String |
|
342 ), |
|
343 # -- HexString |
|
344 (r'x"[0-9a-fA-F_\s]*"[cwd]?', String), |
|
345 # -- DelimitedString |
|
346 (r'q"\[', String, 'delimited_bracket'), |
|
347 (r'q"\(', String, 'delimited_parenthesis'), |
|
348 (r'q"<', String, 'delimited_angle'), |
|
349 (r'q"{', String, 'delimited_curly'), |
|
350 (r'q"([a-zA-Z_]\w*)\n.*?\n\1"', String), |
|
351 (r'q"(.).*?\1"', String), |
|
352 # -- TokenString |
|
353 (r'q{', String, 'token_string'), |
|
354 # Tokens |
|
355 (r'(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>=' |
|
356 r'|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)' |
|
357 r'|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]', Punctuation |
|
358 ), |
|
359 # Identifier |
|
360 (r'[a-zA-Z_]\w*', Name), |
|
361 ], |
|
362 'nested_comment': [ |
|
363 (r'[^+/]+', Comment.Multiline), |
|
364 (r'/\+', Comment.Multiline, '#push'), |
|
365 (r'\+/', Comment.Multiline, '#pop'), |
|
366 (r'[+/]', Comment.Multiline), |
|
367 ], |
|
368 'token_string': [ |
|
369 (r'{', Punctuation, 'token_string_nest'), |
|
370 (r'}', String, '#pop'), |
|
371 include('root'), |
|
372 ], |
|
373 'token_string_nest': [ |
|
374 (r'{', Punctuation, '#push'), |
|
375 (r'}', Punctuation, '#pop'), |
|
376 include('root'), |
|
377 ], |
|
378 'delimited_bracket': [ |
|
379 (r'[^\[\]]+', String), |
|
380 (r'\[', String, 'delimited_inside_bracket'), |
|
381 (r'\]"', String, '#pop'), |
|
382 ], |
|
383 'delimited_inside_bracket': [ |
|
384 (r'[^\[\]]+', String), |
|
385 (r'\[', String, '#push'), |
|
386 (r'\]', String, '#pop'), |
|
387 ], |
|
388 'delimited_parenthesis': [ |
|
389 (r'[^\(\)]+', String), |
|
390 (r'\(', String, 'delimited_inside_parenthesis'), |
|
391 (r'\)"', String, '#pop'), |
|
392 ], |
|
393 'delimited_inside_parenthesis': [ |
|
394 (r'[^\(\)]+', String), |
|
395 (r'\(', String, '#push'), |
|
396 (r'\)', String, '#pop'), |
|
397 ], |
|
398 'delimited_angle': [ |
|
399 (r'[^<>]+', String), |
|
400 (r'<', String, 'delimited_inside_angle'), |
|
401 (r'>"', String, '#pop'), |
|
402 ], |
|
403 'delimited_inside_angle': [ |
|
404 (r'[^<>]+', String), |
|
405 (r'<', String, '#push'), |
|
406 (r'>', String, '#pop'), |
|
407 ], |
|
408 'delimited_curly': [ |
|
409 (r'[^{}]+', String), |
|
410 (r'{', String, 'delimited_inside_curly'), |
|
411 (r'}"', String, '#pop'), |
|
412 ], |
|
413 'delimited_inside_curly': [ |
|
414 (r'[^{}]+', String), |
|
415 (r'{', String, '#push'), |
|
416 (r'}', String, '#pop'), |
|
417 ], |
|
418 } |
|
419 |
|
420 |
|
421 class DelphiLexer(Lexer): |
|
422 """ |
|
423 For `Delphi <http://www.borland.com/delphi/>`_ (Borland Object Pascal), |
|
424 Turbo Pascal and Free Pascal source code. |
|
425 |
|
426 Additional options accepted: |
|
427 |
|
428 `turbopascal` |
|
429 Highlight Turbo Pascal specific keywords (default: ``True``). |
|
430 `delphi` |
|
431 Highlight Borland Delphi specific keywords (default: ``True``). |
|
432 `freepascal` |
|
433 Highlight Free Pascal specific keywords (default: ``True``). |
|
434 `units` |
|
435 A list of units that should be considered builtin, supported are |
|
436 ``System``, ``SysUtils``, ``Classes`` and ``Math``. |
|
437 Default is to consider all of them builtin. |
|
438 """ |
|
439 name = 'Delphi' |
|
440 aliases = ['delphi', 'pas', 'pascal', 'objectpascal'] |
|
441 filenames = ['*.pas'] |
|
442 mimetypes = ['text/x-pascal'] |
|
443 |
|
444 TURBO_PASCAL_KEYWORDS = [ |
|
445 'absolute', 'and', 'array', 'asm', 'begin', 'break', 'case', |
|
446 'const', 'constructor', 'continue', 'destructor', 'div', 'do', |
|
447 'downto', 'else', 'end', 'file', 'for', 'function', 'goto', |
|
448 'if', 'implementation', 'in', 'inherited', 'inline', 'interface', |
|
449 'label', 'mod', 'nil', 'not', 'object', 'of', 'on', 'operator', |
|
450 'or', 'packed', 'procedure', 'program', 'record', 'reintroduce', |
|
451 'repeat', 'self', 'set', 'shl', 'shr', 'string', 'then', 'to', |
|
452 'type', 'unit', 'until', 'uses', 'var', 'while', 'with', 'xor' |
|
453 ] |
|
454 |
|
455 DELPHI_KEYWORDS = [ |
|
456 'as', 'class', 'except', 'exports', 'finalization', 'finally', |
|
457 'initialization', 'is', 'library', 'on', 'property', 'raise', |
|
458 'threadvar', 'try' |
|
459 ] |
|
460 |
|
461 FREE_PASCAL_KEYWORDS = [ |
|
462 'dispose', 'exit', 'false', 'new', 'true' |
|
463 ] |
|
464 |
|
465 BLOCK_KEYWORDS = set([ |
|
466 'begin', 'class', 'const', 'constructor', 'destructor', 'end', |
|
467 'finalization', 'function', 'implementation', 'initialization', |
|
468 'label', 'library', 'operator', 'procedure', 'program', 'property', |
|
469 'record', 'threadvar', 'type', 'unit', 'uses', 'var' |
|
470 ]) |
|
471 |
|
472 FUNCTION_MODIFIERS = set([ |
|
473 'alias', 'cdecl', 'export', 'inline', 'interrupt', 'nostackframe', |
|
474 'pascal', 'register', 'safecall', 'softfloat', 'stdcall', |
|
475 'varargs', 'name', 'dynamic', 'near', 'virtual', 'external', |
|
476 'override', 'assembler' |
|
477 ]) |
|
478 |
|
479 # XXX: those aren't global. but currently we know no way for defining |
|
480 # them just for the type context. |
|
481 DIRECTIVES = set([ |
|
482 'absolute', 'abstract', 'assembler', 'cppdecl', 'default', 'far', |
|
483 'far16', 'forward', 'index', 'oldfpccall', 'private', 'protected', |
|
484 'published', 'public' |
|
485 ]) |
|
486 |
|
487 BUILTIN_TYPES = set([ |
|
488 'ansichar', 'ansistring', 'bool', 'boolean', 'byte', 'bytebool', |
|
489 'cardinal', 'char', 'comp', 'currency', 'double', 'dword', |
|
490 'extended', 'int64', 'integer', 'iunknown', 'longbool', 'longint', |
|
491 'longword', 'pansichar', 'pansistring', 'pbool', 'pboolean', |
|
492 'pbyte', 'pbytearray', 'pcardinal', 'pchar', 'pcomp', 'pcurrency', |
|
493 'pdate', 'pdatetime', 'pdouble', 'pdword', 'pextended', 'phandle', |
|
494 'pint64', 'pinteger', 'plongint', 'plongword', 'pointer', |
|
495 'ppointer', 'pshortint', 'pshortstring', 'psingle', 'psmallint', |
|
496 'pstring', 'pvariant', 'pwidechar', 'pwidestring', 'pword', |
|
497 'pwordarray', 'pwordbool', 'real', 'real48', 'shortint', |
|
498 'shortstring', 'single', 'smallint', 'string', 'tclass', 'tdate', |
|
499 'tdatetime', 'textfile', 'thandle', 'tobject', 'ttime', 'variant', |
|
500 'widechar', 'widestring', 'word', 'wordbool' |
|
501 ]) |
|
502 |
|
503 BUILTIN_UNITS = { |
|
504 'System': [ |
|
505 'abs', 'acquireexceptionobject', 'addr', 'ansitoutf8', |
|
506 'append', 'arctan', 'assert', 'assigned', 'assignfile', |
|
507 'beginthread', 'blockread', 'blockwrite', 'break', 'chdir', |
|
508 'chr', 'close', 'closefile', 'comptocurrency', 'comptodouble', |
|
509 'concat', 'continue', 'copy', 'cos', 'dec', 'delete', |
|
510 'dispose', 'doubletocomp', 'endthread', 'enummodules', |
|
511 'enumresourcemodules', 'eof', 'eoln', 'erase', 'exceptaddr', |
|
512 'exceptobject', 'exclude', 'exit', 'exp', 'filepos', 'filesize', |
|
513 'fillchar', 'finalize', 'findclasshinstance', 'findhinstance', |
|
514 'findresourcehinstance', 'flush', 'frac', 'freemem', |
|
515 'get8087cw', 'getdir', 'getlasterror', 'getmem', |
|
516 'getmemorymanager', 'getmodulefilename', 'getvariantmanager', |
|
517 'halt', 'hi', 'high', 'inc', 'include', 'initialize', 'insert', |
|
518 'int', 'ioresult', 'ismemorymanagerset', 'isvariantmanagerset', |
|
519 'length', 'ln', 'lo', 'low', 'mkdir', 'move', 'new', 'odd', |
|
520 'olestrtostring', 'olestrtostrvar', 'ord', 'paramcount', |
|
521 'paramstr', 'pi', 'pos', 'pred', 'ptr', 'pucs4chars', 'random', |
|
522 'randomize', 'read', 'readln', 'reallocmem', |
|
523 'releaseexceptionobject', 'rename', 'reset', 'rewrite', 'rmdir', |
|
524 'round', 'runerror', 'seek', 'seekeof', 'seekeoln', |
|
525 'set8087cw', 'setlength', 'setlinebreakstyle', |
|
526 'setmemorymanager', 'setstring', 'settextbuf', |
|
527 'setvariantmanager', 'sin', 'sizeof', 'slice', 'sqr', 'sqrt', |
|
528 'str', 'stringofchar', 'stringtoolestr', 'stringtowidechar', |
|
529 'succ', 'swap', 'trunc', 'truncate', 'typeinfo', |
|
530 'ucs4stringtowidestring', 'unicodetoutf8', 'uniquestring', |
|
531 'upcase', 'utf8decode', 'utf8encode', 'utf8toansi', |
|
532 'utf8tounicode', 'val', 'vararrayredim', 'varclear', |
|
533 'widecharlentostring', 'widecharlentostrvar', |
|
534 'widechartostring', 'widechartostrvar', |
|
535 'widestringtoucs4string', 'write', 'writeln' |
|
536 ], |
|
537 'SysUtils': [ |
|
538 'abort', 'addexitproc', 'addterminateproc', 'adjustlinebreaks', |
|
539 'allocmem', 'ansicomparefilename', 'ansicomparestr', |
|
540 'ansicomparetext', 'ansidequotedstr', 'ansiextractquotedstr', |
|
541 'ansilastchar', 'ansilowercase', 'ansilowercasefilename', |
|
542 'ansipos', 'ansiquotedstr', 'ansisamestr', 'ansisametext', |
|
543 'ansistrcomp', 'ansistricomp', 'ansistrlastchar', 'ansistrlcomp', |
|
544 'ansistrlicomp', 'ansistrlower', 'ansistrpos', 'ansistrrscan', |
|
545 'ansistrscan', 'ansistrupper', 'ansiuppercase', |
|
546 'ansiuppercasefilename', 'appendstr', 'assignstr', 'beep', |
|
547 'booltostr', 'bytetocharindex', 'bytetocharlen', 'bytetype', |
|
548 'callterminateprocs', 'changefileext', 'charlength', |
|
549 'chartobyteindex', 'chartobytelen', 'comparemem', 'comparestr', |
|
550 'comparetext', 'createdir', 'createguid', 'currentyear', |
|
551 'currtostr', 'currtostrf', 'date', 'datetimetofiledate', |
|
552 'datetimetostr', 'datetimetostring', 'datetimetosystemtime', |
|
553 'datetimetotimestamp', 'datetostr', 'dayofweek', 'decodedate', |
|
554 'decodedatefully', 'decodetime', 'deletefile', 'directoryexists', |
|
555 'diskfree', 'disksize', 'disposestr', 'encodedate', 'encodetime', |
|
556 'exceptionerrormessage', 'excludetrailingbackslash', |
|
557 'excludetrailingpathdelimiter', 'expandfilename', |
|
558 'expandfilenamecase', 'expanduncfilename', 'extractfiledir', |
|
559 'extractfiledrive', 'extractfileext', 'extractfilename', |
|
560 'extractfilepath', 'extractrelativepath', 'extractshortpathname', |
|
561 'fileage', 'fileclose', 'filecreate', 'filedatetodatetime', |
|
562 'fileexists', 'filegetattr', 'filegetdate', 'fileisreadonly', |
|
563 'fileopen', 'fileread', 'filesearch', 'fileseek', 'filesetattr', |
|
564 'filesetdate', 'filesetreadonly', 'filewrite', 'finalizepackage', |
|
565 'findclose', 'findcmdlineswitch', 'findfirst', 'findnext', |
|
566 'floattocurr', 'floattodatetime', 'floattodecimal', 'floattostr', |
|
567 'floattostrf', 'floattotext', 'floattotextfmt', 'fmtloadstr', |
|
568 'fmtstr', 'forcedirectories', 'format', 'formatbuf', 'formatcurr', |
|
569 'formatdatetime', 'formatfloat', 'freeandnil', 'getcurrentdir', |
|
570 'getenvironmentvariable', 'getfileversion', 'getformatsettings', |
|
571 'getlocaleformatsettings', 'getmodulename', 'getpackagedescription', |
|
572 'getpackageinfo', 'gettime', 'guidtostring', 'incamonth', |
|
573 'includetrailingbackslash', 'includetrailingpathdelimiter', |
|
574 'incmonth', 'initializepackage', 'interlockeddecrement', |
|
575 'interlockedexchange', 'interlockedexchangeadd', |
|
576 'interlockedincrement', 'inttohex', 'inttostr', 'isdelimiter', |
|
577 'isequalguid', 'isleapyear', 'ispathdelimiter', 'isvalidident', |
|
578 'languages', 'lastdelimiter', 'loadpackage', 'loadstr', |
|
579 'lowercase', 'msecstotimestamp', 'newstr', 'nextcharindex', 'now', |
|
580 'outofmemoryerror', 'quotedstr', 'raiselastoserror', |
|
581 'raiselastwin32error', 'removedir', 'renamefile', 'replacedate', |
|
582 'replacetime', 'safeloadlibrary', 'samefilename', 'sametext', |
|
583 'setcurrentdir', 'showexception', 'sleep', 'stralloc', 'strbufsize', |
|
584 'strbytetype', 'strcat', 'strcharlength', 'strcomp', 'strcopy', |
|
585 'strdispose', 'strecopy', 'strend', 'strfmt', 'stricomp', |
|
586 'stringreplace', 'stringtoguid', 'strlcat', 'strlcomp', 'strlcopy', |
|
587 'strlen', 'strlfmt', 'strlicomp', 'strlower', 'strmove', 'strnew', |
|
588 'strnextchar', 'strpas', 'strpcopy', 'strplcopy', 'strpos', |
|
589 'strrscan', 'strscan', 'strtobool', 'strtobooldef', 'strtocurr', |
|
590 'strtocurrdef', 'strtodate', 'strtodatedef', 'strtodatetime', |
|
591 'strtodatetimedef', 'strtofloat', 'strtofloatdef', 'strtoint', |
|
592 'strtoint64', 'strtoint64def', 'strtointdef', 'strtotime', |
|
593 'strtotimedef', 'strupper', 'supports', 'syserrormessage', |
|
594 'systemtimetodatetime', 'texttofloat', 'time', 'timestamptodatetime', |
|
595 'timestamptomsecs', 'timetostr', 'trim', 'trimleft', 'trimright', |
|
596 'tryencodedate', 'tryencodetime', 'tryfloattocurr', 'tryfloattodatetime', |
|
597 'trystrtobool', 'trystrtocurr', 'trystrtodate', 'trystrtodatetime', |
|
598 'trystrtofloat', 'trystrtoint', 'trystrtoint64', 'trystrtotime', |
|
599 'unloadpackage', 'uppercase', 'widecomparestr', 'widecomparetext', |
|
600 'widefmtstr', 'wideformat', 'wideformatbuf', 'widelowercase', |
|
601 'widesamestr', 'widesametext', 'wideuppercase', 'win32check', |
|
602 'wraptext' |
|
603 ], |
|
604 'Classes': [ |
|
605 'activateclassgroup', 'allocatehwnd', 'bintohex', 'checksynchronize', |
|
606 'collectionsequal', 'countgenerations', 'deallocatehwnd', 'equalrect', |
|
607 'extractstrings', 'findclass', 'findglobalcomponent', 'getclass', |
|
608 'groupdescendantswith', 'hextobin', 'identtoint', |
|
609 'initinheritedcomponent', 'inttoident', 'invalidpoint', |
|
610 'isuniqueglobalcomponentname', 'linestart', 'objectbinarytotext', |
|
611 'objectresourcetotext', 'objecttexttobinary', 'objecttexttoresource', |
|
612 'pointsequal', 'readcomponentres', 'readcomponentresex', |
|
613 'readcomponentresfile', 'rect', 'registerclass', 'registerclassalias', |
|
614 'registerclasses', 'registercomponents', 'registerintegerconsts', |
|
615 'registernoicon', 'registernonactivex', 'smallpoint', 'startclassgroup', |
|
616 'teststreamformat', 'unregisterclass', 'unregisterclasses', |
|
617 'unregisterintegerconsts', 'unregistermoduleclasses', |
|
618 'writecomponentresfile' |
|
619 ], |
|
620 'Math': [ |
|
621 'arccos', 'arccosh', 'arccot', 'arccoth', 'arccsc', 'arccsch', 'arcsec', |
|
622 'arcsech', 'arcsin', 'arcsinh', 'arctan2', 'arctanh', 'ceil', |
|
623 'comparevalue', 'cosecant', 'cosh', 'cot', 'cotan', 'coth', 'csc', |
|
624 'csch', 'cycletodeg', 'cycletograd', 'cycletorad', 'degtocycle', |
|
625 'degtograd', 'degtorad', 'divmod', 'doubledecliningbalance', |
|
626 'ensurerange', 'floor', 'frexp', 'futurevalue', 'getexceptionmask', |
|
627 'getprecisionmode', 'getroundmode', 'gradtocycle', 'gradtodeg', |
|
628 'gradtorad', 'hypot', 'inrange', 'interestpayment', 'interestrate', |
|
629 'internalrateofreturn', 'intpower', 'isinfinite', 'isnan', 'iszero', |
|
630 'ldexp', 'lnxp1', 'log10', 'log2', 'logn', 'max', 'maxintvalue', |
|
631 'maxvalue', 'mean', 'meanandstddev', 'min', 'minintvalue', 'minvalue', |
|
632 'momentskewkurtosis', 'netpresentvalue', 'norm', 'numberofperiods', |
|
633 'payment', 'periodpayment', 'poly', 'popnstddev', 'popnvariance', |
|
634 'power', 'presentvalue', 'radtocycle', 'radtodeg', 'radtograd', |
|
635 'randg', 'randomrange', 'roundto', 'samevalue', 'sec', 'secant', |
|
636 'sech', 'setexceptionmask', 'setprecisionmode', 'setroundmode', |
|
637 'sign', 'simpleroundto', 'sincos', 'sinh', 'slndepreciation', 'stddev', |
|
638 'sum', 'sumint', 'sumofsquares', 'sumsandsquares', 'syddepreciation', |
|
639 'tan', 'tanh', 'totalvariance', 'variance' |
|
640 ] |
|
641 } |
|
642 |
|
643 ASM_REGISTERS = set([ |
|
644 'ah', 'al', 'ax', 'bh', 'bl', 'bp', 'bx', 'ch', 'cl', 'cr0', |
|
645 'cr1', 'cr2', 'cr3', 'cr4', 'cs', 'cx', 'dh', 'di', 'dl', 'dr0', |
|
646 'dr1', 'dr2', 'dr3', 'dr4', 'dr5', 'dr6', 'dr7', 'ds', 'dx', |
|
647 'eax', 'ebp', 'ebx', 'ecx', 'edi', 'edx', 'es', 'esi', 'esp', |
|
648 'fs', 'gs', 'mm0', 'mm1', 'mm2', 'mm3', 'mm4', 'mm5', 'mm6', |
|
649 'mm7', 'si', 'sp', 'ss', 'st0', 'st1', 'st2', 'st3', 'st4', 'st5', |
|
650 'st6', 'st7', 'xmm0', 'xmm1', 'xmm2', 'xmm3', 'xmm4', 'xmm5', |
|
651 'xmm6', 'xmm7' |
|
652 ]) |
|
653 |
|
654 ASM_INSTRUCTIONS = set([ |
|
655 'aaa', 'aad', 'aam', 'aas', 'adc', 'add', 'and', 'arpl', 'bound', |
|
656 'bsf', 'bsr', 'bswap', 'bt', 'btc', 'btr', 'bts', 'call', 'cbw', |
|
657 'cdq', 'clc', 'cld', 'cli', 'clts', 'cmc', 'cmova', 'cmovae', |
|
658 'cmovb', 'cmovbe', 'cmovc', 'cmovcxz', 'cmove', 'cmovg', |
|
659 'cmovge', 'cmovl', 'cmovle', 'cmovna', 'cmovnae', 'cmovnb', |
|
660 'cmovnbe', 'cmovnc', 'cmovne', 'cmovng', 'cmovnge', 'cmovnl', |
|
661 'cmovnle', 'cmovno', 'cmovnp', 'cmovns', 'cmovnz', 'cmovo', |
|
662 'cmovp', 'cmovpe', 'cmovpo', 'cmovs', 'cmovz', 'cmp', 'cmpsb', |
|
663 'cmpsd', 'cmpsw', 'cmpxchg', 'cmpxchg486', 'cmpxchg8b', 'cpuid', |
|
664 'cwd', 'cwde', 'daa', 'das', 'dec', 'div', 'emms', 'enter', 'hlt', |
|
665 'ibts', 'icebp', 'idiv', 'imul', 'in', 'inc', 'insb', 'insd', |
|
666 'insw', 'int', 'int01', 'int03', 'int1', 'int3', 'into', 'invd', |
|
667 'invlpg', 'iret', 'iretd', 'iretw', 'ja', 'jae', 'jb', 'jbe', |
|
668 'jc', 'jcxz', 'jcxz', 'je', 'jecxz', 'jg', 'jge', 'jl', 'jle', |
|
669 'jmp', 'jna', 'jnae', 'jnb', 'jnbe', 'jnc', 'jne', 'jng', 'jnge', |
|
670 'jnl', 'jnle', 'jno', 'jnp', 'jns', 'jnz', 'jo', 'jp', 'jpe', |
|
671 'jpo', 'js', 'jz', 'lahf', 'lar', 'lcall', 'lds', 'lea', 'leave', |
|
672 'les', 'lfs', 'lgdt', 'lgs', 'lidt', 'ljmp', 'lldt', 'lmsw', |
|
673 'loadall', 'loadall286', 'lock', 'lodsb', 'lodsd', 'lodsw', |
|
674 'loop', 'loope', 'loopne', 'loopnz', 'loopz', 'lsl', 'lss', 'ltr', |
|
675 'mov', 'movd', 'movq', 'movsb', 'movsd', 'movsw', 'movsx', |
|
676 'movzx', 'mul', 'neg', 'nop', 'not', 'or', 'out', 'outsb', 'outsd', |
|
677 'outsw', 'pop', 'popa', 'popad', 'popaw', 'popf', 'popfd', 'popfw', |
|
678 'push', 'pusha', 'pushad', 'pushaw', 'pushf', 'pushfd', 'pushfw', |
|
679 'rcl', 'rcr', 'rdmsr', 'rdpmc', 'rdshr', 'rdtsc', 'rep', 'repe', |
|
680 'repne', 'repnz', 'repz', 'ret', 'retf', 'retn', 'rol', 'ror', |
|
681 'rsdc', 'rsldt', 'rsm', 'sahf', 'sal', 'salc', 'sar', 'sbb', |
|
682 'scasb', 'scasd', 'scasw', 'seta', 'setae', 'setb', 'setbe', |
|
683 'setc', 'setcxz', 'sete', 'setg', 'setge', 'setl', 'setle', |
|
684 'setna', 'setnae', 'setnb', 'setnbe', 'setnc', 'setne', 'setng', |
|
685 'setnge', 'setnl', 'setnle', 'setno', 'setnp', 'setns', 'setnz', |
|
686 'seto', 'setp', 'setpe', 'setpo', 'sets', 'setz', 'sgdt', 'shl', |
|
687 'shld', 'shr', 'shrd', 'sidt', 'sldt', 'smi', 'smint', 'smintold', |
|
688 'smsw', 'stc', 'std', 'sti', 'stosb', 'stosd', 'stosw', 'str', |
|
689 'sub', 'svdc', 'svldt', 'svts', 'syscall', 'sysenter', 'sysexit', |
|
690 'sysret', 'test', 'ud1', 'ud2', 'umov', 'verr', 'verw', 'wait', |
|
691 'wbinvd', 'wrmsr', 'wrshr', 'xadd', 'xbts', 'xchg', 'xlat', |
|
692 'xlatb', 'xor' |
|
693 ]) |
|
694 |
|
695 def __init__(self, **options): |
|
696 Lexer.__init__(self, **options) |
|
697 self.keywords = set() |
|
698 if get_bool_opt(options, 'turbopascal', True): |
|
699 self.keywords.update(self.TURBO_PASCAL_KEYWORDS) |
|
700 if get_bool_opt(options, 'delphi', True): |
|
701 self.keywords.update(self.DELPHI_KEYWORDS) |
|
702 if get_bool_opt(options, 'freepascal', True): |
|
703 self.keywords.update(self.FREE_PASCAL_KEYWORDS) |
|
704 self.builtins = set() |
|
705 for unit in get_list_opt(options, 'units', list(self.BUILTIN_UNITS.keys())): |
|
706 self.builtins.update(self.BUILTIN_UNITS[unit]) |
|
707 |
|
708 def get_tokens_unprocessed(self, text): |
|
709 scanner = Scanner(text, re.DOTALL | re.MULTILINE | re.IGNORECASE) |
|
710 stack = ['initial'] |
|
711 in_function_block = False |
|
712 in_property_block = False |
|
713 was_dot = False |
|
714 next_token_is_function = False |
|
715 next_token_is_property = False |
|
716 collect_labels = False |
|
717 block_labels = set() |
|
718 brace_balance = [0, 0] |
|
719 |
|
720 while not scanner.eos: |
|
721 token = Error |
|
722 |
|
723 if stack[-1] == 'initial': |
|
724 if scanner.scan(r'\s+'): |
|
725 token = Text |
|
726 elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'): |
|
727 if scanner.match.startswith('$'): |
|
728 token = Comment.Preproc |
|
729 else: |
|
730 token = Comment.Multiline |
|
731 elif scanner.scan(r'//.*?$'): |
|
732 token = Comment.Single |
|
733 elif scanner.scan(r'[-+*\/=<>:;,.@\^]'): |
|
734 token = Operator |
|
735 # stop label highlighting on next ";" |
|
736 if collect_labels and scanner.match == ';': |
|
737 collect_labels = False |
|
738 elif scanner.scan(r'[\(\)\[\]]+'): |
|
739 token = Punctuation |
|
740 # abort function naming ``foo = Function(...)`` |
|
741 next_token_is_function = False |
|
742 # if we are in a function block we count the open |
|
743 # braces because ootherwise it's impossible to |
|
744 # determine the end of the modifier context |
|
745 if in_function_block or in_property_block: |
|
746 if scanner.match == '(': |
|
747 brace_balance[0] += 1 |
|
748 elif scanner.match == ')': |
|
749 brace_balance[0] -= 1 |
|
750 elif scanner.match == '[': |
|
751 brace_balance[1] += 1 |
|
752 elif scanner.match == ']': |
|
753 brace_balance[1] -= 1 |
|
754 elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'): |
|
755 lowercase_name = scanner.match.lower() |
|
756 if lowercase_name == 'result': |
|
757 token = Name.Builtin.Pseudo |
|
758 elif lowercase_name in self.keywords: |
|
759 token = Keyword |
|
760 # if we are in a special block and a |
|
761 # block ending keyword occours (and the parenthesis |
|
762 # is balanced) we end the current block context |
|
763 if (in_function_block or in_property_block) and \ |
|
764 lowercase_name in self.BLOCK_KEYWORDS and \ |
|
765 brace_balance[0] <= 0 and \ |
|
766 brace_balance[1] <= 0: |
|
767 in_function_block = False |
|
768 in_property_block = False |
|
769 brace_balance = [0, 0] |
|
770 block_labels = set() |
|
771 if lowercase_name in ('label', 'goto'): |
|
772 collect_labels = True |
|
773 elif lowercase_name == 'asm': |
|
774 stack.append('asm') |
|
775 elif lowercase_name == 'property': |
|
776 in_property_block = True |
|
777 next_token_is_property = True |
|
778 elif lowercase_name in ('procedure', 'operator', |
|
779 'function', 'constructor', |
|
780 'destructor'): |
|
781 in_function_block = True |
|
782 next_token_is_function = True |
|
783 # we are in a function block and the current name |
|
784 # is in the set of registered modifiers. highlight |
|
785 # it as pseudo keyword |
|
786 elif in_function_block and \ |
|
787 lowercase_name in self.FUNCTION_MODIFIERS: |
|
788 token = Keyword.Pseudo |
|
789 # if we are in a property highlight some more |
|
790 # modifiers |
|
791 elif in_property_block and \ |
|
792 lowercase_name in ('read', 'write'): |
|
793 token = Keyword.Pseudo |
|
794 next_token_is_function = True |
|
795 # if the last iteration set next_token_is_function |
|
796 # to true we now want this name highlighted as |
|
797 # function. so do that and reset the state |
|
798 elif next_token_is_function: |
|
799 # Look if the next token is a dot. If yes it's |
|
800 # not a function, but a class name and the |
|
801 # part after the dot a function name |
|
802 if scanner.test(r'\s*\.\s*'): |
|
803 token = Name.Class |
|
804 # it's not a dot, our job is done |
|
805 else: |
|
806 token = Name.Function |
|
807 next_token_is_function = False |
|
808 # same for properties |
|
809 elif next_token_is_property: |
|
810 token = Name.Property |
|
811 next_token_is_property = False |
|
812 # Highlight this token as label and add it |
|
813 # to the list of known labels |
|
814 elif collect_labels: |
|
815 token = Name.Label |
|
816 block_labels.add(scanner.match.lower()) |
|
817 # name is in list of known labels |
|
818 elif lowercase_name in block_labels: |
|
819 token = Name.Label |
|
820 elif lowercase_name in self.BUILTIN_TYPES: |
|
821 token = Keyword.Type |
|
822 elif lowercase_name in self.DIRECTIVES: |
|
823 token = Keyword.Pseudo |
|
824 # builtins are just builtins if the token |
|
825 # before isn't a dot |
|
826 elif not was_dot and lowercase_name in self.builtins: |
|
827 token = Name.Builtin |
|
828 else: |
|
829 token = Name |
|
830 elif scanner.scan(r"'"): |
|
831 token = String |
|
832 stack.append('string') |
|
833 elif scanner.scan(r'\#(\d+|\$[0-9A-Fa-f]+)'): |
|
834 token = String.Char |
|
835 elif scanner.scan(r'\$[0-9A-Fa-f]+'): |
|
836 token = Number.Hex |
|
837 elif scanner.scan(r'\d+(?![eE]|\.[^.])'): |
|
838 token = Number.Integer |
|
839 elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'): |
|
840 token = Number.Float |
|
841 else: |
|
842 # if the stack depth is deeper than once, pop |
|
843 if len(stack) > 1: |
|
844 stack.pop() |
|
845 scanner.get_char() |
|
846 |
|
847 elif stack[-1] == 'string': |
|
848 if scanner.scan(r"''"): |
|
849 token = String.Escape |
|
850 elif scanner.scan(r"'"): |
|
851 token = String |
|
852 stack.pop() |
|
853 elif scanner.scan(r"[^']*"): |
|
854 token = String |
|
855 else: |
|
856 scanner.get_char() |
|
857 stack.pop() |
|
858 |
|
859 elif stack[-1] == 'asm': |
|
860 if scanner.scan(r'\s+'): |
|
861 token = Text |
|
862 elif scanner.scan(r'end'): |
|
863 token = Keyword |
|
864 stack.pop() |
|
865 elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'): |
|
866 if scanner.match.startswith('$'): |
|
867 token = Comment.Preproc |
|
868 else: |
|
869 token = Comment.Multiline |
|
870 elif scanner.scan(r'//.*?$'): |
|
871 token = Comment.Single |
|
872 elif scanner.scan(r"'"): |
|
873 token = String |
|
874 stack.append('string') |
|
875 elif scanner.scan(r'@@[A-Za-z_][A-Za-z_0-9]*'): |
|
876 token = Name.Label |
|
877 elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'): |
|
878 lowercase_name = scanner.match.lower() |
|
879 if lowercase_name in self.ASM_INSTRUCTIONS: |
|
880 token = Keyword |
|
881 elif lowercase_name in self.ASM_REGISTERS: |
|
882 token = Name.Builtin |
|
883 else: |
|
884 token = Name |
|
885 elif scanner.scan(r'[-+*\/=<>:;,.@\^]+'): |
|
886 token = Operator |
|
887 elif scanner.scan(r'[\(\)\[\]]+'): |
|
888 token = Punctuation |
|
889 elif scanner.scan(r'\$[0-9A-Fa-f]+'): |
|
890 token = Number.Hex |
|
891 elif scanner.scan(r'\d+(?![eE]|\.[^.])'): |
|
892 token = Number.Integer |
|
893 elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'): |
|
894 token = Number.Float |
|
895 else: |
|
896 scanner.get_char() |
|
897 stack.pop() |
|
898 |
|
899 # save the dot!!!11 |
|
900 if scanner.match.strip(): |
|
901 was_dot = scanner.match == '.' |
|
902 yield scanner.start_pos, token, scanner.match or '' |
|
903 |
|
904 |
|
905 class DylanLexer(RegexLexer): |
|
906 """ |
|
907 For the `Dylan <http://www.opendylan.org/>`_ language. |
|
908 |
|
909 *New in Pygments 0.7.* |
|
910 """ |
|
911 |
|
912 name = 'Dylan' |
|
913 aliases = ['dylan'] |
|
914 filenames = ['*.dylan', '*.dyl', '*.intr'] |
|
915 mimetypes = ['text/x-dylan'] |
|
916 |
|
917 flags = re.IGNORECASE |
|
918 |
|
919 builtins = set([ |
|
920 'subclass', 'abstract', 'block', 'concrete', 'constant', 'class', |
|
921 'compiler-open', 'compiler-sideways', 'domain', 'dynamic', |
|
922 'each-subclass', 'exception', 'exclude', 'function', 'generic', |
|
923 'handler', 'inherited', 'inline', 'inline-only', 'instance', |
|
924 'interface', 'import', 'keyword', 'library', 'macro', 'method', |
|
925 'module', 'open', 'primary', 'required', 'sealed', 'sideways', |
|
926 'singleton', 'slot', 'thread', 'variable', 'virtual']) |
|
927 |
|
928 keywords = set([ |
|
929 'above', 'afterwards', 'begin', 'below', 'by', 'case', 'cleanup', |
|
930 'create', 'define', 'else', 'elseif', 'end', 'export', 'finally', |
|
931 'for', 'from', 'if', 'in', 'let', 'local', 'otherwise', 'rename', |
|
932 'select', 'signal', 'then', 'to', 'unless', 'until', 'use', 'when', |
|
933 'while']) |
|
934 |
|
935 operators = set([ |
|
936 '~', '+', '-', '*', '|', '^', '=', '==', '~=', '~==', '<', '<=', |
|
937 '>', '>=', '&', '|']) |
|
938 |
|
939 functions = set([ |
|
940 'abort', 'abs', 'add', 'add!', 'add-method', 'add-new', 'add-new!', |
|
941 'all-superclasses', 'always', 'any?', 'applicable-method?', 'apply', |
|
942 'aref', 'aref-setter', 'as', 'as-lowercase', 'as-lowercase!', |
|
943 'as-uppercase', 'as-uppercase!', 'ash', 'backward-iteration-protocol', |
|
944 'break', 'ceiling', 'ceiling/', 'cerror', 'check-type', 'choose', |
|
945 'choose-by', 'complement', 'compose', 'concatenate', 'concatenate-as', |
|
946 'condition-format-arguments', 'condition-format-string', 'conjoin', |
|
947 'copy-sequence', 'curry', 'default-handler', 'dimension', 'dimensions', |
|
948 'direct-subclasses', 'direct-superclasses', 'disjoin', 'do', |
|
949 'do-handlers', 'element', 'element-setter', 'empty?', 'error', 'even?', |
|
950 'every?', 'false-or', 'fill!', 'find-key', 'find-method', 'first', |
|
951 'first-setter', 'floor', 'floor/', 'forward-iteration-protocol', |
|
952 'function-arguments', 'function-return-values', |
|
953 'function-specializers', 'gcd', 'generic-function-mandatory-keywords', |
|
954 'generic-function-methods', 'head', 'head-setter', 'identity', |
|
955 'initialize', 'instance?', 'integral?', 'intersection', |
|
956 'key-sequence', 'key-test', 'last', 'last-setter', 'lcm', 'limited', |
|
957 'list', 'logand', 'logbit?', 'logior', 'lognot', 'logxor', 'make', |
|
958 'map', 'map-as', 'map-into', 'max', 'member?', 'merge-hash-codes', |
|
959 'min', 'modulo', 'negative', 'negative?', 'next-method', |
|
960 'object-class', 'object-hash', 'odd?', 'one-of', 'pair', 'pop', |
|
961 'pop-last', 'positive?', 'push', 'push-last', 'range', 'rank', |
|
962 'rcurry', 'reduce', 'reduce1', 'remainder', 'remove', 'remove!', |
|
963 'remove-duplicates', 'remove-duplicates!', 'remove-key!', |
|
964 'remove-method', 'replace-elements!', 'replace-subsequence!', |
|
965 'restart-query', 'return-allowed?', 'return-description', |
|
966 'return-query', 'reverse', 'reverse!', 'round', 'round/', |
|
967 'row-major-index', 'second', 'second-setter', 'shallow-copy', |
|
968 'signal', 'singleton', 'size', 'size-setter', 'slot-initialized?', |
|
969 'sort', 'sort!', 'sorted-applicable-methods', 'subsequence-position', |
|
970 'subtype?', 'table-protocol', 'tail', 'tail-setter', 'third', |
|
971 'third-setter', 'truncate', 'truncate/', 'type-error-expected-type', |
|
972 'type-error-value', 'type-for-copy', 'type-union', 'union', 'values', |
|
973 'vector', 'zero?']) |
|
974 |
|
975 valid_name = '\\\\?[a-zA-Z0-9' + re.escape('!&*<>|^$%@_-+~?/=') + ']+' |
|
976 |
|
977 def get_tokens_unprocessed(self, text): |
|
978 for index, token, value in RegexLexer.get_tokens_unprocessed(self, text): |
|
979 if token is Name: |
|
980 lowercase_value = value.lower() |
|
981 if lowercase_value in self.builtins: |
|
982 yield index, Name.Builtin, value |
|
983 continue |
|
984 if lowercase_value in self.keywords: |
|
985 yield index, Keyword, value |
|
986 continue |
|
987 if lowercase_value in self.functions: |
|
988 yield index, Name.Builtin, value |
|
989 continue |
|
990 if lowercase_value in self.operators: |
|
991 yield index, Operator, value |
|
992 continue |
|
993 yield index, token, value |
|
994 |
|
995 tokens = { |
|
996 'root': [ |
|
997 # Whitespace |
|
998 (r'\s+', Text), |
|
999 |
|
1000 # single line comment |
|
1001 (r'//.*?\n', Comment.Single), |
|
1002 |
|
1003 # lid header |
|
1004 (r'([A-Za-z0-9-]+)(:)([ \t]*)(.*(?:\n[ \t].+)*)', |
|
1005 bygroups(Name.Attribute, Operator, Text, String)), |
|
1006 |
|
1007 ('', Text, 'code') # no header match, switch to code |
|
1008 ], |
|
1009 'code': [ |
|
1010 # Whitespace |
|
1011 (r'\s+', Text), |
|
1012 |
|
1013 # single line comment |
|
1014 (r'//.*?\n', Comment.Single), |
|
1015 |
|
1016 # multi-line comment |
|
1017 (r'/\*', Comment.Multiline, 'comment'), |
|
1018 |
|
1019 # strings and characters |
|
1020 (r'"', String, 'string'), |
|
1021 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char), |
|
1022 |
|
1023 # binary integer |
|
1024 (r'#[bB][01]+', Number), |
|
1025 |
|
1026 # octal integer |
|
1027 (r'#[oO][0-7]+', Number.Oct), |
|
1028 |
|
1029 # floating point |
|
1030 (r'[-+]?(\d*\.\d+(e[-+]?\d+)?|\d+(\.\d*)?e[-+]?\d+)', Number.Float), |
|
1031 |
|
1032 # decimal integer |
|
1033 (r'[-+]?\d+', Number.Integer), |
|
1034 |
|
1035 # hex integer |
|
1036 (r'#[xX][0-9a-fA-F]+', Number.Hex), |
|
1037 |
|
1038 # Macro parameters |
|
1039 (r'(\?' + valid_name + ')(:)' |
|
1040 r'(token|name|variable|expression|body|case-body|\*)', |
|
1041 bygroups(Name.Tag, Operator, Name.Builtin)), |
|
1042 (r'(\?)(:)(token|name|variable|expression|body|case-body|\*)', |
|
1043 bygroups(Name.Tag, Operator, Name.Builtin)), |
|
1044 (r'\?' + valid_name, Name.Tag), |
|
1045 |
|
1046 # Punctuation |
|
1047 (r'(=>|::|#\(|#\[|##|\?|\?\?|\?=|[(){}\[\],\.;])', Punctuation), |
|
1048 |
|
1049 # Most operators are picked up as names and then re-flagged. |
|
1050 # This one isn't valid in a name though, so we pick it up now. |
|
1051 (r':=', Operator), |
|
1052 |
|
1053 # Pick up #t / #f before we match other stuff with #. |
|
1054 (r'#[tf]', Literal), |
|
1055 |
|
1056 # #"foo" style keywords |
|
1057 (r'#"', String.Symbol, 'keyword'), |
|
1058 |
|
1059 # #rest, #key, #all-keys, etc. |
|
1060 (r'#[a-zA-Z0-9-]+', Keyword), |
|
1061 |
|
1062 # required-init-keyword: style keywords. |
|
1063 (valid_name + ':', Keyword), |
|
1064 |
|
1065 # class names |
|
1066 (r'<' + valid_name + '>', Name.Class), |
|
1067 |
|
1068 # define variable forms. |
|
1069 (r'\*' + valid_name + '\*', Name.Variable.Global), |
|
1070 |
|
1071 # define constant forms. |
|
1072 (r'\$' + valid_name, Name.Constant), |
|
1073 |
|
1074 # everything else. We re-flag some of these in the method above. |
|
1075 (valid_name, Name), |
|
1076 ], |
|
1077 'comment': [ |
|
1078 (r'[^*/]', Comment.Multiline), |
|
1079 (r'/\*', Comment.Multiline, '#push'), |
|
1080 (r'\*/', Comment.Multiline, '#pop'), |
|
1081 (r'[*/]', Comment.Multiline) |
|
1082 ], |
|
1083 'keyword': [ |
|
1084 (r'"', String.Symbol, '#pop'), |
|
1085 (r'[^\\"]+', String.Symbol), # all other characters |
|
1086 ], |
|
1087 'string': [ |
|
1088 (r'"', String, '#pop'), |
|
1089 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
1090 (r'[^\\"\n]+', String), # all other characters |
|
1091 (r'\\\n', String), # line continuation |
|
1092 (r'\\', String), # stray backslash |
|
1093 ] |
|
1094 } |
|
1095 |
|
1096 |
|
1097 class DylanLidLexer(RegexLexer): |
|
1098 """ |
|
1099 For Dylan LID (Library Interchange Definition) files. |
|
1100 |
|
1101 *New in Pygments 1.6.* |
|
1102 """ |
|
1103 |
|
1104 name = 'DylanLID' |
|
1105 aliases = ['dylan-lid', 'lid'] |
|
1106 filenames = ['*.lid', '*.hdp'] |
|
1107 mimetypes = ['text/x-dylan-lid'] |
|
1108 |
|
1109 flags = re.IGNORECASE |
|
1110 |
|
1111 tokens = { |
|
1112 'root': [ |
|
1113 # Whitespace |
|
1114 (r'\s+', Text), |
|
1115 |
|
1116 # single line comment |
|
1117 (r'//.*?\n', Comment.Single), |
|
1118 |
|
1119 # lid header |
|
1120 (r'(.*?)(:)([ \t]*)(.*(?:\n[ \t].+)*)', |
|
1121 bygroups(Name.Attribute, Operator, Text, String)), |
|
1122 ] |
|
1123 } |
|
1124 |
|
1125 |
|
1126 class DylanConsoleLexer(Lexer): |
|
1127 """ |
|
1128 For Dylan interactive console output like: |
|
1129 |
|
1130 .. sourcecode:: dylan-console |
|
1131 |
|
1132 ? let a = 1; |
|
1133 => 1 |
|
1134 ? a |
|
1135 => 1 |
|
1136 |
|
1137 This is based on a copy of the RubyConsoleLexer. |
|
1138 |
|
1139 *New in Pygments 1.6.* |
|
1140 """ |
|
1141 name = 'Dylan session' |
|
1142 aliases = ['dylan-console', 'dylan-repl'] |
|
1143 filenames = ['*.dylan-console'] |
|
1144 mimetypes = ['text/x-dylan-console'] |
|
1145 |
|
1146 _line_re = re.compile('.*?\n') |
|
1147 _prompt_re = re.compile('\?| ') |
|
1148 |
|
1149 def get_tokens_unprocessed(self, text): |
|
1150 dylexer = DylanLexer(**self.options) |
|
1151 |
|
1152 curcode = '' |
|
1153 insertions = [] |
|
1154 for match in self._line_re.finditer(text): |
|
1155 line = match.group() |
|
1156 m = self._prompt_re.match(line) |
|
1157 if m is not None: |
|
1158 end = m.end() |
|
1159 insertions.append((len(curcode), |
|
1160 [(0, Generic.Prompt, line[:end])])) |
|
1161 curcode += line[end:] |
|
1162 else: |
|
1163 if curcode: |
|
1164 for item in do_insertions(insertions, |
|
1165 dylexer.get_tokens_unprocessed(curcode)): |
|
1166 yield item |
|
1167 curcode = '' |
|
1168 insertions = [] |
|
1169 yield match.start(), Generic.Output, line |
|
1170 if curcode: |
|
1171 for item in do_insertions(insertions, |
|
1172 dylexer.get_tokens_unprocessed(curcode)): |
|
1173 yield item |
|
1174 |
|
1175 |
|
1176 def objective(baselexer): |
|
1177 """ |
|
1178 Generate a subclass of baselexer that accepts the Objective-C syntax |
|
1179 extensions. |
|
1180 """ |
|
1181 |
|
1182 # Have to be careful not to accidentally match JavaDoc/Doxygen syntax here, |
|
1183 # since that's quite common in ordinary C/C++ files. It's OK to match |
|
1184 # JavaDoc/Doxygen keywords that only apply to Objective-C, mind. |
|
1185 # |
|
1186 # The upshot of this is that we CANNOT match @class or @interface |
|
1187 _oc_keywords = re.compile(r'@(?:end|implementation|protocol)') |
|
1188 |
|
1189 # Matches [ <ws>? identifier <ws> ( identifier <ws>? ] | identifier? : ) |
|
1190 # (note the identifier is *optional* when there is a ':'!) |
|
1191 _oc_message = re.compile(r'\[\s*[a-zA-Z_][a-zA-Z0-9_]*\s+' |
|
1192 r'(?:[a-zA-Z_][a-zA-Z0-9_]*\s*\]|' |
|
1193 r'(?:[a-zA-Z_][a-zA-Z0-9_]*)?:)') |
|
1194 |
|
1195 class GeneratedObjectiveCVariant(baselexer): |
|
1196 """ |
|
1197 Implements Objective-C syntax on top of an existing C family lexer. |
|
1198 """ |
|
1199 |
|
1200 tokens = { |
|
1201 'statements': [ |
|
1202 (r'@"', String, 'string'), |
|
1203 (r"@'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", |
|
1204 String.Char), |
|
1205 (r'@(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), |
|
1206 (r'@(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
1207 (r'@0x[0-9a-fA-F]+[Ll]?', Number.Hex), |
|
1208 (r'@0[0-7]+[Ll]?', Number.Oct), |
|
1209 (r'@\d+[Ll]?', Number.Integer), |
|
1210 (r'(in|@selector|@private|@protected|@public|@encode|' |
|
1211 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' |
|
1212 r'@synthesize|@dynamic|@optional)\b', Keyword), |
|
1213 (r'(id|Class|IMP|SEL|BOOL|IBOutlet|IBAction|unichar)\b', |
|
1214 Keyword.Type), |
|
1215 (r'@(true|false|YES|NO)\n', Name.Builtin), |
|
1216 (r'(YES|NO|nil)\b', Name.Builtin), |
|
1217 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), |
|
1218 ('#pop', 'oc_classname')), |
|
1219 (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text), |
|
1220 ('#pop', 'oc_forward_classname')), |
|
1221 inherit, |
|
1222 ], |
|
1223 'oc_classname' : [ |
|
1224 # interface definition that inherits |
|
1225 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?', |
|
1226 bygroups(Name.Class, Text, Name.Class), '#pop'), |
|
1227 # interface definition for a category |
|
1228 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\([a-zA-Z$_][a-zA-Z0-9$_]*\))', |
|
1229 bygroups(Name.Class, Text, Name.Label), '#pop'), |
|
1230 # simple interface / implementation |
|
1231 ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop') |
|
1232 ], |
|
1233 'oc_forward_classname' : [ |
|
1234 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*,\s*)', |
|
1235 bygroups(Name.Class, Text), 'oc_forward_classname'), |
|
1236 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*;?)', |
|
1237 bygroups(Name.Class, Text), '#pop') |
|
1238 ], |
|
1239 'root': [ |
|
1240 # methods |
|
1241 (r'^([-+])(\s*)' # method marker |
|
1242 r'(\(.*?\))?(\s*)' # return type |
|
1243 r'([a-zA-Z$_][a-zA-Z0-9$_]*:?)', # begin of method name |
|
1244 bygroups(Keyword, Text, using(this), |
|
1245 Text, Name.Function), |
|
1246 'method'), |
|
1247 inherit, |
|
1248 ], |
|
1249 'method': [ |
|
1250 include('whitespace'), |
|
1251 # TODO unsure if ellipses are allowed elsewhere, see |
|
1252 # discussion in Issue 789 |
|
1253 (r',', Punctuation), |
|
1254 (r'\.\.\.', Punctuation), |
|
1255 (r'(\(.*?\))([a-zA-Z$_][a-zA-Z0-9$_]*)', bygroups(using(this), |
|
1256 Name.Variable)), |
|
1257 (r'[a-zA-Z$_][a-zA-Z0-9$_]*:', Name.Function), |
|
1258 (';', Punctuation, '#pop'), |
|
1259 ('{', Punctuation, 'function'), |
|
1260 ('', Text, '#pop'), |
|
1261 ], |
|
1262 } |
|
1263 |
|
1264 def analyse_text(text): |
|
1265 if _oc_keywords.search(text): |
|
1266 return 1.0 |
|
1267 elif '@"' in text: # strings |
|
1268 return 0.8 |
|
1269 elif _oc_message.search(text): |
|
1270 return 0.8 |
|
1271 return 0 |
|
1272 |
|
1273 return GeneratedObjectiveCVariant |
|
1274 |
|
1275 |
|
1276 class ObjectiveCLexer(objective(CLexer)): |
|
1277 """ |
|
1278 For Objective-C source code with preprocessor directives. |
|
1279 """ |
|
1280 |
|
1281 name = 'Objective-C' |
|
1282 aliases = ['objective-c', 'objectivec', 'obj-c', 'objc'] |
|
1283 filenames = ['*.m', '*.h'] |
|
1284 mimetypes = ['text/x-objective-c'] |
|
1285 priority = 0.05 # Lower than C |
|
1286 |
|
1287 |
|
1288 class ObjectiveCppLexer(objective(CppLexer)): |
|
1289 """ |
|
1290 For Objective-C++ source code with preprocessor directives. |
|
1291 """ |
|
1292 |
|
1293 name = 'Objective-C++' |
|
1294 aliases = ['objective-c++', 'objectivec++', 'obj-c++', 'objc++'] |
|
1295 filenames = ['*.mm', '*.hh'] |
|
1296 mimetypes = ['text/x-objective-c++'] |
|
1297 priority = 0.05 # Lower than C++ |
|
1298 |
|
1299 |
|
1300 class FortranLexer(RegexLexer): |
|
1301 """ |
|
1302 Lexer for FORTRAN 90 code. |
|
1303 |
|
1304 *New in Pygments 0.10.* |
|
1305 """ |
|
1306 name = 'Fortran' |
|
1307 aliases = ['fortran'] |
|
1308 filenames = ['*.f', '*.f90', '*.F', '*.F90'] |
|
1309 mimetypes = ['text/x-fortran'] |
|
1310 flags = re.IGNORECASE |
|
1311 |
|
1312 # Data Types: INTEGER, REAL, COMPLEX, LOGICAL, CHARACTER and DOUBLE PRECISION |
|
1313 # Operators: **, *, +, -, /, <, >, <=, >=, ==, /= |
|
1314 # Logical (?): NOT, AND, OR, EQV, NEQV |
|
1315 |
|
1316 # Builtins: |
|
1317 # http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Table-of-Intrinsic-Functions.html |
|
1318 |
|
1319 tokens = { |
|
1320 'root': [ |
|
1321 (r'!.*\n', Comment), |
|
1322 include('strings'), |
|
1323 include('core'), |
|
1324 (r'[a-z][a-z0-9_]*', Name.Variable), |
|
1325 include('nums'), |
|
1326 (r'[\s]+', Text), |
|
1327 ], |
|
1328 'core': [ |
|
1329 # Statements |
|
1330 (r'\b(ABSTRACT|ACCEPT|ALLOCATABLE|ALLOCATE|ARRAY|ASSIGN|ASYNCHRONOUS|' |
|
1331 r'BACKSPACE|BIND|BLOCK( DATA)?|BYTE|CALL|CASE|CLASS|CLOSE|COMMON|CONTAINS|' |
|
1332 r'CONTINUE|CYCLE|DATA|DEALLOCATE|DECODE|DEFERRED|DIMENSION|DO|' |
|
1333 r'ELEMENTAL|ELSE|ENCODE|END( FILE)?|ENDIF|ENTRY|ENUMERATOR|EQUIVALENCE|' |
|
1334 r'EXIT|EXTERNAL|EXTRINSIC|FINAL|FORALL|FORMAT|FUNCTION|GENERIC|' |
|
1335 r'GOTO|IF|IMPLICIT|IMPORT|INCLUDE|INQUIRE|INTENT|INTERFACE|' |
|
1336 r'INTRINSIC|MODULE|NAMELIST|NULLIFY|NONE|NON_INTRINSIC|' |
|
1337 r'NON_OVERRIDABLE|NOPASS|OPEN|OPTIONAL|OPTIONS|PARAMETER|PASS|' |
|
1338 r'PAUSE|POINTER|PRINT|PRIVATE|PROGRAM|PROTECTED|PUBLIC|PURE|READ|' |
|
1339 r'RECURSIVE|RESULT|RETURN|REWIND|SAVE|SELECT|SEQUENCE|STOP|SUBROUTINE|' |
|
1340 r'TARGET|THEN|TYPE|USE|VALUE|VOLATILE|WHERE|WRITE|WHILE)\s*\b', |
|
1341 Keyword), |
|
1342 |
|
1343 # Data Types |
|
1344 (r'\b(CHARACTER|COMPLEX|DOUBLE PRECISION|DOUBLE COMPLEX|INTEGER|' |
|
1345 r'LOGICAL|REAL|C_INT|C_SHORT|C_LONG|C_LONG_LONG|C_SIGNED_CHAR|' |
|
1346 r'C_SIZE_T|C_INT8_T|C_INT16_T|C_INT32_T|C_INT64_T|C_INT_LEAST8_T|' |
|
1347 r'C_INT_LEAST16_T|C_INT_LEAST32_T|C_INT_LEAST64_T|C_INT_FAST8_T|' |
|
1348 r'C_INT_FAST16_T|C_INT_FAST32_T|C_INT_FAST64_T|C_INTMAX_T|' |
|
1349 r'C_INTPTR_T|C_FLOAT|C_DOUBLE|C_LONG_DOUBLE|C_FLOAT_COMPLEX|' |
|
1350 r'C_DOUBLE_COMPLEX|C_LONG_DOUBLE_COMPLEX|C_BOOL|C_CHAR|C_PTR|' |
|
1351 r'C_FUNPTR)\s*\b', |
|
1352 Keyword.Type), |
|
1353 |
|
1354 # Operators |
|
1355 (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator), |
|
1356 |
|
1357 (r'(::)', Keyword.Declaration), |
|
1358 |
|
1359 (r'[(),:&%;]', Punctuation), |
|
1360 |
|
1361 # Intrinsics |
|
1362 (r'\b(Abort|Abs|Access|AChar|ACos|AdjustL|AdjustR|AImag|AInt|Alarm|' |
|
1363 r'All|Allocated|ALog|AMax|AMin|AMod|And|ANInt|Any|ASin|Associated|' |
|
1364 r'ATan|BesJ|BesJN|BesY|BesYN|Bit_Size|BTest|CAbs|CCos|Ceiling|' |
|
1365 r'CExp|Char|ChDir|ChMod|CLog|Cmplx|Command_Argument_Count|Complex|' |
|
1366 r'Conjg|Cos|CosH|Count|CPU_Time|CShift|CSin|CSqRt|CTime|C_Funloc|' |
|
1367 r'C_Loc|C_Associated|C_Null_Ptr|C_Null_Funptr|C_F_Pointer|' |
|
1368 r'C_Null_Char|C_Alert|C_Backspace|C_Form_Feed|C_New_Line|' |
|
1369 r'C_Carriage_Return|C_Horizontal_Tab|C_Vertical_Tab|' |
|
1370 r'DAbs|DACos|DASin|DATan|Date_and_Time|DbesJ|' |
|
1371 r'DbesJ|DbesJN|DbesY|DbesY|DbesYN|Dble|DCos|DCosH|DDiM|DErF|DErFC|' |
|
1372 r'DExp|Digits|DiM|DInt|DLog|DLog|DMax|DMin|DMod|DNInt|Dot_Product|' |
|
1373 r'DProd|DSign|DSinH|DSin|DSqRt|DTanH|DTan|DTime|EOShift|Epsilon|' |
|
1374 r'ErF|ErFC|ETime|Exit|Exp|Exponent|Extends_Type_Of|FDate|FGet|' |
|
1375 r'FGetC|Float|Floor|Flush|FNum|FPutC|FPut|Fraction|FSeek|FStat|' |
|
1376 r'FTell|GError|GetArg|Get_Command|Get_Command_Argument|' |
|
1377 r'Get_Environment_Variable|GetCWD|GetEnv|GetGId|GetLog|GetPId|' |
|
1378 r'GetUId|GMTime|HostNm|Huge|IAbs|IAChar|IAnd|IArgC|IBClr|IBits|' |
|
1379 r'IBSet|IChar|IDate|IDiM|IDInt|IDNInt|IEOr|IErrNo|IFix|Imag|' |
|
1380 r'ImagPart|Index|Int|IOr|IRand|IsaTty|IShft|IShftC|ISign|' |
|
1381 r'Iso_C_Binding|Is_Iostat_End|Is_Iostat_Eor|ITime|Kill|Kind|' |
|
1382 r'LBound|Len|Len_Trim|LGe|LGt|Link|LLe|LLt|LnBlnk|Loc|Log|' |
|
1383 r'Logical|Long|LShift|LStat|LTime|MatMul|Max|MaxExponent|MaxLoc|' |
|
1384 r'MaxVal|MClock|Merge|Move_Alloc|Min|MinExponent|MinLoc|MinVal|' |
|
1385 r'Mod|Modulo|MvBits|Nearest|New_Line|NInt|Not|Or|Pack|PError|' |
|
1386 r'Precision|Present|Product|Radix|Rand|Random_Number|Random_Seed|' |
|
1387 r'Range|Real|RealPart|Rename|Repeat|Reshape|RRSpacing|RShift|' |
|
1388 r'Same_Type_As|Scale|Scan|Second|Selected_Int_Kind|' |
|
1389 r'Selected_Real_Kind|Set_Exponent|Shape|Short|Sign|Signal|SinH|' |
|
1390 r'Sin|Sleep|Sngl|Spacing|Spread|SqRt|SRand|Stat|Sum|SymLnk|' |
|
1391 r'System|System_Clock|Tan|TanH|Time|Tiny|Transfer|Transpose|Trim|' |
|
1392 r'TtyNam|UBound|UMask|Unlink|Unpack|Verify|XOr|ZAbs|ZCos|ZExp|' |
|
1393 r'ZLog|ZSin|ZSqRt)\s*\b', |
|
1394 Name.Builtin), |
|
1395 |
|
1396 # Booleans |
|
1397 (r'\.(true|false)\.', Name.Builtin), |
|
1398 # Comparing Operators |
|
1399 (r'\.(eq|ne|lt|le|gt|ge|not|and|or|eqv|neqv)\.', Operator.Word), |
|
1400 ], |
|
1401 |
|
1402 'strings': [ |
|
1403 (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double), |
|
1404 (r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single), |
|
1405 ], |
|
1406 |
|
1407 'nums': [ |
|
1408 (r'\d+(?![.Ee])', Number.Integer), |
|
1409 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float), |
|
1410 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float), |
|
1411 ], |
|
1412 } |
|
1413 |
|
1414 |
|
1415 class GLShaderLexer(RegexLexer): |
|
1416 """ |
|
1417 GLSL (OpenGL Shader) lexer. |
|
1418 |
|
1419 *New in Pygments 1.1.* |
|
1420 """ |
|
1421 name = 'GLSL' |
|
1422 aliases = ['glsl'] |
|
1423 filenames = ['*.vert', '*.frag', '*.geo'] |
|
1424 mimetypes = ['text/x-glslsrc'] |
|
1425 |
|
1426 tokens = { |
|
1427 'root': [ |
|
1428 (r'^#.*', Comment.Preproc), |
|
1429 (r'//.*', Comment.Single), |
|
1430 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
1431 (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?', |
|
1432 Operator), |
|
1433 (r'[?:]', Operator), # quick hack for ternary |
|
1434 (r'\bdefined\b', Operator), |
|
1435 (r'[;{}(),\[\]]', Punctuation), |
|
1436 #FIXME when e is present, no decimal point needed |
|
1437 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float), |
|
1438 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float), |
|
1439 (r'0[xX][0-9a-fA-F]*', Number.Hex), |
|
1440 (r'0[0-7]*', Number.Oct), |
|
1441 (r'[1-9][0-9]*', Number.Integer), |
|
1442 (r'\b(attribute|const|uniform|varying|centroid|break|continue|' |
|
1443 r'do|for|while|if|else|in|out|inout|float|int|void|bool|true|' |
|
1444 r'false|invariant|discard|return|mat[234]|mat[234]x[234]|' |
|
1445 r'vec[234]|[ib]vec[234]|sampler[123]D|samplerCube|' |
|
1446 r'sampler[12]DShadow|struct)\b', Keyword), |
|
1447 (r'\b(asm|class|union|enum|typedef|template|this|packed|goto|' |
|
1448 r'switch|default|inline|noinline|volatile|public|static|extern|' |
|
1449 r'external|interface|long|short|double|half|fixed|unsigned|' |
|
1450 r'lowp|mediump|highp|precision|input|output|hvec[234]|' |
|
1451 r'[df]vec[234]|sampler[23]DRect|sampler2DRectShadow|sizeof|' |
|
1452 r'cast|namespace|using)\b', Keyword), #future use |
|
1453 (r'[a-zA-Z_][a-zA-Z_0-9]*', Name), |
|
1454 (r'\.', Punctuation), |
|
1455 (r'\s+', Text), |
|
1456 ], |
|
1457 } |
|
1458 |
|
1459 |
|
1460 class PrologLexer(RegexLexer): |
|
1461 """ |
|
1462 Lexer for Prolog files. |
|
1463 """ |
|
1464 name = 'Prolog' |
|
1465 aliases = ['prolog'] |
|
1466 filenames = ['*.prolog', '*.pro', '*.pl'] |
|
1467 mimetypes = ['text/x-prolog'] |
|
1468 |
|
1469 flags = re.UNICODE |
|
1470 |
|
1471 tokens = { |
|
1472 'root': [ |
|
1473 (r'^#.*', Comment.Single), |
|
1474 (r'/\*', Comment.Multiline, 'nested-comment'), |
|
1475 (r'%.*', Comment.Single), |
|
1476 (r'[0-9]+', Number), |
|
1477 (r'[\[\](){}|.,;!]', Punctuation), |
|
1478 (r':-|-->', Punctuation), |
|
1479 (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|' |
|
1480 r'\\[0-7]+\\|\\[\w\W]|[^"])*"', String.Double), |
|
1481 (r"'(?:''|[^'])*'", String.Atom), # quoted atom |
|
1482 # Needs to not be followed by an atom. |
|
1483 #(r'=(?=\s|[a-zA-Z\[])', Operator), |
|
1484 (r'is\b', Operator), |
|
1485 (r'(<|>|=<|>=|==|=:=|=|/|//|\*|\+|-)(?=\s|[a-zA-Z0-9\[])', |
|
1486 Operator), |
|
1487 (r'(mod|div|not)\b', Operator), |
|
1488 (r'_', Keyword), # The don't-care variable |
|
1489 (r'([a-z]+)(:)', bygroups(Name.Namespace, Punctuation)), |
|
1490 ('([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]' |
|
1491 '[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)' |
|
1492 '(\\s*)(:-|-->)', |
|
1493 bygroups(Name.Function, Text, Operator)), # function defn |
|
1494 ('([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]' |
|
1495 '[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)' |
|
1496 '(\\s*)(\\()', |
|
1497 bygroups(Name.Function, Text, Punctuation)), |
|
1498 ('[a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]' |
|
1499 '[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*', |
|
1500 String.Atom), # atom, characters |
|
1501 # This one includes ! |
|
1502 ('[#&*+\\-./:<=>?@\\\\^~\u00a1-\u00bf\u2010-\u303f]+', |
|
1503 String.Atom), # atom, graphics |
|
1504 (r'[A-Z_][A-Za-z0-9_]*', Name.Variable), |
|
1505 ('\\s+|[\u2000-\u200f\ufff0-\ufffe\uffef]', Text), |
|
1506 ], |
|
1507 'nested-comment': [ |
|
1508 (r'\*/', Comment.Multiline, '#pop'), |
|
1509 (r'/\*', Comment.Multiline, '#push'), |
|
1510 (r'[^*/]+', Comment.Multiline), |
|
1511 (r'[*/]', Comment.Multiline), |
|
1512 ], |
|
1513 } |
|
1514 |
|
1515 def analyse_text(text): |
|
1516 return ':-' in text |
|
1517 |
|
1518 |
|
1519 class CythonLexer(RegexLexer): |
|
1520 """ |
|
1521 For Pyrex and `Cython <http://cython.org>`_ source code. |
|
1522 |
|
1523 *New in Pygments 1.1.* |
|
1524 """ |
|
1525 |
|
1526 name = 'Cython' |
|
1527 aliases = ['cython', 'pyx'] |
|
1528 filenames = ['*.pyx', '*.pxd', '*.pxi'] |
|
1529 mimetypes = ['text/x-cython', 'application/x-cython'] |
|
1530 |
|
1531 tokens = { |
|
1532 'root': [ |
|
1533 (r'\n', Text), |
|
1534 (r'^(\s*)("""(?:.|\n)*?""")', bygroups(Text, String.Doc)), |
|
1535 (r"^(\s*)('''(?:.|\n)*?''')", bygroups(Text, String.Doc)), |
|
1536 (r'[^\S\n]+', Text), |
|
1537 (r'#.*$', Comment), |
|
1538 (r'[]{}:(),;[]', Punctuation), |
|
1539 (r'\\\n', Text), |
|
1540 (r'\\', Text), |
|
1541 (r'(in|is|and|or|not)\b', Operator.Word), |
|
1542 (r'(<)([a-zA-Z0-9.?]+)(>)', |
|
1543 bygroups(Punctuation, Keyword.Type, Punctuation)), |
|
1544 (r'!=|==|<<|>>|[-~+/*%=<>&^|.?]', Operator), |
|
1545 (r'(from)(\d+)(<=)(\s+)(<)(\d+)(:)', |
|
1546 bygroups(Keyword, Number.Integer, Operator, Name, Operator, |
|
1547 Name, Punctuation)), |
|
1548 include('keywords'), |
|
1549 (r'(def|property)(\s+)', bygroups(Keyword, Text), 'funcname'), |
|
1550 (r'(cp?def)(\s+)', bygroups(Keyword, Text), 'cdef'), |
|
1551 (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'classname'), |
|
1552 (r'(from)(\s+)', bygroups(Keyword, Text), 'fromimport'), |
|
1553 (r'(c?import)(\s+)', bygroups(Keyword, Text), 'import'), |
|
1554 include('builtins'), |
|
1555 include('backtick'), |
|
1556 ('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'), |
|
1557 ("(?:[rR]|[uU][rR]|[rR][uU])'''", String, 'tsqs'), |
|
1558 ('(?:[rR]|[uU][rR]|[rR][uU])"', String, 'dqs'), |
|
1559 ("(?:[rR]|[uU][rR]|[rR][uU])'", String, 'sqs'), |
|
1560 ('[uU]?"""', String, combined('stringescape', 'tdqs')), |
|
1561 ("[uU]?'''", String, combined('stringescape', 'tsqs')), |
|
1562 ('[uU]?"', String, combined('stringescape', 'dqs')), |
|
1563 ("[uU]?'", String, combined('stringescape', 'sqs')), |
|
1564 include('name'), |
|
1565 include('numbers'), |
|
1566 ], |
|
1567 'keywords': [ |
|
1568 (r'(assert|break|by|continue|ctypedef|del|elif|else|except\??|exec|' |
|
1569 r'finally|for|gil|global|if|include|lambda|nogil|pass|print|raise|' |
|
1570 r'return|try|while|yield|as|with)\b', Keyword), |
|
1571 (r'(DEF|IF|ELIF|ELSE)\b', Comment.Preproc), |
|
1572 ], |
|
1573 'builtins': [ |
|
1574 (r'(?<!\.)(__import__|abs|all|any|apply|basestring|bin|bool|buffer|' |
|
1575 r'bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|' |
|
1576 r'complex|delattr|dict|dir|divmod|enumerate|eval|execfile|exit|' |
|
1577 r'file|filter|float|frozenset|getattr|globals|hasattr|hash|hex|id|' |
|
1578 r'input|int|intern|isinstance|issubclass|iter|len|list|locals|' |
|
1579 r'long|map|max|min|next|object|oct|open|ord|pow|property|range|' |
|
1580 r'raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|' |
|
1581 r'sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|' |
|
1582 r'vars|xrange|zip)\b', Name.Builtin), |
|
1583 (r'(?<!\.)(self|None|Ellipsis|NotImplemented|False|True|NULL' |
|
1584 r')\b', Name.Builtin.Pseudo), |
|
1585 (r'(?<!\.)(ArithmeticError|AssertionError|AttributeError|' |
|
1586 r'BaseException|DeprecationWarning|EOFError|EnvironmentError|' |
|
1587 r'Exception|FloatingPointError|FutureWarning|GeneratorExit|IOError|' |
|
1588 r'ImportError|ImportWarning|IndentationError|IndexError|KeyError|' |
|
1589 r'KeyboardInterrupt|LookupError|MemoryError|NameError|' |
|
1590 r'NotImplemented|NotImplementedError|OSError|OverflowError|' |
|
1591 r'OverflowWarning|PendingDeprecationWarning|ReferenceError|' |
|
1592 r'RuntimeError|RuntimeWarning|StandardError|StopIteration|' |
|
1593 r'SyntaxError|SyntaxWarning|SystemError|SystemExit|TabError|' |
|
1594 r'TypeError|UnboundLocalError|UnicodeDecodeError|' |
|
1595 r'UnicodeEncodeError|UnicodeError|UnicodeTranslateError|' |
|
1596 r'UnicodeWarning|UserWarning|ValueError|Warning|ZeroDivisionError' |
|
1597 r')\b', Name.Exception), |
|
1598 ], |
|
1599 'numbers': [ |
|
1600 (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), |
|
1601 (r'0\d+', Number.Oct), |
|
1602 (r'0[xX][a-fA-F0-9]+', Number.Hex), |
|
1603 (r'\d+L', Number.Integer.Long), |
|
1604 (r'\d+', Number.Integer) |
|
1605 ], |
|
1606 'backtick': [ |
|
1607 ('`.*?`', String.Backtick), |
|
1608 ], |
|
1609 'name': [ |
|
1610 (r'@[a-zA-Z0-9_]+', Name.Decorator), |
|
1611 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
1612 ], |
|
1613 'funcname': [ |
|
1614 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop') |
|
1615 ], |
|
1616 'cdef': [ |
|
1617 (r'(public|readonly|extern|api|inline)\b', Keyword.Reserved), |
|
1618 (r'(struct|enum|union|class)\b', Keyword), |
|
1619 (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(?=[(:#=]|$)', |
|
1620 bygroups(Name.Function, Text), '#pop'), |
|
1621 (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(,)', |
|
1622 bygroups(Name.Function, Text, Punctuation)), |
|
1623 (r'from\b', Keyword, '#pop'), |
|
1624 (r'as\b', Keyword), |
|
1625 (r':', Punctuation, '#pop'), |
|
1626 (r'(?=["\'])', Text, '#pop'), |
|
1627 (r'[a-zA-Z_][a-zA-Z0-9_]*', Keyword.Type), |
|
1628 (r'.', Text), |
|
1629 ], |
|
1630 'classname': [ |
|
1631 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') |
|
1632 ], |
|
1633 'import': [ |
|
1634 (r'(\s+)(as)(\s+)', bygroups(Text, Keyword, Text)), |
|
1635 (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace), |
|
1636 (r'(\s*)(,)(\s*)', bygroups(Text, Operator, Text)), |
|
1637 (r'', Text, '#pop') # all else: go back |
|
1638 ], |
|
1639 'fromimport': [ |
|
1640 (r'(\s+)(c?import)\b', bygroups(Text, Keyword), '#pop'), |
|
1641 (r'[a-zA-Z_.][a-zA-Z0-9_.]*', Name.Namespace), |
|
1642 # ``cdef foo from "header"``, or ``for foo from 0 < i < 10`` |
|
1643 (r'', Text, '#pop'), |
|
1644 ], |
|
1645 'stringescape': [ |
|
1646 (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|' |
|
1647 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) |
|
1648 ], |
|
1649 'strings': [ |
|
1650 (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' |
|
1651 '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol), |
|
1652 (r'[^\\\'"%\n]+', String), |
|
1653 # quotes, percents and backslashes must be parsed one at a time |
|
1654 (r'[\'"\\]', String), |
|
1655 # unhandled string formatting sign |
|
1656 (r'%', String) |
|
1657 # newlines are an error (use "nl" state) |
|
1658 ], |
|
1659 'nl': [ |
|
1660 (r'\n', String) |
|
1661 ], |
|
1662 'dqs': [ |
|
1663 (r'"', String, '#pop'), |
|
1664 (r'\\\\|\\"|\\\n', String.Escape), # included here again for raw strings |
|
1665 include('strings') |
|
1666 ], |
|
1667 'sqs': [ |
|
1668 (r"'", String, '#pop'), |
|
1669 (r"\\\\|\\'|\\\n", String.Escape), # included here again for raw strings |
|
1670 include('strings') |
|
1671 ], |
|
1672 'tdqs': [ |
|
1673 (r'"""', String, '#pop'), |
|
1674 include('strings'), |
|
1675 include('nl') |
|
1676 ], |
|
1677 'tsqs': [ |
|
1678 (r"'''", String, '#pop'), |
|
1679 include('strings'), |
|
1680 include('nl') |
|
1681 ], |
|
1682 } |
|
1683 |
|
1684 |
|
1685 class ValaLexer(RegexLexer): |
|
1686 """ |
|
1687 For Vala source code with preprocessor directives. |
|
1688 |
|
1689 *New in Pygments 1.1.* |
|
1690 """ |
|
1691 name = 'Vala' |
|
1692 aliases = ['vala', 'vapi'] |
|
1693 filenames = ['*.vala', '*.vapi'] |
|
1694 mimetypes = ['text/x-vala'] |
|
1695 |
|
1696 tokens = { |
|
1697 'whitespace': [ |
|
1698 (r'^\s*#if\s+0', Comment.Preproc, 'if0'), |
|
1699 (r'\n', Text), |
|
1700 (r'\s+', Text), |
|
1701 (r'\\\n', Text), # line continuation |
|
1702 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), |
|
1703 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
1704 ], |
|
1705 'statements': [ |
|
1706 (r'L?"', String, 'string'), |
|
1707 (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", |
|
1708 String.Char), |
|
1709 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), |
|
1710 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
1711 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), |
|
1712 (r'0[0-7]+[Ll]?', Number.Oct), |
|
1713 (r'\d+[Ll]?', Number.Integer), |
|
1714 (r'[~!%^&*+=|?:<>/-]', Operator), |
|
1715 (r'(\[)(Compact|Immutable|(?:Boolean|Simple)Type)(\])', |
|
1716 bygroups(Punctuation, Name.Decorator, Punctuation)), |
|
1717 # TODO: "correctly" parse complex code attributes |
|
1718 (r'(\[)(CCode|(?:Integer|Floating)Type)', |
|
1719 bygroups(Punctuation, Name.Decorator)), |
|
1720 (r'[()\[\],.]', Punctuation), |
|
1721 (r'(as|base|break|case|catch|construct|continue|default|delete|do|' |
|
1722 r'else|enum|finally|for|foreach|get|if|in|is|lock|new|out|params|' |
|
1723 r'return|set|sizeof|switch|this|throw|try|typeof|while|yield)\b', |
|
1724 Keyword), |
|
1725 (r'(abstract|const|delegate|dynamic|ensures|extern|inline|internal|' |
|
1726 r'override|owned|private|protected|public|ref|requires|signal|' |
|
1727 r'static|throws|unowned|var|virtual|volatile|weak|yields)\b', |
|
1728 Keyword.Declaration), |
|
1729 (r'(namespace|using)(\s+)', bygroups(Keyword.Namespace, Text), |
|
1730 'namespace'), |
|
1731 (r'(class|errordomain|interface|struct)(\s+)', |
|
1732 bygroups(Keyword.Declaration, Text), 'class'), |
|
1733 (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', |
|
1734 bygroups(Operator, Name.Attribute)), |
|
1735 # void is an actual keyword, others are in glib-2.0.vapi |
|
1736 (r'(void|bool|char|double|float|int|int8|int16|int32|int64|long|' |
|
1737 r'short|size_t|ssize_t|string|time_t|uchar|uint|uint8|uint16|' |
|
1738 r'uint32|uint64|ulong|unichar|ushort)\b', Keyword.Type), |
|
1739 (r'(true|false|null)\b', Name.Builtin), |
|
1740 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
1741 ], |
|
1742 'root': [ |
|
1743 include('whitespace'), |
|
1744 ('', Text, 'statement'), |
|
1745 ], |
|
1746 'statement' : [ |
|
1747 include('whitespace'), |
|
1748 include('statements'), |
|
1749 ('[{}]', Punctuation), |
|
1750 (';', Punctuation, '#pop'), |
|
1751 ], |
|
1752 'string': [ |
|
1753 (r'"', String, '#pop'), |
|
1754 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
1755 (r'[^\\"\n]+', String), # all other characters |
|
1756 (r'\\\n', String), # line continuation |
|
1757 (r'\\', String), # stray backslash |
|
1758 ], |
|
1759 'if0': [ |
|
1760 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), |
|
1761 (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'), |
|
1762 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), |
|
1763 (r'.*?\n', Comment), |
|
1764 ], |
|
1765 'class': [ |
|
1766 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') |
|
1767 ], |
|
1768 'namespace': [ |
|
1769 (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop') |
|
1770 ], |
|
1771 } |
|
1772 |
|
1773 |
|
1774 class OocLexer(RegexLexer): |
|
1775 """ |
|
1776 For `Ooc <http://ooc-lang.org/>`_ source code |
|
1777 |
|
1778 *New in Pygments 1.2.* |
|
1779 """ |
|
1780 name = 'Ooc' |
|
1781 aliases = ['ooc'] |
|
1782 filenames = ['*.ooc'] |
|
1783 mimetypes = ['text/x-ooc'] |
|
1784 |
|
1785 tokens = { |
|
1786 'root': [ |
|
1787 (r'\b(class|interface|implement|abstract|extends|from|' |
|
1788 r'this|super|new|const|final|static|import|use|extern|' |
|
1789 r'inline|proto|break|continue|fallthrough|operator|if|else|for|' |
|
1790 r'while|do|switch|case|as|in|version|return|true|false|null)\b', |
|
1791 Keyword), |
|
1792 (r'include\b', Keyword, 'include'), |
|
1793 (r'(cover)([ \t]+)(from)([ \t]+)([a-zA-Z0-9_]+[*@]?)', |
|
1794 bygroups(Keyword, Text, Keyword, Text, Name.Class)), |
|
1795 (r'(func)((?:[ \t]|\\\n)+)(~[a-z_][a-zA-Z0-9_]*)', |
|
1796 bygroups(Keyword, Text, Name.Function)), |
|
1797 (r'\bfunc\b', Keyword), |
|
1798 # Note: %= and ^= not listed on http://ooc-lang.org/syntax |
|
1799 (r'//.*', Comment), |
|
1800 (r'(?s)/\*.*?\*/', Comment.Multiline), |
|
1801 (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|' |
|
1802 r'&&?|\|\|?|\^=?)', Operator), |
|
1803 (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text, |
|
1804 Name.Function)), |
|
1805 (r'[A-Z][A-Z0-9_]+', Name.Constant), |
|
1806 (r'[A-Z][a-zA-Z0-9_]*([@*]|\[[ \t]*\])?', Name.Class), |
|
1807 |
|
1808 (r'([a-z][a-zA-Z0-9_]*(?:~[a-z][a-zA-Z0-9_]*)?)((?:[ \t]|\\\n)*)(?=\()', |
|
1809 bygroups(Name.Function, Text)), |
|
1810 (r'[a-z][a-zA-Z0-9_]*', Name.Variable), |
|
1811 |
|
1812 # : introduces types |
|
1813 (r'[:(){}\[\];,]', Punctuation), |
|
1814 |
|
1815 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
1816 (r'0c[0-9]+', Number.Oct), |
|
1817 (r'0b[01]+', Number.Binary), |
|
1818 (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float), |
|
1819 (r'[0-9_]+', Number.Decimal), |
|
1820 |
|
1821 (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\"])*"', |
|
1822 String.Double), |
|
1823 (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", |
|
1824 String.Char), |
|
1825 (r'@', Punctuation), # pointer dereference |
|
1826 (r'\.', Punctuation), # imports or chain operator |
|
1827 |
|
1828 (r'\\[ \t\n]', Text), |
|
1829 (r'[ \t]+', Text), |
|
1830 ], |
|
1831 'include': [ |
|
1832 (r'[\w/]+', Name), |
|
1833 (r',', Punctuation), |
|
1834 (r'[ \t]', Text), |
|
1835 (r'[;\n]', Text, '#pop'), |
|
1836 ], |
|
1837 } |
|
1838 |
|
1839 |
|
1840 class GoLexer(RegexLexer): |
|
1841 """ |
|
1842 For `Go <http://golang.org>`_ source. |
|
1843 """ |
|
1844 name = 'Go' |
|
1845 filenames = ['*.go'] |
|
1846 aliases = ['go'] |
|
1847 mimetypes = ['text/x-gosrc'] |
|
1848 |
|
1849 tokens = { |
|
1850 'root': [ |
|
1851 (r'\n', Text), |
|
1852 (r'\s+', Text), |
|
1853 (r'\\\n', Text), # line continuations |
|
1854 (r'//(.*?)\n', Comment.Single), |
|
1855 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
1856 (r'(import|package)\b', Keyword.Namespace), |
|
1857 (r'(var|func|struct|map|chan|type|interface|const)\b', Keyword.Declaration), |
|
1858 (r'(break|default|select|case|defer|go' |
|
1859 r'|else|goto|switch|fallthrough|if|range' |
|
1860 r'|continue|for|return)\b', Keyword), |
|
1861 (r'(true|false|iota|nil)\b', Keyword.Constant), |
|
1862 # It seems the builtin types aren't actually keywords, but |
|
1863 # can be used as functions. So we need two declarations. |
|
1864 (r'(uint|uint8|uint16|uint32|uint64' |
|
1865 r'|int|int8|int16|int32|int64' |
|
1866 r'|float|float32|float64' |
|
1867 r'|complex64|complex128|byte|rune' |
|
1868 r'|string|bool|error|uintptr' |
|
1869 r'|print|println|panic|recover|close|complex|real|imag' |
|
1870 r'|len|cap|append|copy|delete|new|make)\b(\()', |
|
1871 bygroups(Name.Builtin, Punctuation)), |
|
1872 (r'(uint|uint8|uint16|uint32|uint64' |
|
1873 r'|int|int8|int16|int32|int64' |
|
1874 r'|float|float32|float64' |
|
1875 r'|complex64|complex128|byte|rune' |
|
1876 r'|string|bool|error|uintptr)\b', Keyword.Type), |
|
1877 # imaginary_lit |
|
1878 (r'\d+i', Number), |
|
1879 (r'\d+\.\d*([Ee][-+]\d+)?i', Number), |
|
1880 (r'\.\d+([Ee][-+]\d+)?i', Number), |
|
1881 (r'\d+[Ee][-+]\d+i', Number), |
|
1882 # float_lit |
|
1883 (r'\d+(\.\d+[eE][+\-]?\d+|' |
|
1884 r'\.\d*|[eE][+\-]?\d+)', Number.Float), |
|
1885 (r'\.\d+([eE][+\-]?\d+)?', Number.Float), |
|
1886 # int_lit |
|
1887 # -- octal_lit |
|
1888 (r'0[0-7]+', Number.Oct), |
|
1889 # -- hex_lit |
|
1890 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
1891 # -- decimal_lit |
|
1892 (r'(0|[1-9][0-9]*)', Number.Integer), |
|
1893 # char_lit |
|
1894 (r"""'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" |
|
1895 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'""", |
|
1896 String.Char |
|
1897 ), |
|
1898 # StringLiteral |
|
1899 # -- raw_string_lit |
|
1900 (r'`[^`]*`', String), |
|
1901 # -- interpreted_string_lit |
|
1902 (r'"(\\\\|\\"|[^"])*"', String), |
|
1903 # Tokens |
|
1904 (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|' |
|
1905 r'|<-|\+\+|--|==|!=|:=|\.\.\.|[+\-*/%&])', Operator), |
|
1906 (r'[|^<>=!()\[\]{}.,;:]', Punctuation), |
|
1907 # identifier |
|
1908 (r'[a-zA-Z_]\w*', Name.Other), |
|
1909 ] |
|
1910 } |
|
1911 |
|
1912 |
|
1913 class FelixLexer(RegexLexer): |
|
1914 """ |
|
1915 For `Felix <http://www.felix-lang.org>`_ source code. |
|
1916 |
|
1917 *New in Pygments 1.2.* |
|
1918 """ |
|
1919 |
|
1920 name = 'Felix' |
|
1921 aliases = ['felix', 'flx'] |
|
1922 filenames = ['*.flx', '*.flxh'] |
|
1923 mimetypes = ['text/x-felix'] |
|
1924 |
|
1925 preproc = [ |
|
1926 'elif', 'else', 'endif', 'if', 'ifdef', 'ifndef', |
|
1927 ] |
|
1928 |
|
1929 keywords = [ |
|
1930 '_', '_deref', 'all', 'as', |
|
1931 'assert', 'attempt', 'call', 'callback', 'case', 'caseno', 'cclass', |
|
1932 'code', 'compound', 'ctypes', 'do', 'done', 'downto', 'elif', 'else', |
|
1933 'endattempt', 'endcase', 'endif', 'endmatch', 'enum', 'except', |
|
1934 'exceptions', 'expect', 'finally', 'for', 'forall', 'forget', 'fork', |
|
1935 'functor', 'goto', 'ident', 'if', 'incomplete', 'inherit', 'instance', |
|
1936 'interface', 'jump', 'lambda', 'loop', 'match', 'module', 'namespace', |
|
1937 'new', 'noexpand', 'nonterm', 'obj', 'of', 'open', 'parse', 'raise', |
|
1938 'regexp', 'reglex', 'regmatch', 'rename', 'return', 'the', 'then', |
|
1939 'to', 'type', 'typecase', 'typedef', 'typematch', 'typeof', 'upto', |
|
1940 'when', 'whilst', 'with', 'yield', |
|
1941 ] |
|
1942 |
|
1943 keyword_directives = [ |
|
1944 '_gc_pointer', '_gc_type', 'body', 'comment', 'const', 'export', |
|
1945 'header', 'inline', 'lval', 'macro', 'noinline', 'noreturn', |
|
1946 'package', 'private', 'pod', 'property', 'public', 'publish', |
|
1947 'requires', 'todo', 'virtual', 'use', |
|
1948 ] |
|
1949 |
|
1950 keyword_declarations = [ |
|
1951 'def', 'let', 'ref', 'val', 'var', |
|
1952 ] |
|
1953 |
|
1954 keyword_types = [ |
|
1955 'unit', 'void', 'any', 'bool', |
|
1956 'byte', 'offset', |
|
1957 'address', 'caddress', 'cvaddress', 'vaddress', |
|
1958 'tiny', 'short', 'int', 'long', 'vlong', |
|
1959 'utiny', 'ushort', 'vshort', 'uint', 'ulong', 'uvlong', |
|
1960 'int8', 'int16', 'int32', 'int64', |
|
1961 'uint8', 'uint16', 'uint32', 'uint64', |
|
1962 'float', 'double', 'ldouble', |
|
1963 'complex', 'dcomplex', 'lcomplex', |
|
1964 'imaginary', 'dimaginary', 'limaginary', |
|
1965 'char', 'wchar', 'uchar', |
|
1966 'charp', 'charcp', 'ucharp', 'ucharcp', |
|
1967 'string', 'wstring', 'ustring', |
|
1968 'cont', |
|
1969 'array', 'varray', 'list', |
|
1970 'lvalue', 'opt', 'slice', |
|
1971 ] |
|
1972 |
|
1973 keyword_constants = [ |
|
1974 'false', 'true', |
|
1975 ] |
|
1976 |
|
1977 operator_words = [ |
|
1978 'and', 'not', 'in', 'is', 'isin', 'or', 'xor', |
|
1979 ] |
|
1980 |
|
1981 name_builtins = [ |
|
1982 '_svc', 'while', |
|
1983 ] |
|
1984 |
|
1985 name_pseudo = [ |
|
1986 'root', 'self', 'this', |
|
1987 ] |
|
1988 |
|
1989 decimal_suffixes = '([tTsSiIlLvV]|ll|LL|([iIuU])(8|16|32|64))?' |
|
1990 |
|
1991 tokens = { |
|
1992 'root': [ |
|
1993 include('whitespace'), |
|
1994 |
|
1995 # Keywords |
|
1996 (r'(axiom|ctor|fun|gen|proc|reduce|union)\b', Keyword, |
|
1997 'funcname'), |
|
1998 (r'(class|cclass|cstruct|obj|struct)\b', Keyword, 'classname'), |
|
1999 (r'(instance|module|typeclass)\b', Keyword, 'modulename'), |
|
2000 |
|
2001 (r'(%s)\b' % '|'.join(keywords), Keyword), |
|
2002 (r'(%s)\b' % '|'.join(keyword_directives), Name.Decorator), |
|
2003 (r'(%s)\b' % '|'.join(keyword_declarations), Keyword.Declaration), |
|
2004 (r'(%s)\b' % '|'.join(keyword_types), Keyword.Type), |
|
2005 (r'(%s)\b' % '|'.join(keyword_constants), Keyword.Constant), |
|
2006 |
|
2007 # Operators |
|
2008 include('operators'), |
|
2009 |
|
2010 # Float Literal |
|
2011 # -- Hex Float |
|
2012 (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)' |
|
2013 r'[pP][+\-]?[0-9_]+[lLfFdD]?', Number.Float), |
|
2014 # -- DecimalFloat |
|
2015 (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|' |
|
2016 r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[lLfFdD]?', Number.Float), |
|
2017 (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[lLfFdD]?', |
|
2018 Number.Float), |
|
2019 |
|
2020 # IntegerLiteral |
|
2021 # -- Binary |
|
2022 (r'0[Bb][01_]+%s' % decimal_suffixes, Number), |
|
2023 # -- Octal |
|
2024 (r'0[0-7_]+%s' % decimal_suffixes, Number.Oct), |
|
2025 # -- Hexadecimal |
|
2026 (r'0[xX][0-9a-fA-F_]+%s' % decimal_suffixes, Number.Hex), |
|
2027 # -- Decimal |
|
2028 (r'(0|[1-9][0-9_]*)%s' % decimal_suffixes, Number.Integer), |
|
2029 |
|
2030 # Strings |
|
2031 ('([rR][cC]?|[cC][rR])"""', String, 'tdqs'), |
|
2032 ("([rR][cC]?|[cC][rR])'''", String, 'tsqs'), |
|
2033 ('([rR][cC]?|[cC][rR])"', String, 'dqs'), |
|
2034 ("([rR][cC]?|[cC][rR])'", String, 'sqs'), |
|
2035 ('[cCfFqQwWuU]?"""', String, combined('stringescape', 'tdqs')), |
|
2036 ("[cCfFqQwWuU]?'''", String, combined('stringescape', 'tsqs')), |
|
2037 ('[cCfFqQwWuU]?"', String, combined('stringescape', 'dqs')), |
|
2038 ("[cCfFqQwWuU]?'", String, combined('stringescape', 'sqs')), |
|
2039 |
|
2040 # Punctuation |
|
2041 (r'[\[\]{}:(),;?]', Punctuation), |
|
2042 |
|
2043 # Labels |
|
2044 (r'[a-zA-Z_]\w*:>', Name.Label), |
|
2045 |
|
2046 # Identifiers |
|
2047 (r'(%s)\b' % '|'.join(name_builtins), Name.Builtin), |
|
2048 (r'(%s)\b' % '|'.join(name_pseudo), Name.Builtin.Pseudo), |
|
2049 (r'[a-zA-Z_]\w*', Name), |
|
2050 ], |
|
2051 'whitespace': [ |
|
2052 (r'\n', Text), |
|
2053 (r'\s+', Text), |
|
2054 |
|
2055 include('comment'), |
|
2056 |
|
2057 # Preprocessor |
|
2058 (r'#\s*if\s+0', Comment.Preproc, 'if0'), |
|
2059 (r'#', Comment.Preproc, 'macro'), |
|
2060 ], |
|
2061 'operators': [ |
|
2062 (r'(%s)\b' % '|'.join(operator_words), Operator.Word), |
|
2063 (r'!=|==|<<|>>|\|\||&&|[-~+/*%=<>&^|.$]', Operator), |
|
2064 ], |
|
2065 'comment': [ |
|
2066 (r'//(.*?)\n', Comment.Single), |
|
2067 (r'/[*]', Comment.Multiline, 'comment2'), |
|
2068 ], |
|
2069 'comment2': [ |
|
2070 (r'[^\/*]', Comment.Multiline), |
|
2071 (r'/[*]', Comment.Multiline, '#push'), |
|
2072 (r'[*]/', Comment.Multiline, '#pop'), |
|
2073 (r'[\/*]', Comment.Multiline), |
|
2074 ], |
|
2075 'if0': [ |
|
2076 (r'^\s*#if.*?(?<!\\)\n', Comment, '#push'), |
|
2077 (r'^\s*#endif.*?(?<!\\)\n', Comment, '#pop'), |
|
2078 (r'.*?\n', Comment), |
|
2079 ], |
|
2080 'macro': [ |
|
2081 include('comment'), |
|
2082 (r'(import|include)(\s+)(<[^>]*?>)', |
|
2083 bygroups(Comment.Preproc, Text, String), '#pop'), |
|
2084 (r'(import|include)(\s+)("[^"]*?")', |
|
2085 bygroups(Comment.Preproc, Text, String), '#pop'), |
|
2086 (r"(import|include)(\s+)('[^']*?')", |
|
2087 bygroups(Comment.Preproc, Text, String), '#pop'), |
|
2088 (r'[^/\n]+', Comment.Preproc), |
|
2089 ##(r'/[*](.|\n)*?[*]/', Comment), |
|
2090 ##(r'//.*?\n', Comment, '#pop'), |
|
2091 (r'/', Comment.Preproc), |
|
2092 (r'(?<=\\)\n', Comment.Preproc), |
|
2093 (r'\n', Comment.Preproc, '#pop'), |
|
2094 ], |
|
2095 'funcname': [ |
|
2096 include('whitespace'), |
|
2097 (r'[a-zA-Z_]\w*', Name.Function, '#pop'), |
|
2098 # anonymous functions |
|
2099 (r'(?=\()', Text, '#pop'), |
|
2100 ], |
|
2101 'classname': [ |
|
2102 include('whitespace'), |
|
2103 (r'[a-zA-Z_]\w*', Name.Class, '#pop'), |
|
2104 # anonymous classes |
|
2105 (r'(?=\{)', Text, '#pop'), |
|
2106 ], |
|
2107 'modulename': [ |
|
2108 include('whitespace'), |
|
2109 (r'\[', Punctuation, ('modulename2', 'tvarlist')), |
|
2110 (r'', Error, 'modulename2'), |
|
2111 ], |
|
2112 'modulename2': [ |
|
2113 include('whitespace'), |
|
2114 (r'([a-zA-Z_]\w*)', Name.Namespace, '#pop:2'), |
|
2115 ], |
|
2116 'tvarlist': [ |
|
2117 include('whitespace'), |
|
2118 include('operators'), |
|
2119 (r'\[', Punctuation, '#push'), |
|
2120 (r'\]', Punctuation, '#pop'), |
|
2121 (r',', Punctuation), |
|
2122 (r'(with|where)\b', Keyword), |
|
2123 (r'[a-zA-Z_]\w*', Name), |
|
2124 ], |
|
2125 'stringescape': [ |
|
2126 (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|' |
|
2127 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) |
|
2128 ], |
|
2129 'strings': [ |
|
2130 (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?' |
|
2131 '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol), |
|
2132 (r'[^\\\'"%\n]+', String), |
|
2133 # quotes, percents and backslashes must be parsed one at a time |
|
2134 (r'[\'"\\]', String), |
|
2135 # unhandled string formatting sign |
|
2136 (r'%', String) |
|
2137 # newlines are an error (use "nl" state) |
|
2138 ], |
|
2139 'nl': [ |
|
2140 (r'\n', String) |
|
2141 ], |
|
2142 'dqs': [ |
|
2143 (r'"', String, '#pop'), |
|
2144 # included here again for raw strings |
|
2145 (r'\\\\|\\"|\\\n', String.Escape), |
|
2146 include('strings') |
|
2147 ], |
|
2148 'sqs': [ |
|
2149 (r"'", String, '#pop'), |
|
2150 # included here again for raw strings |
|
2151 (r"\\\\|\\'|\\\n", String.Escape), |
|
2152 include('strings') |
|
2153 ], |
|
2154 'tdqs': [ |
|
2155 (r'"""', String, '#pop'), |
|
2156 include('strings'), |
|
2157 include('nl') |
|
2158 ], |
|
2159 'tsqs': [ |
|
2160 (r"'''", String, '#pop'), |
|
2161 include('strings'), |
|
2162 include('nl') |
|
2163 ], |
|
2164 } |
|
2165 |
|
2166 |
|
2167 class AdaLexer(RegexLexer): |
|
2168 """ |
|
2169 For Ada source code. |
|
2170 |
|
2171 *New in Pygments 1.3.* |
|
2172 """ |
|
2173 |
|
2174 name = 'Ada' |
|
2175 aliases = ['ada', 'ada95' 'ada2005'] |
|
2176 filenames = ['*.adb', '*.ads', '*.ada'] |
|
2177 mimetypes = ['text/x-ada'] |
|
2178 |
|
2179 flags = re.MULTILINE | re.I # Ignore case |
|
2180 |
|
2181 tokens = { |
|
2182 'root': [ |
|
2183 (r'[^\S\n]+', Text), |
|
2184 (r'--.*?\n', Comment.Single), |
|
2185 (r'[^\S\n]+', Text), |
|
2186 (r'function|procedure|entry', Keyword.Declaration, 'subprogram'), |
|
2187 (r'(subtype|type)(\s+)([a-z0-9_]+)', |
|
2188 bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'), |
|
2189 (r'task|protected', Keyword.Declaration), |
|
2190 (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)), |
|
2191 (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'), |
|
2192 (r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text, |
|
2193 Comment.Preproc)), |
|
2194 (r'(true|false|null)\b', Keyword.Constant), |
|
2195 (r'(Address|Byte|Boolean|Character|Controlled|Count|Cursor|' |
|
2196 r'Duration|File_Mode|File_Type|Float|Generator|Integer|Long_Float|' |
|
2197 r'Long_Integer|Long_Long_Float|Long_Long_Integer|Natural|Positive|' |
|
2198 r'Reference_Type|Short_Float|Short_Integer|Short_Short_Float|' |
|
2199 r'Short_Short_Integer|String|Wide_Character|Wide_String)\b', |
|
2200 Keyword.Type), |
|
2201 (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word), |
|
2202 (r'generic|private', Keyword.Declaration), |
|
2203 (r'package', Keyword.Declaration, 'package'), |
|
2204 (r'array\b', Keyword.Reserved, 'array_def'), |
|
2205 (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'), |
|
2206 (r'([a-z0-9_]+)(\s*)(:)(\s*)(constant)', |
|
2207 bygroups(Name.Constant, Text, Punctuation, Text, |
|
2208 Keyword.Reserved)), |
|
2209 (r'<<[a-z0-9_]+>>', Name.Label), |
|
2210 (r'([a-z0-9_]+)(\s*)(:)(\s*)(declare|begin|loop|for|while)', |
|
2211 bygroups(Name.Label, Text, Punctuation, Text, Keyword.Reserved)), |
|
2212 (r'\b(abort|abs|abstract|accept|access|aliased|all|array|at|begin|' |
|
2213 r'body|case|constant|declare|delay|delta|digits|do|else|elsif|end|' |
|
2214 r'entry|exception|exit|interface|for|goto|if|is|limited|loop|new|' |
|
2215 r'null|of|or|others|out|overriding|pragma|protected|raise|range|' |
|
2216 r'record|renames|requeue|return|reverse|select|separate|subtype|' |
|
2217 r'synchronized|task|tagged|terminate|then|type|until|when|while|' |
|
2218 r'xor)\b', |
|
2219 Keyword.Reserved), |
|
2220 (r'"[^"]*"', String), |
|
2221 include('attribute'), |
|
2222 include('numbers'), |
|
2223 (r"'[^']'", String.Character), |
|
2224 (r'([a-z0-9_]+)(\s*|[(,])', bygroups(Name, using(this))), |
|
2225 (r"(<>|=>|:=|[()|:;,.'])", Punctuation), |
|
2226 (r'[*<>+=/&-]', Operator), |
|
2227 (r'\n+', Text), |
|
2228 ], |
|
2229 'numbers' : [ |
|
2230 (r'[0-9_]+#[0-9a-f]+#', Number.Hex), |
|
2231 (r'[0-9_]+\.[0-9_]*', Number.Float), |
|
2232 (r'[0-9_]+', Number.Integer), |
|
2233 ], |
|
2234 'attribute' : [ |
|
2235 (r"(')([a-zA-Z0-9_]+)", bygroups(Punctuation, Name.Attribute)), |
|
2236 ], |
|
2237 'subprogram' : [ |
|
2238 (r'\(', Punctuation, ('#pop', 'formal_part')), |
|
2239 (r';', Punctuation, '#pop'), |
|
2240 (r'is\b', Keyword.Reserved, '#pop'), |
|
2241 (r'"[^"]+"|[a-z0-9_]+', Name.Function), |
|
2242 include('root'), |
|
2243 ], |
|
2244 'end' : [ |
|
2245 ('(if|case|record|loop|select)', Keyword.Reserved), |
|
2246 ('"[^"]+"|[a-zA-Z0-9_.]+', Name.Function), |
|
2247 ('\s+', Text), |
|
2248 (';', Punctuation, '#pop'), |
|
2249 ], |
|
2250 'type_def': [ |
|
2251 (r';', Punctuation, '#pop'), |
|
2252 (r'\(', Punctuation, 'formal_part'), |
|
2253 (r'with|and|use', Keyword.Reserved), |
|
2254 (r'array\b', Keyword.Reserved, ('#pop', 'array_def')), |
|
2255 (r'record\b', Keyword.Reserved, ('record_def')), |
|
2256 (r'(null record)(;)', bygroups(Keyword.Reserved, Punctuation), '#pop'), |
|
2257 include('root'), |
|
2258 ], |
|
2259 'array_def' : [ |
|
2260 (r';', Punctuation, '#pop'), |
|
2261 (r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text, |
|
2262 Keyword.Reserved)), |
|
2263 include('root'), |
|
2264 ], |
|
2265 'record_def' : [ |
|
2266 (r'end record', Keyword.Reserved, '#pop'), |
|
2267 include('root'), |
|
2268 ], |
|
2269 'import': [ |
|
2270 (r'[a-z0-9_.]+', Name.Namespace, '#pop'), |
|
2271 (r'', Text, '#pop'), |
|
2272 ], |
|
2273 'formal_part' : [ |
|
2274 (r'\)', Punctuation, '#pop'), |
|
2275 (r'[a-z0-9_]+', Name.Variable), |
|
2276 (r',|:[^=]', Punctuation), |
|
2277 (r'(in|not|null|out|access)\b', Keyword.Reserved), |
|
2278 include('root'), |
|
2279 ], |
|
2280 'package': [ |
|
2281 ('body', Keyword.Declaration), |
|
2282 ('is\s+new|renames', Keyword.Reserved), |
|
2283 ('is', Keyword.Reserved, '#pop'), |
|
2284 (';', Punctuation, '#pop'), |
|
2285 ('\(', Punctuation, 'package_instantiation'), |
|
2286 ('([a-zA-Z0-9_.]+)', Name.Class), |
|
2287 include('root'), |
|
2288 ], |
|
2289 'package_instantiation': [ |
|
2290 (r'("[^"]+"|[a-z0-9_]+)(\s+)(=>)', bygroups(Name.Variable, |
|
2291 Text, Punctuation)), |
|
2292 (r'[a-z0-9._\'"]', Text), |
|
2293 (r'\)', Punctuation, '#pop'), |
|
2294 include('root'), |
|
2295 ], |
|
2296 } |
|
2297 |
|
2298 |
|
2299 class Modula2Lexer(RegexLexer): |
|
2300 """ |
|
2301 For `Modula-2 <http://www.modula2.org/>`_ source code. |
|
2302 |
|
2303 Additional options that determine which keywords are highlighted: |
|
2304 |
|
2305 `pim` |
|
2306 Select PIM Modula-2 dialect (default: True). |
|
2307 `iso` |
|
2308 Select ISO Modula-2 dialect (default: False). |
|
2309 `objm2` |
|
2310 Select Objective Modula-2 dialect (default: False). |
|
2311 `gm2ext` |
|
2312 Also highlight GNU extensions (default: False). |
|
2313 |
|
2314 *New in Pygments 1.3.* |
|
2315 """ |
|
2316 name = 'Modula-2' |
|
2317 aliases = ['modula2', 'm2'] |
|
2318 filenames = ['*.def', '*.mod'] |
|
2319 mimetypes = ['text/x-modula2'] |
|
2320 |
|
2321 flags = re.MULTILINE | re.DOTALL |
|
2322 |
|
2323 tokens = { |
|
2324 'whitespace': [ |
|
2325 (r'\n+', Text), # blank lines |
|
2326 (r'\s+', Text), # whitespace |
|
2327 ], |
|
2328 'identifiers': [ |
|
2329 (r'([a-zA-Z_\$][a-zA-Z0-9_\$]*)', Name), |
|
2330 ], |
|
2331 'numliterals': [ |
|
2332 (r'[01]+B', Number.Binary), # binary number (ObjM2) |
|
2333 (r'[0-7]+B', Number.Oct), # octal number (PIM + ISO) |
|
2334 (r'[0-7]+C', Number.Oct), # char code (PIM + ISO) |
|
2335 (r'[0-9A-F]+C', Number.Hex), # char code (ObjM2) |
|
2336 (r'[0-9A-F]+H', Number.Hex), # hexadecimal number |
|
2337 (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number |
|
2338 (r'[0-9]+\.[0-9]+', Number.Float), # real number |
|
2339 (r'[0-9]+', Number.Integer), # decimal whole number |
|
2340 ], |
|
2341 'strings': [ |
|
2342 (r"'(\\\\|\\'|[^'])*'", String), # single quoted string |
|
2343 (r'"(\\\\|\\"|[^"])*"', String), # double quoted string |
|
2344 ], |
|
2345 'operators': [ |
|
2346 (r'[*/+=#~&<>\^-]', Operator), |
|
2347 (r':=', Operator), # assignment |
|
2348 (r'@', Operator), # pointer deref (ISO) |
|
2349 (r'\.\.', Operator), # ellipsis or range |
|
2350 (r'`', Operator), # Smalltalk message (ObjM2) |
|
2351 (r'::', Operator), # type conversion (ObjM2) |
|
2352 ], |
|
2353 'punctuation': [ |
|
2354 (r'[\(\)\[\]{},.:;|]', Punctuation), |
|
2355 ], |
|
2356 'comments': [ |
|
2357 (r'//.*?\n', Comment.Single), # ObjM2 |
|
2358 (r'/\*(.*?)\*/', Comment.Multiline), # ObjM2 |
|
2359 (r'\(\*([^\$].*?)\*\)', Comment.Multiline), |
|
2360 # TO DO: nesting of (* ... *) comments |
|
2361 ], |
|
2362 'pragmas': [ |
|
2363 (r'\(\*\$(.*?)\*\)', Comment.Preproc), # PIM |
|
2364 (r'<\*(.*?)\*>', Comment.Preproc), # ISO + ObjM2 |
|
2365 ], |
|
2366 'root': [ |
|
2367 include('whitespace'), |
|
2368 include('comments'), |
|
2369 include('pragmas'), |
|
2370 include('identifiers'), |
|
2371 include('numliterals'), |
|
2372 include('strings'), |
|
2373 include('operators'), |
|
2374 include('punctuation'), |
|
2375 ] |
|
2376 } |
|
2377 |
|
2378 pim_reserved_words = [ |
|
2379 # 40 reserved words |
|
2380 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', |
|
2381 'DIV', 'DO', 'ELSE', 'ELSIF', 'END', 'EXIT', 'EXPORT', 'FOR', |
|
2382 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN', 'LOOP', 'MOD', |
|
2383 'MODULE', 'NOT', 'OF', 'OR', 'POINTER', 'PROCEDURE', 'QUALIFIED', |
|
2384 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', |
|
2385 'UNTIL', 'VAR', 'WHILE', 'WITH', |
|
2386 ] |
|
2387 |
|
2388 pim_pervasives = [ |
|
2389 # 31 pervasives |
|
2390 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'DEC', |
|
2391 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH', 'INC', 'INCL', |
|
2392 'INTEGER', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW', 'NIL', 'ODD', |
|
2393 'ORD', 'PROC', 'REAL', 'SIZE', 'TRUE', 'TRUNC', 'VAL', |
|
2394 ] |
|
2395 |
|
2396 iso_reserved_words = [ |
|
2397 # 46 reserved words |
|
2398 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV', |
|
2399 'DO', 'ELSE', 'ELSIF', 'END', 'EXCEPT', 'EXIT', 'EXPORT', 'FINALLY', |
|
2400 'FOR', 'FORWARD', 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN', |
|
2401 'LOOP', 'MOD', 'MODULE', 'NOT', 'OF', 'OR', 'PACKEDSET', 'POINTER', |
|
2402 'PROCEDURE', 'QUALIFIED', 'RECORD', 'REPEAT', 'REM', 'RETRY', |
|
2403 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', 'UNTIL', 'VAR', 'WHILE', |
|
2404 'WITH', |
|
2405 ] |
|
2406 |
|
2407 iso_pervasives = [ |
|
2408 # 42 pervasives |
|
2409 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'CMPLX', |
|
2410 'COMPLEX', 'DEC', 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH', |
|
2411 'IM', 'INC', 'INCL', 'INT', 'INTEGER', 'INTERRUPTIBLE', 'LENGTH', |
|
2412 'LFLOAT', 'LONGCOMPLEX', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW', |
|
2413 'NIL', 'ODD', 'ORD', 'PROC', 'PROTECTION', 'RE', 'REAL', 'SIZE', |
|
2414 'TRUE', 'TRUNC', 'UNINTERRUBTIBLE', 'VAL', |
|
2415 ] |
|
2416 |
|
2417 objm2_reserved_words = [ |
|
2418 # base language, 42 reserved words |
|
2419 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV', |
|
2420 'DO', 'ELSE', 'ELSIF', 'END', 'ENUM', 'EXIT', 'FOR', 'FROM', 'IF', |
|
2421 'IMMUTABLE', 'IMPLEMENTATION', 'IMPORT', 'IN', 'IS', 'LOOP', 'MOD', |
|
2422 'MODULE', 'NOT', 'OF', 'OPAQUE', 'OR', 'POINTER', 'PROCEDURE', |
|
2423 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', |
|
2424 'UNTIL', 'VAR', 'VARIADIC', 'WHILE', |
|
2425 # OO extensions, 16 reserved words |
|
2426 'BYCOPY', 'BYREF', 'CLASS', 'CONTINUE', 'CRITICAL', 'INOUT', 'METHOD', |
|
2427 'ON', 'OPTIONAL', 'OUT', 'PRIVATE', 'PROTECTED', 'PROTOCOL', 'PUBLIC', |
|
2428 'SUPER', 'TRY', |
|
2429 ] |
|
2430 |
|
2431 objm2_pervasives = [ |
|
2432 # base language, 38 pervasives |
|
2433 'ABS', 'BITSET', 'BOOLEAN', 'CARDINAL', 'CHAR', 'CHR', 'DISPOSE', |
|
2434 'FALSE', 'HALT', 'HIGH', 'INTEGER', 'INRANGE', 'LENGTH', 'LONGCARD', |
|
2435 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEG', 'NEW', 'NEXTV', 'NIL', |
|
2436 'OCTET', 'ODD', 'ORD', 'PRED', 'PROC', 'READ', 'REAL', 'SUCC', 'TMAX', |
|
2437 'TMIN', 'TRUE', 'TSIZE', 'UNICHAR', 'VAL', 'WRITE', 'WRITEF', |
|
2438 # OO extensions, 3 pervasives |
|
2439 'OBJECT', 'NO', 'YES', |
|
2440 ] |
|
2441 |
|
2442 gnu_reserved_words = [ |
|
2443 # 10 additional reserved words |
|
2444 'ASM', '__ATTRIBUTE__', '__BUILTIN__', '__COLUMN__', '__DATE__', |
|
2445 '__FILE__', '__FUNCTION__', '__LINE__', '__MODULE__', 'VOLATILE', |
|
2446 ] |
|
2447 |
|
2448 gnu_pervasives = [ |
|
2449 # 21 identifiers, actually from pseudo-module SYSTEM |
|
2450 # but we will highlight them as if they were pervasives |
|
2451 'BITSET8', 'BITSET16', 'BITSET32', 'CARDINAL8', 'CARDINAL16', |
|
2452 'CARDINAL32', 'CARDINAL64', 'COMPLEX32', 'COMPLEX64', 'COMPLEX96', |
|
2453 'COMPLEX128', 'INTEGER8', 'INTEGER16', 'INTEGER32', 'INTEGER64', |
|
2454 'REAL8', 'REAL16', 'REAL32', 'REAL96', 'REAL128', 'THROW', |
|
2455 ] |
|
2456 |
|
2457 def __init__(self, **options): |
|
2458 self.reserved_words = set() |
|
2459 self.pervasives = set() |
|
2460 # ISO Modula-2 |
|
2461 if get_bool_opt(options, 'iso', False): |
|
2462 self.reserved_words.update(self.iso_reserved_words) |
|
2463 self.pervasives.update(self.iso_pervasives) |
|
2464 # Objective Modula-2 |
|
2465 elif get_bool_opt(options, 'objm2', False): |
|
2466 self.reserved_words.update(self.objm2_reserved_words) |
|
2467 self.pervasives.update(self.objm2_pervasives) |
|
2468 # PIM Modula-2 (DEFAULT) |
|
2469 else: |
|
2470 self.reserved_words.update(self.pim_reserved_words) |
|
2471 self.pervasives.update(self.pim_pervasives) |
|
2472 # GNU extensions |
|
2473 if get_bool_opt(options, 'gm2ext', False): |
|
2474 self.reserved_words.update(self.gnu_reserved_words) |
|
2475 self.pervasives.update(self.gnu_pervasives) |
|
2476 # initialise |
|
2477 RegexLexer.__init__(self, **options) |
|
2478 |
|
2479 def get_tokens_unprocessed(self, text): |
|
2480 for index, token, value in \ |
|
2481 RegexLexer.get_tokens_unprocessed(self, text): |
|
2482 # check for reserved words and pervasives |
|
2483 if token is Name: |
|
2484 if value in self.reserved_words: |
|
2485 token = Keyword.Reserved |
|
2486 elif value in self.pervasives: |
|
2487 token = Keyword.Pervasive |
|
2488 # return result |
|
2489 yield index, token, value |
|
2490 |
|
2491 |
|
2492 class BlitzMaxLexer(RegexLexer): |
|
2493 """ |
|
2494 For `BlitzMax <http://blitzbasic.com>`_ source code. |
|
2495 |
|
2496 *New in Pygments 1.4.* |
|
2497 """ |
|
2498 |
|
2499 name = 'BlitzMax' |
|
2500 aliases = ['blitzmax', 'bmax'] |
|
2501 filenames = ['*.bmx'] |
|
2502 mimetypes = ['text/x-bmx'] |
|
2503 |
|
2504 bmax_vopwords = r'\b(Shl|Shr|Sar|Mod)\b' |
|
2505 bmax_sktypes = r'@{1,2}|[!#$%]' |
|
2506 bmax_lktypes = r'\b(Int|Byte|Short|Float|Double|Long)\b' |
|
2507 bmax_name = r'[a-z_][a-z0-9_]*' |
|
2508 bmax_var = (r'(%s)(?:(?:([ \t]*)(%s)|([ \t]*:[ \t]*\b(?:Shl|Shr|Sar|Mod)\b)' |
|
2509 r'|([ \t]*)([:])([ \t]*)(?:%s|(%s)))(?:([ \t]*)(Ptr))?)') % \ |
|
2510 (bmax_name, bmax_sktypes, bmax_lktypes, bmax_name) |
|
2511 bmax_func = bmax_var + r'?((?:[ \t]|\.\.\n)*)([(])' |
|
2512 |
|
2513 flags = re.MULTILINE | re.IGNORECASE |
|
2514 tokens = { |
|
2515 'root': [ |
|
2516 # Text |
|
2517 (r'[ \t]+', Text), |
|
2518 (r'\.\.\n', Text), # Line continuation |
|
2519 # Comments |
|
2520 (r"'.*?\n", Comment.Single), |
|
2521 (r'([ \t]*)\bRem\n(\n|.)*?\s*\bEnd([ \t]*)Rem', Comment.Multiline), |
|
2522 # Data types |
|
2523 ('"', String.Double, 'string'), |
|
2524 # Numbers |
|
2525 (r'[0-9]+\.[0-9]*(?!\.)', Number.Float), |
|
2526 (r'\.[0-9]*(?!\.)', Number.Float), |
|
2527 (r'[0-9]+', Number.Integer), |
|
2528 (r'\$[0-9a-f]+', Number.Hex), |
|
2529 (r'\%[10]+', Number), # Binary |
|
2530 # Other |
|
2531 (r'(?:(?:(:)?([ \t]*)(:?%s|([+\-*/&|~]))|Or|And|Not|[=<>^]))' % |
|
2532 (bmax_vopwords), Operator), |
|
2533 (r'[(),.:\[\]]', Punctuation), |
|
2534 (r'(?:#[\w \t]*)', Name.Label), |
|
2535 (r'(?:\?[\w \t]*)', Comment.Preproc), |
|
2536 # Identifiers |
|
2537 (r'\b(New)\b([ \t]?)([(]?)(%s)' % (bmax_name), |
|
2538 bygroups(Keyword.Reserved, Text, Punctuation, Name.Class)), |
|
2539 (r'\b(Import|Framework|Module)([ \t]+)(%s\.%s)' % |
|
2540 (bmax_name, bmax_name), |
|
2541 bygroups(Keyword.Reserved, Text, Keyword.Namespace)), |
|
2542 (bmax_func, bygroups(Name.Function, Text, Keyword.Type, |
|
2543 Operator, Text, Punctuation, Text, |
|
2544 Keyword.Type, Name.Class, Text, |
|
2545 Keyword.Type, Text, Punctuation)), |
|
2546 (bmax_var, bygroups(Name.Variable, Text, Keyword.Type, Operator, |
|
2547 Text, Punctuation, Text, Keyword.Type, |
|
2548 Name.Class, Text, Keyword.Type)), |
|
2549 (r'\b(Type|Extends)([ \t]+)(%s)' % (bmax_name), |
|
2550 bygroups(Keyword.Reserved, Text, Name.Class)), |
|
2551 # Keywords |
|
2552 (r'\b(Ptr)\b', Keyword.Type), |
|
2553 (r'\b(Pi|True|False|Null|Self|Super)\b', Keyword.Constant), |
|
2554 (r'\b(Local|Global|Const|Field)\b', Keyword.Declaration), |
|
2555 (r'\b(TNullMethodException|TNullFunctionException|' |
|
2556 r'TNullObjectException|TArrayBoundsException|' |
|
2557 r'TRuntimeException)\b', Name.Exception), |
|
2558 (r'\b(Strict|SuperStrict|Module|ModuleInfo|' |
|
2559 r'End|Return|Continue|Exit|Public|Private|' |
|
2560 r'Var|VarPtr|Chr|Len|Asc|SizeOf|Sgn|Abs|Min|Max|' |
|
2561 r'New|Release|Delete|' |
|
2562 r'Incbin|IncbinPtr|IncbinLen|' |
|
2563 r'Framework|Include|Import|Extern|EndExtern|' |
|
2564 r'Function|EndFunction|' |
|
2565 r'Type|EndType|Extends|' |
|
2566 r'Method|EndMethod|' |
|
2567 r'Abstract|Final|' |
|
2568 r'If|Then|Else|ElseIf|EndIf|' |
|
2569 r'For|To|Next|Step|EachIn|' |
|
2570 r'While|Wend|EndWhile|' |
|
2571 r'Repeat|Until|Forever|' |
|
2572 r'Select|Case|Default|EndSelect|' |
|
2573 r'Try|Catch|EndTry|Throw|Assert|' |
|
2574 r'Goto|DefData|ReadData|RestoreData)\b', Keyword.Reserved), |
|
2575 # Final resolve (for variable names and such) |
|
2576 (r'(%s)' % (bmax_name), Name.Variable), |
|
2577 ], |
|
2578 'string': [ |
|
2579 (r'""', String.Double), |
|
2580 (r'"C?', String.Double, '#pop'), |
|
2581 (r'[^"]+', String.Double), |
|
2582 ], |
|
2583 } |
|
2584 |
|
2585 |
|
2586 class NimrodLexer(RegexLexer): |
|
2587 """ |
|
2588 For `Nimrod <http://nimrod-code.org/>`_ source code. |
|
2589 |
|
2590 *New in Pygments 1.5.* |
|
2591 """ |
|
2592 |
|
2593 name = 'Nimrod' |
|
2594 aliases = ['nimrod', 'nim'] |
|
2595 filenames = ['*.nim', '*.nimrod'] |
|
2596 mimetypes = ['text/x-nimrod'] |
|
2597 |
|
2598 flags = re.MULTILINE | re.IGNORECASE | re.UNICODE |
|
2599 |
|
2600 def underscorize(words): |
|
2601 newWords = [] |
|
2602 new = "" |
|
2603 for word in words: |
|
2604 for ch in word: |
|
2605 new += (ch + "_?") |
|
2606 newWords.append(new) |
|
2607 new = "" |
|
2608 return "|".join(newWords) |
|
2609 |
|
2610 keywords = [ |
|
2611 'addr', 'and', 'as', 'asm', 'atomic', 'bind', 'block', 'break', |
|
2612 'case', 'cast', 'const', 'continue', 'converter', 'discard', |
|
2613 'distinct', 'div', 'elif', 'else', 'end', 'enum', 'except', 'finally', |
|
2614 'for', 'generic', 'if', 'implies', 'in', 'yield', |
|
2615 'is', 'isnot', 'iterator', 'lambda', 'let', 'macro', 'method', |
|
2616 'mod', 'not', 'notin', 'object', 'of', 'or', 'out', 'proc', |
|
2617 'ptr', 'raise', 'ref', 'return', 'shl', 'shr', 'template', 'try', |
|
2618 'tuple', 'type' , 'when', 'while', 'with', 'without', 'xor' |
|
2619 ] |
|
2620 |
|
2621 keywordsPseudo = [ |
|
2622 'nil', 'true', 'false' |
|
2623 ] |
|
2624 |
|
2625 opWords = [ |
|
2626 'and', 'or', 'not', 'xor', 'shl', 'shr', 'div', 'mod', 'in', |
|
2627 'notin', 'is', 'isnot' |
|
2628 ] |
|
2629 |
|
2630 types = [ |
|
2631 'int', 'int8', 'int16', 'int32', 'int64', 'float', 'float32', 'float64', |
|
2632 'bool', 'char', 'range', 'array', 'seq', 'set', 'string' |
|
2633 ] |
|
2634 |
|
2635 tokens = { |
|
2636 'root': [ |
|
2637 (r'##.*$', String.Doc), |
|
2638 (r'#.*$', Comment), |
|
2639 (r'\*|=|>|<|\+|-|/|@|\$|~|&|%|\!|\?|\||\\|\[|\]', Operator), |
|
2640 (r'\.\.|\.|,|\[\.|\.\]|{\.|\.}|\(\.|\.\)|{|}|\(|\)|:|\^|`|;', |
|
2641 Punctuation), |
|
2642 |
|
2643 # Strings |
|
2644 (r'(?:[\w]+)"', String, 'rdqs'), |
|
2645 (r'"""', String, 'tdqs'), |
|
2646 ('"', String, 'dqs'), |
|
2647 |
|
2648 # Char |
|
2649 ("'", String.Char, 'chars'), |
|
2650 |
|
2651 # Keywords |
|
2652 (r'(%s)\b' % underscorize(opWords), Operator.Word), |
|
2653 (r'(p_?r_?o_?c_?\s)(?![\(\[\]])', Keyword, 'funcname'), |
|
2654 (r'(%s)\b' % underscorize(keywords), Keyword), |
|
2655 (r'(%s)\b' % underscorize(['from', 'import', 'include']), |
|
2656 Keyword.Namespace), |
|
2657 (r'(v_?a_?r)\b', Keyword.Declaration), |
|
2658 (r'(%s)\b' % underscorize(types), Keyword.Type), |
|
2659 (r'(%s)\b' % underscorize(keywordsPseudo), Keyword.Pseudo), |
|
2660 # Identifiers |
|
2661 (r'\b((?![_\d])\w)(((?!_)\w)|(_(?!_)\w))*', Name), |
|
2662 # Numbers |
|
2663 (r'[0-9][0-9_]*(?=([eE.]|\'[fF](32|64)))', |
|
2664 Number.Float, ('float-suffix', 'float-number')), |
|
2665 (r'0[xX][a-fA-F0-9][a-fA-F0-9_]*', Number.Hex, 'int-suffix'), |
|
2666 (r'0[bB][01][01_]*', Number, 'int-suffix'), |
|
2667 (r'0o[0-7][0-7_]*', Number.Oct, 'int-suffix'), |
|
2668 (r'[0-9][0-9_]*', Number.Integer, 'int-suffix'), |
|
2669 # Whitespace |
|
2670 (r'\s+', Text), |
|
2671 (r'.+$', Error), |
|
2672 ], |
|
2673 'chars': [ |
|
2674 (r'\\([\\abcefnrtvl"\']|x[a-fA-F0-9]{2}|[0-9]{1,3})', String.Escape), |
|
2675 (r"'", String.Char, '#pop'), |
|
2676 (r".", String.Char) |
|
2677 ], |
|
2678 'strings': [ |
|
2679 (r'(?<!\$)\$(\d+|#|\w+)+', String.Interpol), |
|
2680 (r'[^\\\'"\$\n]+', String), |
|
2681 # quotes, dollars and backslashes must be parsed one at a time |
|
2682 (r'[\'"\\]', String), |
|
2683 # unhandled string formatting sign |
|
2684 (r'\$', String) |
|
2685 # newlines are an error (use "nl" state) |
|
2686 ], |
|
2687 'dqs': [ |
|
2688 (r'\\([\\abcefnrtvl"\']|\n|x[a-fA-F0-9]{2}|[0-9]{1,3})', |
|
2689 String.Escape), |
|
2690 (r'"', String, '#pop'), |
|
2691 include('strings') |
|
2692 ], |
|
2693 'rdqs': [ |
|
2694 (r'"(?!")', String, '#pop'), |
|
2695 (r'""', String.Escape), |
|
2696 include('strings') |
|
2697 ], |
|
2698 'tdqs': [ |
|
2699 (r'"""(?!")', String, '#pop'), |
|
2700 include('strings'), |
|
2701 include('nl') |
|
2702 ], |
|
2703 'funcname': [ |
|
2704 (r'((?![\d_])\w)(((?!_)\w)|(_(?!_)\w))*', Name.Function, '#pop'), |
|
2705 (r'`.+`', Name.Function, '#pop') |
|
2706 ], |
|
2707 'nl': [ |
|
2708 (r'\n', String) |
|
2709 ], |
|
2710 'float-number': [ |
|
2711 (r'\.(?!\.)[0-9_]*', Number.Float), |
|
2712 (r'[eE][+-]?[0-9][0-9_]*', Number.Float), |
|
2713 (r'', Text, '#pop') |
|
2714 ], |
|
2715 'float-suffix': [ |
|
2716 (r'\'[fF](32|64)', Number.Float), |
|
2717 (r'', Text, '#pop') |
|
2718 ], |
|
2719 'int-suffix': [ |
|
2720 (r'\'[iI](32|64)', Number.Integer.Long), |
|
2721 (r'\'[iI](8|16)', Number.Integer), |
|
2722 (r'', Text, '#pop') |
|
2723 ], |
|
2724 } |
|
2725 |
|
2726 |
|
2727 class FantomLexer(RegexLexer): |
|
2728 """ |
|
2729 For Fantom source code. |
|
2730 |
|
2731 *New in Pygments 1.5.* |
|
2732 """ |
|
2733 name = 'Fantom' |
|
2734 aliases = ['fan'] |
|
2735 filenames = ['*.fan'] |
|
2736 mimetypes = ['application/x-fantom'] |
|
2737 |
|
2738 # often used regexes |
|
2739 def s(str): |
|
2740 return Template(str).substitute( |
|
2741 dict ( |
|
2742 pod = r'[\"\w\.]+', |
|
2743 eos = r'\n|;', |
|
2744 id = r'[a-zA-Z_][a-zA-Z0-9_]*', |
|
2745 # all chars which can be part of type definition. Starts with |
|
2746 # either letter, or [ (maps), or | (funcs) |
|
2747 type = r'(?:\[|[a-zA-Z_]|\|)[:\w\[\]\|\->\?]*?', |
|
2748 ) |
|
2749 ) |
|
2750 |
|
2751 |
|
2752 tokens = { |
|
2753 'comments': [ |
|
2754 (r'(?s)/\*.*?\*/', Comment.Multiline), #Multiline |
|
2755 (r'//.*?\n', Comment.Single), #Single line |
|
2756 #todo: highlight references in fandocs |
|
2757 (r'\*\*.*?\n', Comment.Special), #Fandoc |
|
2758 (r'#.*\n', Comment.Single) #Shell-style |
|
2759 ], |
|
2760 'literals': [ |
|
2761 (r'\b-?[\d_]+(ns|ms|sec|min|hr|day)', Number), #Duration |
|
2762 (r'\b-?[\d_]*\.[\d_]+(ns|ms|sec|min|hr|day)', Number), |
|
2763 #Duration with dot |
|
2764 (r'\b-?(\d+)?\.\d+(f|F|d|D)?', Number.Float), #Float/Decimal |
|
2765 (r'\b-?0x[0-9a-fA-F_]+', Number.Hex), #Hex |
|
2766 (r'\b-?[\d_]+', Number.Integer), #Int |
|
2767 (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char), #Char |
|
2768 (r'"', Punctuation, 'insideStr'), #Opening quote |
|
2769 (r'`', Punctuation, 'insideUri'), #Opening accent |
|
2770 (r'\b(true|false|null)\b', Keyword.Constant), #Bool & null |
|
2771 (r'(?:(\w+)(::))?(\w+)(<\|)(.*?)(\|>)', #DSL |
|
2772 bygroups(Name.Namespace, Punctuation, Name.Class, |
|
2773 Punctuation, String, Punctuation)), |
|
2774 (r'(?:(\w+)(::))?(\w+)?(#)(\w+)?', #Type/slot literal |
|
2775 bygroups(Name.Namespace, Punctuation, Name.Class, |
|
2776 Punctuation, Name.Function)), |
|
2777 (r'\[,\]', Literal), # Empty list |
|
2778 (s(r'($type)(\[,\])'), # Typed empty list |
|
2779 bygroups(using(this, state = 'inType'), Literal)), |
|
2780 (r'\[:\]', Literal), # Empty Map |
|
2781 (s(r'($type)(\[:\])'), |
|
2782 bygroups(using(this, state = 'inType'), Literal)), |
|
2783 ], |
|
2784 'insideStr': [ |
|
2785 (r'\\\\', String.Escape), #Escaped backslash |
|
2786 (r'\\"', String.Escape), #Escaped " |
|
2787 (r'\\`', String.Escape), #Escaped ` |
|
2788 (r'\$\w+', String.Interpol), #Subst var |
|
2789 (r'\${.*?}', String.Interpol), #Subst expr |
|
2790 (r'"', Punctuation, '#pop'), #Closing quot |
|
2791 (r'.', String) #String content |
|
2792 ], |
|
2793 'insideUri': [ #TODO: remove copy/paste str/uri |
|
2794 (r'\\\\', String.Escape), #Escaped backslash |
|
2795 (r'\\"', String.Escape), #Escaped " |
|
2796 (r'\\`', String.Escape), #Escaped ` |
|
2797 (r'\$\w+', String.Interpol), #Subst var |
|
2798 (r'\${.*?}', String.Interpol), #Subst expr |
|
2799 (r'`', Punctuation, '#pop'), #Closing tick |
|
2800 (r'.', String.Backtick) #URI content |
|
2801 ], |
|
2802 'protectionKeywords': [ |
|
2803 (r'\b(public|protected|private|internal)\b', Keyword), |
|
2804 ], |
|
2805 'typeKeywords': [ |
|
2806 (r'\b(abstract|final|const|native|facet|enum)\b', Keyword), |
|
2807 ], |
|
2808 'methodKeywords': [ |
|
2809 (r'\b(abstract|native|once|override|static|virtual|final)\b', |
|
2810 Keyword), |
|
2811 ], |
|
2812 'fieldKeywords': [ |
|
2813 (r'\b(abstract|const|final|native|override|static|virtual|' |
|
2814 r'readonly)\b', Keyword) |
|
2815 ], |
|
2816 'otherKeywords': [ |
|
2817 (r'\b(try|catch|throw|finally|for|if|else|while|as|is|isnot|' |
|
2818 r'switch|case|default|continue|break|do|return|get|set)\b', |
|
2819 Keyword), |
|
2820 (r'\b(it|this|super)\b', Name.Builtin.Pseudo), |
|
2821 ], |
|
2822 'operators': [ |
|
2823 (r'\+\+|\-\-|\+|\-|\*|/|\|\||&&|<=>|<=|<|>=|>|=|!|\[|\]', Operator) |
|
2824 ], |
|
2825 'inType': [ |
|
2826 (r'[\[\]\|\->:\?]', Punctuation), |
|
2827 (s(r'$id'), Name.Class), |
|
2828 (r'', Text, '#pop'), |
|
2829 |
|
2830 ], |
|
2831 'root': [ |
|
2832 include('comments'), |
|
2833 include('protectionKeywords'), |
|
2834 include('typeKeywords'), |
|
2835 include('methodKeywords'), |
|
2836 include('fieldKeywords'), |
|
2837 include('literals'), |
|
2838 include('otherKeywords'), |
|
2839 include('operators'), |
|
2840 (r'using\b', Keyword.Namespace, 'using'), # Using stmt |
|
2841 (r'@\w+', Name.Decorator, 'facet'), # Symbol |
|
2842 (r'(class|mixin)(\s+)(\w+)', bygroups(Keyword, Text, Name.Class), |
|
2843 'inheritance'), # Inheritance list |
|
2844 |
|
2845 |
|
2846 ### Type var := val |
|
2847 (s(r'($type)([ \t]+)($id)(\s*)(:=)'), |
|
2848 bygroups(using(this, state = 'inType'), Text, |
|
2849 Name.Variable, Text, Operator)), |
|
2850 |
|
2851 ### var := val |
|
2852 (s(r'($id)(\s*)(:=)'), |
|
2853 bygroups(Name.Variable, Text, Operator)), |
|
2854 |
|
2855 ### .someId( or ->someId( ### |
|
2856 (s(r'(\.|(?:\->))($id)(\s*)(\()'), |
|
2857 bygroups(Operator, Name.Function, Text, Punctuation), |
|
2858 'insideParen'), |
|
2859 |
|
2860 ### .someId or ->someId |
|
2861 (s(r'(\.|(?:\->))($id)'), |
|
2862 bygroups(Operator, Name.Function)), |
|
2863 |
|
2864 ### new makeXXX ( #### |
|
2865 (r'(new)(\s+)(make\w*)(\s*)(\()', |
|
2866 bygroups(Keyword, Text, Name.Function, Text, Punctuation), |
|
2867 'insideMethodDeclArgs'), |
|
2868 |
|
2869 ### Type name ( #### |
|
2870 (s(r'($type)([ \t]+)' #Return type and whitespace |
|
2871 r'($id)(\s*)(\()'), #method name + open brace |
|
2872 bygroups(using(this, state = 'inType'), Text, |
|
2873 Name.Function, Text, Punctuation), |
|
2874 'insideMethodDeclArgs'), |
|
2875 |
|
2876 ### ArgType argName, ##### |
|
2877 (s(r'($type)(\s+)($id)(\s*)(,)'), |
|
2878 bygroups(using(this, state='inType'), Text, Name.Variable, |
|
2879 Text, Punctuation)), |
|
2880 |
|
2881 #### ArgType argName) #### |
|
2882 ## Covered in 'insideParen' state |
|
2883 |
|
2884 ### ArgType argName -> ArgType| ### |
|
2885 (s(r'($type)(\s+)($id)(\s*)(\->)(\s*)($type)(\|)'), |
|
2886 bygroups(using(this, state='inType'), Text, Name.Variable, |
|
2887 Text, Punctuation, Text, using(this, state = 'inType'), |
|
2888 Punctuation)), |
|
2889 |
|
2890 ### ArgType argName| ### |
|
2891 (s(r'($type)(\s+)($id)(\s*)(\|)'), |
|
2892 bygroups(using(this, state='inType'), Text, Name.Variable, |
|
2893 Text, Punctuation)), |
|
2894 |
|
2895 ### Type var |
|
2896 (s(r'($type)([ \t]+)($id)'), |
|
2897 bygroups(using(this, state='inType'), Text, |
|
2898 Name.Variable)), |
|
2899 |
|
2900 (r'\(', Punctuation, 'insideParen'), |
|
2901 (r'\{', Punctuation, 'insideBrace'), |
|
2902 (r'.', Text) |
|
2903 ], |
|
2904 'insideParen': [ |
|
2905 (r'\)', Punctuation, '#pop'), |
|
2906 include('root'), |
|
2907 ], |
|
2908 'insideMethodDeclArgs': [ |
|
2909 (r'\)', Punctuation, '#pop'), |
|
2910 (s(r'($type)(\s+)($id)(\s*)(\))'), |
|
2911 bygroups(using(this, state='inType'), Text, Name.Variable, |
|
2912 Text, Punctuation), '#pop'), |
|
2913 include('root'), |
|
2914 ], |
|
2915 'insideBrace': [ |
|
2916 (r'\}', Punctuation, '#pop'), |
|
2917 include('root'), |
|
2918 ], |
|
2919 'inheritance': [ |
|
2920 (r'\s+', Text), #Whitespace |
|
2921 (r':|,', Punctuation), |
|
2922 (r'(?:(\w+)(::))?(\w+)', |
|
2923 bygroups(Name.Namespace, Punctuation, Name.Class)), |
|
2924 (r'{', Punctuation, '#pop') |
|
2925 ], |
|
2926 'using': [ |
|
2927 (r'[ \t]+', Text), # consume whitespaces |
|
2928 (r'(\[)(\w+)(\])', |
|
2929 bygroups(Punctuation, Comment.Special, Punctuation)), #ffi |
|
2930 (r'(\")?([\w\.]+)(\")?', |
|
2931 bygroups(Punctuation, Name.Namespace, Punctuation)), #podname |
|
2932 (r'::', Punctuation, 'usingClass'), |
|
2933 (r'', Text, '#pop') |
|
2934 ], |
|
2935 'usingClass': [ |
|
2936 (r'[ \t]+', Text), # consume whitespaces |
|
2937 (r'(as)(\s+)(\w+)', |
|
2938 bygroups(Keyword.Declaration, Text, Name.Class), '#pop:2'), |
|
2939 (r'[\w\$]+', Name.Class), |
|
2940 (r'', Text, '#pop:2') # jump out to root state |
|
2941 ], |
|
2942 'facet': [ |
|
2943 (r'\s+', Text), |
|
2944 (r'{', Punctuation, 'facetFields'), |
|
2945 (r'', Text, '#pop') |
|
2946 ], |
|
2947 'facetFields': [ |
|
2948 include('comments'), |
|
2949 include('literals'), |
|
2950 include('operators'), |
|
2951 (r'\s+', Text), |
|
2952 (r'(\s*)(\w+)(\s*)(=)', bygroups(Text, Name, Text, Operator)), |
|
2953 (r'}', Punctuation, '#pop'), |
|
2954 (r'.', Text) |
|
2955 ], |
|
2956 } |
|
2957 |
|
2958 |
|
2959 class RustLexer(RegexLexer): |
|
2960 """ |
|
2961 Lexer for Mozilla's Rust programming language. |
|
2962 |
|
2963 *New in Pygments 1.6.* |
|
2964 """ |
|
2965 name = 'Rust' |
|
2966 filenames = ['*.rs', '*.rc'] |
|
2967 aliases = ['rust'] |
|
2968 mimetypes = ['text/x-rustsrc'] |
|
2969 |
|
2970 tokens = { |
|
2971 'root': [ |
|
2972 # Whitespace and Comments |
|
2973 (r'\n', Text), |
|
2974 (r'\s+', Text), |
|
2975 (r'//(.*?)\n', Comment.Single), |
|
2976 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
|
2977 |
|
2978 # Keywords |
|
2979 (r'(as|assert|break|const' |
|
2980 r'|copy|do|else|enum|extern|fail' |
|
2981 r'|false|fn|for|if|impl|let|log' |
|
2982 r'|loop|match|mod|move|mut|once|priv|pub|pure' |
|
2983 r'|ref|return|static|struct|trait|true|type|unsafe|use|while' |
|
2984 r'|u8|u16|u32|u64|i8|i16|i32|i64|uint' |
|
2985 r'|int|float|f32|f64|str)\b', Keyword), |
|
2986 |
|
2987 # Character Literal |
|
2988 (r"""'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" |
|
2989 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""", |
|
2990 String.Char), |
|
2991 # Binary Literal |
|
2992 (r'0[Bb][01_]+', Number, 'number_lit'), |
|
2993 # Octal Literal |
|
2994 (r'0[0-7_]+', Number.Oct, 'number_lit'), |
|
2995 # Hexadecimal Literal |
|
2996 (r'0[xX][0-9a-fA-F_]+', Number.Hex, 'number_lit'), |
|
2997 # Decimal Literal |
|
2998 (r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?' |
|
2999 r'[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+)?', Number, 'number_lit'), |
|
3000 # String Literal |
|
3001 (r'"', String, 'string'), |
|
3002 |
|
3003 # Operators and Punctuation |
|
3004 (r'[{}()\[\],.;]', Punctuation), |
|
3005 (r'[+\-*/%&|<>^!~@=:?]', Operator), |
|
3006 |
|
3007 # Identifier |
|
3008 (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), |
|
3009 |
|
3010 # Attributes |
|
3011 (r'#\[', Comment.Preproc, 'attribute['), |
|
3012 (r'#\(', Comment.Preproc, 'attribute('), |
|
3013 # Macros |
|
3014 (r'[A-Za-z_][A-Za-z0-9_]*!\[', Comment.Preproc, 'attribute['), |
|
3015 (r'[A-Za-z_][A-Za-z0-9_]*!\(', Comment.Preproc, 'attribute('), |
|
3016 ], |
|
3017 'number_lit': [ |
|
3018 (r'(([ui](8|16|32|64)?)|(f(32|64)?))?', Keyword, '#pop'), |
|
3019 ], |
|
3020 'string': [ |
|
3021 (r'"', String, '#pop'), |
|
3022 (r"""\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" |
|
3023 r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}""", String.Escape), |
|
3024 (r'[^\\"]+', String), |
|
3025 (r'\\', String), |
|
3026 ], |
|
3027 'attribute_common': [ |
|
3028 (r'"', String, 'string'), |
|
3029 (r'\[', Comment.Preproc, 'attribute['), |
|
3030 (r'\(', Comment.Preproc, 'attribute('), |
|
3031 ], |
|
3032 'attribute[': [ |
|
3033 include('attribute_common'), |
|
3034 (r'\];?', Comment.Preproc, '#pop'), |
|
3035 (r'[^"\]]+', Comment.Preproc), |
|
3036 ], |
|
3037 'attribute(': [ |
|
3038 include('attribute_common'), |
|
3039 (r'\);?', Comment.Preproc, '#pop'), |
|
3040 (r'[^"\)]+', Comment.Preproc), |
|
3041 ], |
|
3042 } |
|
3043 |
|
3044 |
|
3045 class CudaLexer(CLexer): |
|
3046 """ |
|
3047 For NVIDIA `CUDAâ„¢ <http://developer.nvidia.com/category/zone/cuda-zone>`_ |
|
3048 source. |
|
3049 |
|
3050 *New in Pygments 1.6.* |
|
3051 """ |
|
3052 name = 'CUDA' |
|
3053 filenames = ['*.cu', '*.cuh'] |
|
3054 aliases = ['cuda', 'cu'] |
|
3055 mimetypes = ['text/x-cuda'] |
|
3056 |
|
3057 function_qualifiers = ['__device__', '__global__', '__host__', |
|
3058 '__noinline__', '__forceinline__'] |
|
3059 variable_qualifiers = ['__device__', '__constant__', '__shared__', |
|
3060 '__restrict__'] |
|
3061 vector_types = ['char1', 'uchar1', 'char2', 'uchar2', 'char3', 'uchar3', |
|
3062 'char4', 'uchar4', 'short1', 'ushort1', 'short2', 'ushort2', |
|
3063 'short3', 'ushort3', 'short4', 'ushort4', 'int1', 'uint1', |
|
3064 'int2', 'uint2', 'int3', 'uint3', 'int4', 'uint4', 'long1', |
|
3065 'ulong1', 'long2', 'ulong2', 'long3', 'ulong3', 'long4', |
|
3066 'ulong4', 'longlong1', 'ulonglong1', 'longlong2', |
|
3067 'ulonglong2', 'float1', 'float2', 'float3', 'float4', |
|
3068 'double1', 'double2', 'dim3'] |
|
3069 variables = ['gridDim', 'blockIdx', 'blockDim', 'threadIdx', 'warpSize'] |
|
3070 functions = ['__threadfence_block', '__threadfence', '__threadfence_system', |
|
3071 '__syncthreads', '__syncthreads_count', '__syncthreads_and', |
|
3072 '__syncthreads_or'] |
|
3073 execution_confs = ['<<<', '>>>'] |
|
3074 |
|
3075 def get_tokens_unprocessed(self, text): |
|
3076 for index, token, value in \ |
|
3077 CLexer.get_tokens_unprocessed(self, text): |
|
3078 if token is Name: |
|
3079 if value in self.variable_qualifiers: |
|
3080 token = Keyword.Type |
|
3081 elif value in self.vector_types: |
|
3082 token = Keyword.Type |
|
3083 elif value in self.variables: |
|
3084 token = Name.Builtin |
|
3085 elif value in self.execution_confs: |
|
3086 token = Keyword.Pseudo |
|
3087 elif value in self.function_qualifiers: |
|
3088 token = Keyword.Reserved |
|
3089 elif value in self.functions: |
|
3090 token = Name.Function |
|
3091 yield index, token, value |
|
3092 |
|
3093 |
|
3094 class MonkeyLexer(RegexLexer): |
|
3095 """ |
|
3096 For |
|
3097 `Monkey <https://en.wikipedia.org/wiki/Monkey_(programming_language)>`_ |
|
3098 source code. |
|
3099 |
|
3100 *New in Pygments 1.6.* |
|
3101 """ |
|
3102 |
|
3103 name = 'Monkey' |
|
3104 aliases = ['monkey'] |
|
3105 filenames = ['*.monkey'] |
|
3106 mimetypes = ['text/x-monkey'] |
|
3107 |
|
3108 name_variable = r'[a-z_][a-zA-Z0-9_]*' |
|
3109 name_function = r'[A-Z][a-zA-Z0-9_]*' |
|
3110 name_constant = r'[A-Z_][A-Z0-9_]*' |
|
3111 name_class = r'[A-Z][a-zA-Z0-9_]*' |
|
3112 name_module = r'[a-z0-9_]*' |
|
3113 |
|
3114 keyword_type = r'(?:Int|Float|String|Bool|Object|Array|Void)' |
|
3115 # ? == Bool // % == Int // # == Float // $ == String |
|
3116 keyword_type_special = r'[?%#$]' |
|
3117 |
|
3118 flags = re.MULTILINE |
|
3119 |
|
3120 tokens = { |
|
3121 'root': [ |
|
3122 #Text |
|
3123 (r'\s+', Text), |
|
3124 # Comments |
|
3125 (r"'.*", Comment), |
|
3126 (r'(?i)^#rem\b', Comment.Multiline, 'comment'), |
|
3127 # preprocessor directives |
|
3128 (r'(?i)^(?:#If|#ElseIf|#Else|#EndIf|#End|#Print|#Error)\b', Comment.Preproc), |
|
3129 # preprocessor variable (any line starting with '#' that is not a directive) |
|
3130 (r'^#', Comment.Preproc, 'variables'), |
|
3131 # String |
|
3132 ('"', String.Double, 'string'), |
|
3133 # Numbers |
|
3134 (r'[0-9]+\.[0-9]*(?!\.)', Number.Float), |
|
3135 (r'\.[0-9]+(?!\.)', Number.Float), |
|
3136 (r'[0-9]+', Number.Integer), |
|
3137 (r'\$[0-9a-fA-Z]+', Number.Hex), |
|
3138 (r'\%[10]+', Number), # Binary |
|
3139 # Native data types |
|
3140 (r'\b%s\b' % keyword_type, Keyword.Type), |
|
3141 # Exception handling |
|
3142 (r'(?i)\b(?:Try|Catch|Throw)\b', Keyword.Reserved), |
|
3143 (r'Throwable', Name.Exception), |
|
3144 # Builtins |
|
3145 (r'(?i)\b(?:Null|True|False)\b', Name.Builtin), |
|
3146 (r'(?i)\b(?:Self|Super)\b', Name.Builtin.Pseudo), |
|
3147 (r'\b(?:HOST|LANG|TARGET|CONFIG)\b', Name.Constant), |
|
3148 # Keywords |
|
3149 (r'(?i)^(Import)(\s+)(.*)(\n)', |
|
3150 bygroups(Keyword.Namespace, Text, Name.Namespace, Text)), |
|
3151 (r'(?i)^Strict\b.*\n', Keyword.Reserved), |
|
3152 (r'(?i)(Const|Local|Global|Field)(\s+)', |
|
3153 bygroups(Keyword.Declaration, Text), 'variables'), |
|
3154 (r'(?i)(New|Class|Interface|Extends|Implements)(\s+)', |
|
3155 bygroups(Keyword.Reserved, Text), 'classname'), |
|
3156 (r'(?i)(Function|Method)(\s+)', |
|
3157 bygroups(Keyword.Reserved, Text), 'funcname'), |
|
3158 (r'(?i)(?:End|Return|Public|Private|Extern|Property|' |
|
3159 r'Final|Abstract)\b', Keyword.Reserved), |
|
3160 # Flow Control stuff |
|
3161 (r'(?i)(?:If|Then|Else|ElseIf|EndIf|' |
|
3162 r'Select|Case|Default|' |
|
3163 r'While|Wend|' |
|
3164 r'Repeat|Until|Forever|' |
|
3165 r'For|To|Until|Step|EachIn|Next|' |
|
3166 r'Exit|Continue)\s+', Keyword.Reserved), |
|
3167 # not used yet |
|
3168 (r'(?i)\b(?:Module|Inline)\b', Keyword.Reserved), |
|
3169 # Array |
|
3170 (r'[\[\]]', Punctuation), |
|
3171 # Other |
|
3172 (r'<=|>=|<>|\*=|/=|\+=|-=|&=|~=|\|=|[-&*/^+=<>|~]', Operator), |
|
3173 (r'(?i)(?:Not|Mod|Shl|Shr|And|Or)', Operator.Word), |
|
3174 (r'[\(\){}!#,.:]', Punctuation), |
|
3175 # catch the rest |
|
3176 (r'%s\b' % name_constant, Name.Constant), |
|
3177 (r'%s\b' % name_function, Name.Function), |
|
3178 (r'%s\b' % name_variable, Name.Variable), |
|
3179 ], |
|
3180 'funcname': [ |
|
3181 (r'(?i)%s\b' % name_function, Name.Function), |
|
3182 (r':', Punctuation, 'classname'), |
|
3183 (r'\s+', Text), |
|
3184 (r'\(', Punctuation, 'variables'), |
|
3185 (r'\)', Punctuation, '#pop') |
|
3186 ], |
|
3187 'classname': [ |
|
3188 (r'%s\.' % name_module, Name.Namespace), |
|
3189 (r'%s\b' % keyword_type, Keyword.Type), |
|
3190 (r'%s\b' % name_class, Name.Class), |
|
3191 # array (of given size) |
|
3192 (r'(\[)(\s*)(\d*)(\s*)(\])', |
|
3193 bygroups(Punctuation, Text, Number.Integer, Text, Punctuation)), |
|
3194 # generics |
|
3195 (r'\s+(?!<)', Text, '#pop'), |
|
3196 (r'<', Punctuation, '#push'), |
|
3197 (r'>', Punctuation, '#pop'), |
|
3198 (r'\n', Text, '#pop'), |
|
3199 (r'', Text, '#pop') |
|
3200 ], |
|
3201 'variables': [ |
|
3202 (r'%s\b' % name_constant, Name.Constant), |
|
3203 (r'%s\b' % name_variable, Name.Variable), |
|
3204 (r'%s' % keyword_type_special, Keyword.Type), |
|
3205 (r'\s+', Text), |
|
3206 (r':', Punctuation, 'classname'), |
|
3207 (r',', Punctuation, '#push'), |
|
3208 (r'', Text, '#pop') |
|
3209 ], |
|
3210 'string': [ |
|
3211 (r'[^"~]+', String.Double), |
|
3212 (r'~q|~n|~r|~t|~z|~~', String.Escape), |
|
3213 (r'"', String.Double, '#pop'), |
|
3214 ], |
|
3215 'comment' : [ |
|
3216 (r'(?i)^#rem.*?', Comment.Multiline, "#push"), |
|
3217 (r'(?i)^#end.*?', Comment.Multiline, "#pop"), |
|
3218 (r'\n', Comment.Multiline), |
|
3219 (r'.+', Comment.Multiline), |
|
3220 ], |
|
3221 } |
|
3222 |
|
3223 |
|
3224 class CobolLexer(RegexLexer): |
|
3225 """ |
|
3226 Lexer for OpenCOBOL code. |
|
3227 |
|
3228 *New in Pygments 1.6.* |
|
3229 """ |
|
3230 name = 'COBOL' |
|
3231 aliases = ['cobol'] |
|
3232 filenames = ['*.cob', '*.COB', '*.cpy', '*.CPY'] |
|
3233 mimetypes = ['text/x-cobol'] |
|
3234 flags = re.IGNORECASE | re.MULTILINE |
|
3235 |
|
3236 # Data Types: by PICTURE and USAGE |
|
3237 # Operators: **, *, +, -, /, <, >, <=, >=, =, <> |
|
3238 # Logical (?): NOT, AND, OR |
|
3239 |
|
3240 # Reserved words: |
|
3241 # http://opencobol.add1tocobol.com/#reserved-words |
|
3242 # Intrinsics: |
|
3243 # http://opencobol.add1tocobol.com/#does-opencobol-implement-any-intrinsic-functions |
|
3244 |
|
3245 tokens = { |
|
3246 'root': [ |
|
3247 include('comment'), |
|
3248 include('strings'), |
|
3249 include('core'), |
|
3250 include('nums'), |
|
3251 (r'[a-z0-9]([_a-z0-9\-]*[a-z0-9]+)?', Name.Variable), |
|
3252 # (r'[\s]+', Text), |
|
3253 (r'[ \t]+', Text), |
|
3254 ], |
|
3255 'comment': [ |
|
3256 (r'(^.{6}[*/].*\n|^.{6}|\*>.*\n)', Comment), |
|
3257 ], |
|
3258 'core': [ |
|
3259 # Figurative constants |
|
3260 (r'(^|(?<=[^0-9a-z_\-]))(ALL\s+)?' |
|
3261 r'((ZEROES)|(HIGH-VALUE|LOW-VALUE|QUOTE|SPACE|ZERO)(S)?)' |
|
3262 r'\s*($|(?=[^0-9a-z_\-]))', |
|
3263 Name.Constant), |
|
3264 |
|
3265 # Reserved words STATEMENTS and other bolds |
|
3266 (r'(^|(?<=[^0-9a-z_\-]))' |
|
3267 r'(ACCEPT|ADD|ALLOCATE|CALL|CANCEL|CLOSE|COMPUTE|' |
|
3268 r'CONFIGURATION|CONTINUE|' |
|
3269 r'DATA|DELETE|DISPLAY|DIVIDE|DIVISION|ELSE|END|END-ACCEPT|' |
|
3270 r'END-ADD|END-CALL|END-COMPUTE|END-DELETE|END-DISPLAY|' |
|
3271 r'END-DIVIDE|END-EVALUATE|END-IF|END-MULTIPLY|END-OF-PAGE|' |
|
3272 r'END-PERFORM|END-READ|END-RETURN|END-REWRITE|END-SEARCH|' |
|
3273 r'END-START|END-STRING|END-SUBTRACT|END-UNSTRING|END-WRITE|' |
|
3274 r'ENVIRONMENT|EVALUATE|EXIT|FD|FILE|FILE-CONTROL|FOREVER|' |
|
3275 r'FREE|GENERATE|GO|GOBACK|' |
|
3276 r'IDENTIFICATION|IF|INITIALIZE|' |
|
3277 r'INITIATE|INPUT-OUTPUT|INSPECT|INVOKE|I-O-CONTROL|LINKAGE|' |
|
3278 r'LOCAL-STORAGE|MERGE|MOVE|MULTIPLY|OPEN|' |
|
3279 r'PERFORM|PROCEDURE|PROGRAM-ID|RAISE|READ|RELEASE|RESUME|' |
|
3280 r'RETURN|REWRITE|SCREEN|' |
|
3281 r'SD|SEARCH|SECTION|SET|SORT|START|STOP|STRING|SUBTRACT|' |
|
3282 r'SUPPRESS|TERMINATE|THEN|UNLOCK|UNSTRING|USE|VALIDATE|' |
|
3283 r'WORKING-STORAGE|WRITE)' |
|
3284 r'\s*($|(?=[^0-9a-z_\-]))', Keyword.Reserved), |
|
3285 |
|
3286 # Reserved words |
|
3287 (r'(^|(?<=[^0-9a-z_\-]))' |
|
3288 r'(ACCESS|ADDRESS|ADVANCING|AFTER|ALL|' |
|
3289 r'ALPHABET|ALPHABETIC|ALPHABETIC-LOWER|ALPHABETIC-UPPER|' |
|
3290 r'ALPHANUMERIC|ALPHANUMERIC-EDITED|ALSO|ALTER|ALTERNATE' |
|
3291 r'ANY|ARE|AREA|AREAS|ARGUMENT-NUMBER|ARGUMENT-VALUE|AS|' |
|
3292 r'ASCENDING|ASSIGN|AT|AUTO|AUTO-SKIP|AUTOMATIC|AUTOTERMINATE|' |
|
3293 r'BACKGROUND-COLOR|BASED|BEEP|BEFORE|BELL|' |
|
3294 r'BLANK|' |
|
3295 r'BLINK|BLOCK|BOTTOM|BY|BYTE-LENGTH|CHAINING|' |
|
3296 r'CHARACTER|CHARACTERS|CLASS|CODE|CODE-SET|COL|COLLATING|' |
|
3297 r'COLS|COLUMN|COLUMNS|COMMA|COMMAND-LINE|COMMIT|COMMON|' |
|
3298 r'CONSTANT|CONTAINS|CONTENT|CONTROL|' |
|
3299 r'CONTROLS|CONVERTING|COPY|CORR|CORRESPONDING|COUNT|CRT|' |
|
3300 r'CURRENCY|CURSOR|CYCLE|DATE|DAY|DAY-OF-WEEK|DE|DEBUGGING|' |
|
3301 r'DECIMAL-POINT|DECLARATIVES|DEFAULT|DELIMITED|' |
|
3302 r'DELIMITER|DEPENDING|DESCENDING|DETAIL|DISK|' |
|
3303 r'DOWN|DUPLICATES|DYNAMIC|EBCDIC|' |
|
3304 r'ENTRY|ENVIRONMENT-NAME|ENVIRONMENT-VALUE|EOL|EOP|' |
|
3305 r'EOS|ERASE|ERROR|ESCAPE|EXCEPTION|' |
|
3306 r'EXCLUSIVE|EXTEND|EXTERNAL|' |
|
3307 r'FILE-ID|FILLER|FINAL|FIRST|FIXED|FLOAT-LONG|FLOAT-SHORT|' |
|
3308 r'FOOTING|FOR|FOREGROUND-COLOR|FORMAT|FROM|FULL|FUNCTION|' |
|
3309 r'FUNCTION-ID|GIVING|GLOBAL|GROUP|' |
|
3310 r'HEADING|HIGHLIGHT|I-O|ID|' |
|
3311 r'IGNORE|IGNORING|IN|INDEX|INDEXED|INDICATE|' |
|
3312 r'INITIAL|INITIALIZED|INPUT|' |
|
3313 r'INTO|INTRINSIC|INVALID|IS|JUST|JUSTIFIED|KEY|LABEL|' |
|
3314 r'LAST|LEADING|LEFT|LENGTH|LIMIT|LIMITS|LINAGE|' |
|
3315 r'LINAGE-COUNTER|LINE|LINES|LOCALE|LOCK|' |
|
3316 r'LOWLIGHT|MANUAL|MEMORY|MINUS|MODE|' |
|
3317 r'MULTIPLE|NATIONAL|NATIONAL-EDITED|NATIVE|' |
|
3318 r'NEGATIVE|NEXT|NO|NULL|NULLS|NUMBER|NUMBERS|NUMERIC|' |
|
3319 r'NUMERIC-EDITED|OBJECT-COMPUTER|OCCURS|OF|OFF|OMITTED|ON|ONLY|' |
|
3320 r'OPTIONAL|ORDER|ORGANIZATION|OTHER|OUTPUT|OVERFLOW|' |
|
3321 r'OVERLINE|PACKED-DECIMAL|PADDING|PAGE|PARAGRAPH|' |
|
3322 r'PLUS|POINTER|POSITION|POSITIVE|PRESENT|PREVIOUS|' |
|
3323 r'PRINTER|PRINTING|PROCEDURE-POINTER|PROCEDURES|' |
|
3324 r'PROCEED|PROGRAM|PROGRAM-POINTER|PROMPT|QUOTE|' |
|
3325 r'QUOTES|RANDOM|RD|RECORD|RECORDING|RECORDS|RECURSIVE|' |
|
3326 r'REDEFINES|REEL|REFERENCE|RELATIVE|REMAINDER|REMOVAL|' |
|
3327 r'RENAMES|REPLACING|REPORT|REPORTING|REPORTS|REPOSITORY|' |
|
3328 r'REQUIRED|RESERVE|RETURNING|REVERSE-VIDEO|REWIND|' |
|
3329 r'RIGHT|ROLLBACK|ROUNDED|RUN|SAME|SCROLL|' |
|
3330 r'SECURE|SEGMENT-LIMIT|SELECT|SENTENCE|SEPARATE|' |
|
3331 r'SEQUENCE|SEQUENTIAL|SHARING|SIGN|SIGNED|SIGNED-INT|' |
|
3332 r'SIGNED-LONG|SIGNED-SHORT|SIZE|SORT-MERGE|SOURCE|' |
|
3333 r'SOURCE-COMPUTER|SPECIAL-NAMES|STANDARD|' |
|
3334 r'STANDARD-1|STANDARD-2|STATUS|SUM|' |
|
3335 r'SYMBOLIC|SYNC|SYNCHRONIZED|TALLYING|TAPE|' |
|
3336 r'TEST|THROUGH|THRU|TIME|TIMES|TO|TOP|TRAILING|' |
|
3337 r'TRANSFORM|TYPE|UNDERLINE|UNIT|UNSIGNED|' |
|
3338 r'UNSIGNED-INT|UNSIGNED-LONG|UNSIGNED-SHORT|UNTIL|UP|' |
|
3339 r'UPDATE|UPON|USAGE|USING|VALUE|VALUES|VARYING|WAIT|WHEN|' |
|
3340 r'WITH|WORDS|YYYYDDD|YYYYMMDD)' |
|
3341 r'\s*($|(?=[^0-9a-z_\-]))', Keyword.Pseudo), |
|
3342 |
|
3343 # inactive reserved words |
|
3344 (r'(^|(?<=[^0-9a-z_\-]))' |
|
3345 r'(ACTIVE-CLASS|ALIGNED|ANYCASE|ARITHMETIC|ATTRIBUTE|B-AND|' |
|
3346 r'B-NOT|B-OR|B-XOR|BIT|BOOLEAN|CD|CENTER|CF|CH|CHAIN|CLASS-ID|' |
|
3347 r'CLASSIFICATION|COMMUNICATION|CONDITION|DATA-POINTER|' |
|
3348 r'DESTINATION|DISABLE|EC|EGI|EMI|ENABLE|END-RECEIVE|' |
|
3349 r'ENTRY-CONVENTION|EO|ESI|EXCEPTION-OBJECT|EXPANDS|FACTORY|' |
|
3350 r'FLOAT-BINARY-16|FLOAT-BINARY-34|FLOAT-BINARY-7|' |
|
3351 r'FLOAT-DECIMAL-16|FLOAT-DECIMAL-34|FLOAT-EXTENDED|FORMAT|' |
|
3352 r'FUNCTION-POINTER|GET|GROUP-USAGE|IMPLEMENTS|INFINITY|' |
|
3353 r'INHERITS|INTERFACE|INTERFACE-ID|INVOKE|LC_ALL|LC_COLLATE|' |
|
3354 r'LC_CTYPE|LC_MESSAGES|LC_MONETARY|LC_NUMERIC|LC_TIME|' |
|
3355 r'LINE-COUNTER|MESSAGE|METHOD|METHOD-ID|NESTED|NONE|NORMAL|' |
|
3356 r'OBJECT|OBJECT-REFERENCE|OPTIONS|OVERRIDE|PAGE-COUNTER|PF|PH|' |
|
3357 r'PROPERTY|PROTOTYPE|PURGE|QUEUE|RAISE|RAISING|RECEIVE|' |
|
3358 r'RELATION|REPLACE|REPRESENTS-NOT-A-NUMBER|RESET|RESUME|RETRY|' |
|
3359 r'RF|RH|SECONDS|SEGMENT|SELF|SEND|SOURCES|STATEMENT|STEP|' |
|
3360 r'STRONG|SUB-QUEUE-1|SUB-QUEUE-2|SUB-QUEUE-3|SUPER|SYMBOL|' |
|
3361 r'SYSTEM-DEFAULT|TABLE|TERMINAL|TEXT|TYPEDEF|UCS-4|UNIVERSAL|' |
|
3362 r'USER-DEFAULT|UTF-16|UTF-8|VAL-STATUS|VALID|VALIDATE|' |
|
3363 r'VALIDATE-STATUS)\s*($|(?=[^0-9a-z_\-]))', Error), |
|
3364 |
|
3365 # Data Types |
|
3366 (r'(^|(?<=[^0-9a-z_\-]))' |
|
3367 r'(PIC\s+.+?(?=(\s|\.\s))|PICTURE\s+.+?(?=(\s|\.\s))|' |
|
3368 r'(COMPUTATIONAL)(-[1-5X])?|(COMP)(-[1-5X])?|' |
|
3369 r'BINARY-C-LONG|' |
|
3370 r'BINARY-CHAR|BINARY-DOUBLE|BINARY-LONG|BINARY-SHORT|' |
|
3371 r'BINARY)\s*($|(?=[^0-9a-z_\-]))', Keyword.Type), |
|
3372 |
|
3373 # Operators |
|
3374 (r'(\*\*|\*|\+|-|/|<=|>=|<|>|==|/=|=)', Operator), |
|
3375 |
|
3376 # (r'(::)', Keyword.Declaration), |
|
3377 |
|
3378 (r'([(),;:&%.])', Punctuation), |
|
3379 |
|
3380 # Intrinsics |
|
3381 (r'(^|(?<=[^0-9a-z_\-]))(ABS|ACOS|ANNUITY|ASIN|ATAN|BYTE-LENGTH|' |
|
3382 r'CHAR|COMBINED-DATETIME|CONCATENATE|COS|CURRENT-DATE|' |
|
3383 r'DATE-OF-INTEGER|DATE-TO-YYYYMMDD|DAY-OF-INTEGER|DAY-TO-YYYYDDD|' |
|
3384 r'EXCEPTION-(?:FILE|LOCATION|STATEMENT|STATUS)|EXP10|EXP|E|' |
|
3385 r'FACTORIAL|FRACTION-PART|INTEGER-OF-(?:DATE|DAY|PART)|INTEGER|' |
|
3386 r'LENGTH|LOCALE-(?:DATE|TIME(?:-FROM-SECONDS)?)|LOG10|LOG|' |
|
3387 r'LOWER-CASE|MAX|MEAN|MEDIAN|MIDRANGE|MIN|MOD|NUMVAL(?:-C)?|' |
|
3388 r'ORD(?:-MAX|-MIN)?|PI|PRESENT-VALUE|RANDOM|RANGE|REM|REVERSE|' |
|
3389 r'SECONDS-FROM-FORMATTED-TIME|SECONDS-PAST-MIDNIGHT|SIGN|SIN|SQRT|' |
|
3390 r'STANDARD-DEVIATION|STORED-CHAR-LENGTH|SUBSTITUTE(?:-CASE)?|' |
|
3391 r'SUM|TAN|TEST-DATE-YYYYMMDD|TEST-DAY-YYYYDDD|TRIM|' |
|
3392 r'UPPER-CASE|VARIANCE|WHEN-COMPILED|YEAR-TO-YYYY)\s*' |
|
3393 r'($|(?=[^0-9a-z_\-]))', Name.Function), |
|
3394 |
|
3395 # Booleans |
|
3396 (r'(^|(?<=[^0-9a-z_\-]))(true|false)\s*($|(?=[^0-9a-z_\-]))', Name.Builtin), |
|
3397 # Comparing Operators |
|
3398 (r'(^|(?<=[^0-9a-z_\-]))(equal|equals|ne|lt|le|gt|ge|' |
|
3399 r'greater|less|than|not|and|or)\s*($|(?=[^0-9a-z_\-]))', Operator.Word), |
|
3400 ], |
|
3401 |
|
3402 # \"[^\"\n]*\"|\'[^\'\n]*\' |
|
3403 'strings': [ |
|
3404 # apparently strings can be delimited by EOL if they are continued |
|
3405 # in the next line |
|
3406 (r'"[^"\n]*("|\n)', String.Double), |
|
3407 (r"'[^'\n]*('|\n)", String.Single), |
|
3408 ], |
|
3409 |
|
3410 'nums': [ |
|
3411 (r'\d+(\s*|\.$|$)', Number.Integer), |
|
3412 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float), |
|
3413 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float), |
|
3414 ], |
|
3415 } |
|
3416 |
|
3417 |
|
3418 class CobolFreeformatLexer(CobolLexer): |
|
3419 """ |
|
3420 Lexer for Free format OpenCOBOL code. |
|
3421 |
|
3422 *New in Pygments 1.6.* |
|
3423 """ |
|
3424 name = 'COBOLFree' |
|
3425 aliases = ['cobolfree'] |
|
3426 filenames = ['*.cbl', '*.CBL'] |
|
3427 mimetypes = [] |
|
3428 flags = re.IGNORECASE | re.MULTILINE |
|
3429 |
|
3430 tokens = { |
|
3431 'comment': [ |
|
3432 (r'(\*>.*\n|^\w*\*.*$)', Comment), |
|
3433 ], |
|
3434 } |
|
3435 |
|
3436 |
|
3437 class LogosLexer(ObjectiveCppLexer): |
|
3438 """ |
|
3439 For Logos + Objective-C source code with preprocessor directives. |
|
3440 |
|
3441 *New in Pygments 1.6.* |
|
3442 """ |
|
3443 |
|
3444 name = 'Logos' |
|
3445 aliases = ['logos'] |
|
3446 filenames = ['*.x', '*.xi', '*.xm', '*.xmi'] |
|
3447 mimetypes = ['text/x-logos'] |
|
3448 priority = 0.25 |
|
3449 |
|
3450 tokens = { |
|
3451 'statements': [ |
|
3452 (r'(%orig|%log)\b', Keyword), |
|
3453 (r'(%c)\b(\()(\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\))', |
|
3454 bygroups(Keyword, Punctuation, Text, Name.Class, Text, Punctuation)), |
|
3455 (r'(%init)\b(\()', |
|
3456 bygroups(Keyword, Punctuation), 'logos_init_directive'), |
|
3457 (r'(%init)(?=\s*;)', bygroups(Keyword)), |
|
3458 (r'(%hook|%group)(\s+)([a-zA-Z$_][a-zA-Z0-9$_]+)', |
|
3459 bygroups(Keyword, Text, Name.Class), '#pop'), |
|
3460 (r'(%subclass)(\s+)', bygroups(Keyword, Text), |
|
3461 ('#pop', 'logos_classname')), |
|
3462 inherit, |
|
3463 ], |
|
3464 'logos_init_directive' : [ |
|
3465 ('\s+', Text), |
|
3466 (',', Punctuation, ('logos_init_directive', '#pop')), |
|
3467 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(=)(\s*)([^);]*)', |
|
3468 bygroups(Name.Class, Text, Punctuation, Text, Text)), |
|
3469 ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class), |
|
3470 ('\)', Punctuation, '#pop'), |
|
3471 ], |
|
3472 'logos_classname' : [ |
|
3473 ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?', |
|
3474 bygroups(Name.Class, Text, Name.Class), '#pop'), |
|
3475 ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop') |
|
3476 ], |
|
3477 'root': [ |
|
3478 (r'(%subclass)(\s+)', bygroups(Keyword, Text), |
|
3479 'logos_classname'), |
|
3480 (r'(%hook|%group)(\s+)([a-zA-Z$_][a-zA-Z0-9$_]+)', |
|
3481 bygroups(Keyword, Text, Name.Class)), |
|
3482 (r'(%config)(\s*\(\s*)(\w+)(\s*=\s*)(.*?)(\s*\)\s*)', |
|
3483 bygroups(Keyword, Text, Name.Variable, Text, String, Text)), |
|
3484 (r'(%ctor)(\s*)({)', bygroups(Keyword, Text, Punctuation), |
|
3485 'function'), |
|
3486 (r'(%new)(\s*)(\()(\s*.*?\s*)(\))', |
|
3487 bygroups(Keyword, Text, Keyword, String, Keyword)), |
|
3488 (r'(\s*)(%end)(\s*)', bygroups(Text, Keyword, Text)), |
|
3489 inherit, |
|
3490 ], |
|
3491 } |
|
3492 |
|
3493 _logos_keywords = re.compile(r'%(?:hook|ctor|init|c\()') |
|
3494 |
|
3495 def analyse_text(text): |
|
3496 if LogosLexer._logos_keywords.search(text): |
|
3497 return 1.0 |
|
3498 return 0 |
|