pygmentize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/LICENSE +19 -0
  2. data/lib/pygments.rb +23 -0
  3. data/pygmentize.gemspec +11 -0
  4. data/test/pygments.rb +19 -0
  5. data/vendor/pygmentize.py +7 -0
  6. data/vendor/pygments/AUTHORS +73 -0
  7. data/vendor/pygments/LICENSE +25 -0
  8. data/vendor/pygments/__init__.py +91 -0
  9. data/vendor/pygments/__init__.pyc +0 -0
  10. data/vendor/pygments/cmdline.py +430 -0
  11. data/vendor/pygments/cmdline.pyc +0 -0
  12. data/vendor/pygments/console.py +74 -0
  13. data/vendor/pygments/console.pyc +0 -0
  14. data/vendor/pygments/filter.py +74 -0
  15. data/vendor/pygments/filter.pyc +0 -0
  16. data/vendor/pygments/filters/__init__.py +357 -0
  17. data/vendor/pygments/filters/__init__.pyc +0 -0
  18. data/vendor/pygments/formatter.py +92 -0
  19. data/vendor/pygments/formatter.pyc +0 -0
  20. data/vendor/pygments/formatters/__init__.py +68 -0
  21. data/vendor/pygments/formatters/__init__.pyc +0 -0
  22. data/vendor/pygments/formatters/_mapping.py +92 -0
  23. data/vendor/pygments/formatters/_mapping.pyc +0 -0
  24. data/vendor/pygments/formatters/bbcode.py +109 -0
  25. data/vendor/pygments/formatters/bbcode.pyc +0 -0
  26. data/vendor/pygments/formatters/html.py +723 -0
  27. data/vendor/pygments/formatters/html.pyc +0 -0
  28. data/vendor/pygments/formatters/img.py +553 -0
  29. data/vendor/pygments/formatters/img.pyc +0 -0
  30. data/vendor/pygments/formatters/latex.py +354 -0
  31. data/vendor/pygments/formatters/latex.pyc +0 -0
  32. data/vendor/pygments/formatters/other.py +117 -0
  33. data/vendor/pygments/formatters/other.pyc +0 -0
  34. data/vendor/pygments/formatters/rtf.py +136 -0
  35. data/vendor/pygments/formatters/rtf.pyc +0 -0
  36. data/vendor/pygments/formatters/svg.py +154 -0
  37. data/vendor/pygments/formatters/svg.pyc +0 -0
  38. data/vendor/pygments/formatters/terminal.py +109 -0
  39. data/vendor/pygments/formatters/terminal.pyc +0 -0
  40. data/vendor/pygments/formatters/terminal256.py +219 -0
  41. data/vendor/pygments/formatters/terminal256.pyc +0 -0
  42. data/vendor/pygments/lexer.py +660 -0
  43. data/vendor/pygments/lexer.pyc +0 -0
  44. data/vendor/pygments/lexers/__init__.py +226 -0
  45. data/vendor/pygments/lexers/__init__.pyc +0 -0
  46. data/vendor/pygments/lexers/_asybuiltins.py +1645 -0
  47. data/vendor/pygments/lexers/_clbuiltins.py +232 -0
  48. data/vendor/pygments/lexers/_luabuiltins.py +256 -0
  49. data/vendor/pygments/lexers/_mapping.py +234 -0
  50. data/vendor/pygments/lexers/_mapping.pyc +0 -0
  51. data/vendor/pygments/lexers/_phpbuiltins.py +3389 -0
  52. data/vendor/pygments/lexers/_vimbuiltins.py +3 -0
  53. data/vendor/pygments/lexers/agile.py +1485 -0
  54. data/vendor/pygments/lexers/agile.pyc +0 -0
  55. data/vendor/pygments/lexers/asm.py +353 -0
  56. data/vendor/pygments/lexers/compiled.py +2365 -0
  57. data/vendor/pygments/lexers/dotnet.py +355 -0
  58. data/vendor/pygments/lexers/functional.py +756 -0
  59. data/vendor/pygments/lexers/functional.pyc +0 -0
  60. data/vendor/pygments/lexers/math.py +461 -0
  61. data/vendor/pygments/lexers/other.py +2297 -0
  62. data/vendor/pygments/lexers/parsers.py +695 -0
  63. data/vendor/pygments/lexers/special.py +100 -0
  64. data/vendor/pygments/lexers/special.pyc +0 -0
  65. data/vendor/pygments/lexers/templates.py +1387 -0
  66. data/vendor/pygments/lexers/text.py +1586 -0
  67. data/vendor/pygments/lexers/web.py +1619 -0
  68. data/vendor/pygments/lexers/web.pyc +0 -0
  69. data/vendor/pygments/plugin.py +74 -0
  70. data/vendor/pygments/plugin.pyc +0 -0
  71. data/vendor/pygments/scanner.py +104 -0
  72. data/vendor/pygments/style.py +117 -0
  73. data/vendor/pygments/style.pyc +0 -0
  74. data/vendor/pygments/styles/__init__.py +68 -0
  75. data/vendor/pygments/styles/__init__.pyc +0 -0
  76. data/vendor/pygments/styles/autumn.py +65 -0
  77. data/vendor/pygments/styles/borland.py +51 -0
  78. data/vendor/pygments/styles/bw.py +49 -0
  79. data/vendor/pygments/styles/colorful.py +81 -0
  80. data/vendor/pygments/styles/default.py +73 -0
  81. data/vendor/pygments/styles/default.pyc +0 -0
  82. data/vendor/pygments/styles/emacs.py +72 -0
  83. data/vendor/pygments/styles/friendly.py +72 -0
  84. data/vendor/pygments/styles/fruity.py +43 -0
  85. data/vendor/pygments/styles/manni.py +75 -0
  86. data/vendor/pygments/styles/monokai.py +106 -0
  87. data/vendor/pygments/styles/murphy.py +80 -0
  88. data/vendor/pygments/styles/native.py +65 -0
  89. data/vendor/pygments/styles/pastie.py +75 -0
  90. data/vendor/pygments/styles/perldoc.py +69 -0
  91. data/vendor/pygments/styles/tango.py +141 -0
  92. data/vendor/pygments/styles/trac.py +63 -0
  93. data/vendor/pygments/styles/vim.py +63 -0
  94. data/vendor/pygments/styles/vs.py +38 -0
  95. data/vendor/pygments/token.py +198 -0
  96. data/vendor/pygments/token.pyc +0 -0
  97. data/vendor/pygments/unistring.py +130 -0
  98. data/vendor/pygments/unistring.pyc +0 -0
  99. data/vendor/pygments/util.py +226 -0
  100. data/vendor/pygments/util.pyc +0 -0
  101. metadata +166 -0
@@ -0,0 +1,353 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.lexers.asm
4
+ ~~~~~~~~~~~~~~~~~~~
5
+
6
+ Lexers for assembly languages.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import re
13
+
14
+ from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer
15
+ from pygments.lexers.compiled import DLexer, CppLexer, CLexer
16
+ from pygments.token import *
17
+
18
+ __all__ = ['GasLexer', 'ObjdumpLexer','DObjdumpLexer', 'CppObjdumpLexer',
19
+ 'CObjdumpLexer', 'LlvmLexer', 'NasmLexer']
20
+
21
+
22
+ class GasLexer(RegexLexer):
23
+ """
24
+ For Gas (AT&T) assembly code.
25
+ """
26
+ name = 'GAS'
27
+ aliases = ['gas']
28
+ filenames = ['*.s', '*.S']
29
+ mimetypes = ['text/x-gas']
30
+
31
+ #: optional Comment or Whitespace
32
+ string = r'"(\\"|[^"])*"'
33
+ char = r'[a-zA-Z$._0-9@]'
34
+ identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)'
35
+ number = r'(?:0[xX][a-zA-Z0-9]+|\d+)'
36
+
37
+ tokens = {
38
+ 'root': [
39
+ include('whitespace'),
40
+ (identifier + ':', Name.Label),
41
+ (r'\.' + identifier, Name.Attribute, 'directive-args'),
42
+ (r'lock|rep(n?z)?|data\d+', Name.Attribute),
43
+ (identifier, Name.Function, 'instruction-args'),
44
+ (r'[\r\n]+', Text)
45
+ ],
46
+ 'directive-args': [
47
+ (identifier, Name.Constant),
48
+ (string, String),
49
+ ('@' + identifier, Name.Attribute),
50
+ (number, Number.Integer),
51
+ (r'[\r\n]+', Text, '#pop'),
52
+
53
+ (r'#.*?$', Comment, '#pop'),
54
+
55
+ include('punctuation'),
56
+ include('whitespace')
57
+ ],
58
+ 'instruction-args': [
59
+ # For objdump-disassembled code, shouldn't occur in
60
+ # actual assembler input
61
+ ('([a-z0-9]+)( )(<)('+identifier+')(>)',
62
+ bygroups(Number.Hex, Text, Punctuation, Name.Constant,
63
+ Punctuation)),
64
+ ('([a-z0-9]+)( )(<)('+identifier+')([-+])('+number+')(>)',
65
+ bygroups(Number.Hex, Text, Punctuation, Name.Constant,
66
+ Punctuation, Number.Integer, Punctuation)),
67
+
68
+ # Address constants
69
+ (identifier, Name.Constant),
70
+ (number, Number.Integer),
71
+ # Registers
72
+ ('%' + identifier, Name.Variable),
73
+ # Numeric constants
74
+ ('$'+number, Number.Integer),
75
+ (r'[\r\n]+', Text, '#pop'),
76
+ (r'#.*?$', Comment, '#pop'),
77
+ include('punctuation'),
78
+ include('whitespace')
79
+ ],
80
+ 'whitespace': [
81
+ (r'\n', Text),
82
+ (r'\s+', Text),
83
+ (r'#.*?\n', Comment)
84
+ ],
85
+ 'punctuation': [
86
+ (r'[-*,.():]+', Punctuation)
87
+ ]
88
+ }
89
+
90
+ def analyse_text(text):
91
+ return re.match(r'^\.\w+', text, re.M)
92
+
93
+ class ObjdumpLexer(RegexLexer):
94
+ """
95
+ For the output of 'objdump -dr'
96
+ """
97
+ name = 'objdump'
98
+ aliases = ['objdump']
99
+ filenames = ['*.objdump']
100
+ mimetypes = ['text/x-objdump']
101
+
102
+ hex = r'[0-9A-Za-z]'
103
+
104
+ tokens = {
105
+ 'root': [
106
+ # File name & format:
107
+ ('(.*?)(:)( +file format )(.*?)$',
108
+ bygroups(Name.Label, Punctuation, Text, String)),
109
+ # Section header
110
+ ('(Disassembly of section )(.*?)(:)$',
111
+ bygroups(Text, Name.Label, Punctuation)),
112
+ # Function labels
113
+ # (With offset)
114
+ ('('+hex+'+)( )(<)(.*?)([-+])(0[xX][A-Za-z0-9]+)(>:)$',
115
+ bygroups(Number.Hex, Text, Punctuation, Name.Function,
116
+ Punctuation, Number.Hex, Punctuation)),
117
+ # (Without offset)
118
+ ('('+hex+'+)( )(<)(.*?)(>:)$',
119
+ bygroups(Number.Hex, Text, Punctuation, Name.Function,
120
+ Punctuation)),
121
+ # Code line with disassembled instructions
122
+ ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)( *\t)([a-zA-Z].*?)$',
123
+ bygroups(Text, Name.Label, Text, Number.Hex, Text,
124
+ using(GasLexer))),
125
+ # Code line with ascii
126
+ ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)( *)(.*?)$',
127
+ bygroups(Text, Name.Label, Text, Number.Hex, Text, String)),
128
+ # Continued code line, only raw opcodes without disassembled
129
+ # instruction
130
+ ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)$',
131
+ bygroups(Text, Name.Label, Text, Number.Hex)),
132
+ # Skipped a few bytes
133
+ ('\t\.\.\.$', Text),
134
+ # Relocation line
135
+ # (With offset)
136
+ ('(\t\t\t)('+hex+'+:)( )([^\t]+)(\t)(.*?)([-+])(0x' + hex + '+)$',
137
+ bygroups(Text, Name.Label, Text, Name.Property, Text,
138
+ Name.Constant, Punctuation, Number.Hex)),
139
+ # (Without offset)
140
+ ('(\t\t\t)('+hex+'+:)( )([^\t]+)(\t)(.*?)$',
141
+ bygroups(Text, Name.Label, Text, Name.Property, Text,
142
+ Name.Constant)),
143
+ ('[^\n]+\n', Other)
144
+ ]
145
+ }
146
+
147
+
148
+ class DObjdumpLexer(DelegatingLexer):
149
+ """
150
+ For the output of 'objdump -Sr on compiled D files'
151
+ """
152
+ name = 'd-objdump'
153
+ aliases = ['d-objdump']
154
+ filenames = ['*.d-objdump']
155
+ mimetypes = ['text/x-d-objdump']
156
+
157
+ def __init__(self, **options):
158
+ super(DObjdumpLexer, self).__init__(DLexer, ObjdumpLexer, **options)
159
+
160
+
161
+ class CppObjdumpLexer(DelegatingLexer):
162
+ """
163
+ For the output of 'objdump -Sr on compiled C++ files'
164
+ """
165
+ name = 'cpp-objdump'
166
+ aliases = ['cpp-objdump', 'c++-objdumb', 'cxx-objdump']
167
+ filenames = ['*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump']
168
+ mimetypes = ['text/x-cpp-objdump']
169
+
170
+ def __init__(self, **options):
171
+ super(CppObjdumpLexer, self).__init__(CppLexer, ObjdumpLexer, **options)
172
+
173
+
174
+ class CObjdumpLexer(DelegatingLexer):
175
+ """
176
+ For the output of 'objdump -Sr on compiled C files'
177
+ """
178
+ name = 'c-objdump'
179
+ aliases = ['c-objdump']
180
+ filenames = ['*.c-objdump']
181
+ mimetypes = ['text/x-c-objdump']
182
+
183
+ def __init__(self, **options):
184
+ super(CObjdumpLexer, self).__init__(CLexer, ObjdumpLexer, **options)
185
+
186
+
187
+ class LlvmLexer(RegexLexer):
188
+ """
189
+ For LLVM assembly code.
190
+ """
191
+ name = 'LLVM'
192
+ aliases = ['llvm']
193
+ filenames = ['*.ll']
194
+ mimetypes = ['text/x-llvm']
195
+
196
+ #: optional Comment or Whitespace
197
+ string = r'"[^"]*?"'
198
+ identifier = r'([-a-zA-Z$._][-a-zA-Z$._0-9]*|' + string + ')'
199
+
200
+ tokens = {
201
+ 'root': [
202
+ include('whitespace'),
203
+
204
+ # Before keywords, because keywords are valid label names :(...
205
+ (r'^\s*' + identifier + '\s*:', Name.Label),
206
+
207
+ include('keyword'),
208
+
209
+ (r'%' + identifier, Name.Variable),#Name.Identifier.Local),
210
+ (r'@' + identifier, Name.Variable.Global),#Name.Identifier.Global),
211
+ (r'%\d+', Name.Variable.Anonymous),#Name.Identifier.Anonymous),
212
+ (r'@\d+', Name.Variable.Global),#Name.Identifier.Anonymous),
213
+ (r'!' + identifier, Name.Variable),
214
+ (r'!\d+', Name.Variable.Anonymous),
215
+ (r'c?' + string, String),
216
+
217
+ (r'0[xX][a-fA-F0-9]+', Number),
218
+ (r'-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?', Number),
219
+
220
+ (r'[=<>{}\[\]()*.,!]|x\b', Punctuation)
221
+ ],
222
+ 'whitespace': [
223
+ (r'(\n|\s)+', Text),
224
+ (r';.*?\n', Comment)
225
+ ],
226
+ 'keyword': [
227
+ # Regular keywords
228
+ (r'(begin|end'
229
+ r'|true|false'
230
+ r'|declare|define'
231
+ r'|global|constant'
232
+
233
+ r'|private|linker_private|internal|available_externally|linkonce'
234
+ r'|linkonce_odr|weak|weak_odr|appending|dllimport|dllexport'
235
+ r'|common|default|hidden|protected|extern_weak|external'
236
+ r'|thread_local|zeroinitializer|undef|null|to|tail|target|triple'
237
+ r'|deplibs|datalayout|volatile|nuw|nsw|exact|inbounds|align'
238
+ r'|addrspace|section|alias|module|asm|sideeffect|gc|dbg'
239
+
240
+ r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc'
241
+ r'|arm_aapcscc|arm_aapcs_vfpcc'
242
+
243
+ r'|cc|c'
244
+
245
+ r'|signext|zeroext|inreg|sret|nounwind|noreturn|noalias|nocapture'
246
+ r'|byval|nest|readnone|readonly'
247
+
248
+ r'|inlinehint|noinline|alwaysinline|optsize|ssp|sspreq|noredzone'
249
+ r'|noimplicitfloat|naked'
250
+
251
+ r'|type|opaque'
252
+
253
+ r'|eq|ne|slt|sgt|sle'
254
+ r'|sge|ult|ugt|ule|uge'
255
+ r'|oeq|one|olt|ogt|ole'
256
+ r'|oge|ord|uno|ueq|une'
257
+ r'|x'
258
+
259
+ # instructions
260
+ r'|add|fadd|sub|fsub|mul|fmul|udiv|sdiv|fdiv|urem|srem|frem|shl'
261
+ r'|lshr|ashr|and|or|xor|icmp|fcmp'
262
+
263
+ r'|phi|call|trunc|zext|sext|fptrunc|fpext|uitofp|sitofp|fptoui'
264
+ r'fptosi|inttoptr|ptrtoint|bitcast|select|va_arg|ret|br|switch'
265
+ r'|invoke|unwind|unreachable'
266
+
267
+ r'|malloc|alloca|free|load|store|getelementptr'
268
+
269
+ r'|extractelement|insertelement|shufflevector|getresult'
270
+ r'|extractvalue|insertvalue'
271
+
272
+ r')\b', Keyword),
273
+
274
+ # Types
275
+ (r'void|float|double|x86_fp80|fp128|ppc_fp128|label|metadata',
276
+ Keyword.Type),
277
+
278
+ # Integer types
279
+ (r'i[1-9]\d*', Keyword)
280
+ ]
281
+ }
282
+
283
+
284
+ class NasmLexer(RegexLexer):
285
+ """
286
+ For Nasm (Intel) assembly code.
287
+ """
288
+ name = 'NASM'
289
+ aliases = ['nasm']
290
+ filenames = ['*.asm', '*.ASM']
291
+ mimetypes = ['text/x-nasm']
292
+
293
+ identifier = r'[a-zA-Z$._?][a-zA-Z0-9$._?#@~]*'
294
+ hexn = r'(?:0[xX][0-9a-fA-F]+|$0[0-9a-fA-F]*|[0-9]+[0-9a-fA-F]*h)'
295
+ octn = r'[0-7]+q'
296
+ binn = r'[01]+b'
297
+ decn = r'[0-9]+'
298
+ floatn = decn + r'\.e?' + decn
299
+ string = r'"(\\"|[^"])*"|' + r"'(\\'|[^'])*'"
300
+ declkw = r'(?:res|d)[bwdqt]|times'
301
+ register = (r'[a-d][lh]|e?[a-d]x|e?[sb]p|e?[sd]i|[c-gs]s|st[0-7]|'
302
+ r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
303
+ wordop = r'seg|wrt|strict'
304
+ type = r'byte|[dq]?word'
305
+ directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|'
306
+ r'ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|'
307
+ r'EXPORT|LIBRARY|MODULE')
308
+
309
+ flags = re.IGNORECASE | re.MULTILINE
310
+ tokens = {
311
+ 'root': [
312
+ include('whitespace'),
313
+ (r'^\s*%', Comment.Preproc, 'preproc'),
314
+ (identifier + ':', Name.Label),
315
+ (r'(%s)(\s+)(equ)' % identifier,
316
+ bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
317
+ 'instruction-args'),
318
+ (directives, Keyword, 'instruction-args'),
319
+ (declkw, Keyword.Declaration, 'instruction-args'),
320
+ (identifier, Name.Function, 'instruction-args'),
321
+ (r'[\r\n]+', Text)
322
+ ],
323
+ 'instruction-args': [
324
+ (string, String),
325
+ (hexn, Number.Hex),
326
+ (octn, Number.Oct),
327
+ (binn, Number),
328
+ (floatn, Number.Float),
329
+ (decn, Number.Integer),
330
+ include('punctuation'),
331
+ (register, Name.Builtin),
332
+ (identifier, Name.Variable),
333
+ (r'[\r\n]+', Text, '#pop'),
334
+ include('whitespace')
335
+ ],
336
+ 'preproc': [
337
+ (r'[^;\n]+', Comment.Preproc),
338
+ (r';.*?\n', Comment.Single, '#pop'),
339
+ (r'\n', Comment.Preproc, '#pop'),
340
+ ],
341
+ 'whitespace': [
342
+ (r'\n', Text),
343
+ (r'[ \t]+', Text),
344
+ (r';.*', Comment.Single)
345
+ ],
346
+ 'punctuation': [
347
+ (r'[,():\[\]]+', Punctuation),
348
+ (r'[&|^<>+*/%~-]+', Operator),
349
+ (r'[$]+', Keyword.Constant),
350
+ (wordop, Operator.Word),
351
+ (type, Keyword.Type)
352
+ ],
353
+ }
@@ -0,0 +1,2365 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.lexers.compiled
4
+ ~~~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ Lexers for compiled languages.
7
+
8
+ :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import re
13
+
14
+ from pygments.scanner import Scanner
15
+ from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
16
+ this, combined
17
+ from pygments.util import get_bool_opt, get_list_opt
18
+ from pygments.token import \
19
+ Text, Comment, Operator, Keyword, Name, String, Number, Punctuation, \
20
+ Error
21
+
22
+ # backwards compatibility
23
+ from pygments.lexers.functional import OcamlLexer
24
+
25
+ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'JavaLexer',
26
+ 'ScalaLexer', 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer',
27
+ 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer',
28
+ 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer',
29
+ 'Modula2Lexer']
30
+
31
+
32
+ class CLexer(RegexLexer):
33
+ """
34
+ For C source code with preprocessor directives.
35
+ """
36
+ name = 'C'
37
+ aliases = ['c']
38
+ filenames = ['*.c', '*.h']
39
+ mimetypes = ['text/x-chdr', 'text/x-csrc']
40
+
41
+ #: optional Comment or Whitespace
42
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
43
+
44
+ tokens = {
45
+ 'whitespace': [
46
+ (r'^\s*#if\s+0', Comment.Preproc, 'if0'),
47
+ (r'^\s*#', Comment.Preproc, 'macro'),
48
+ (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', bygroups(Text, Name.Label)),
49
+ (r'\n', Text),
50
+ (r'\s+', Text),
51
+ (r'\\\n', Text), # line continuation
52
+ (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
53
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
54
+ ],
55
+ 'statements': [
56
+ (r'L?"', String, 'string'),
57
+ (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
58
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
59
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
60
+ (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
61
+ (r'0[0-7]+[Ll]?', Number.Oct),
62
+ (r'\d+[Ll]?', Number.Integer),
63
+ (r'\*/', Error),
64
+ (r'[~!%^&*+=|?:<>/-]', Operator),
65
+ (r'[()\[\],.]', Punctuation),
66
+ (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
67
+ (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
68
+ r'for|goto|if|register|restricted|return|sizeof|static|struct|'
69
+ r'switch|typedef|union|volatile|virtual|while)\b', Keyword),
70
+ (r'(int|long|float|short|double|char|unsigned|signed|void)\b',
71
+ Keyword.Type),
72
+ (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved),
73
+ (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
74
+ r'declspec|finally|int64|try|leave)\b', Keyword.Reserved),
75
+ (r'(true|false|NULL)\b', Name.Builtin),
76
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
77
+ ],
78
+ 'root': [
79
+ include('whitespace'),
80
+ # functions
81
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
82
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
83
+ r'(\s*\([^;]*?\))' # signature
84
+ r'(' + _ws + r')({)',
85
+ bygroups(using(this), Name.Function, using(this), using(this),
86
+ Punctuation),
87
+ 'function'),
88
+ # function declarations
89
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
90
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
91
+ r'(\s*\([^;]*?\))' # signature
92
+ r'(' + _ws + r')(;)',
93
+ bygroups(using(this), Name.Function, using(this), using(this),
94
+ Punctuation)),
95
+ ('', Text, 'statement'),
96
+ ],
97
+ 'statement' : [
98
+ include('whitespace'),
99
+ include('statements'),
100
+ ('[{}]', Punctuation),
101
+ (';', Punctuation, '#pop'),
102
+ ],
103
+ 'function': [
104
+ include('whitespace'),
105
+ include('statements'),
106
+ (';', Punctuation),
107
+ ('{', Punctuation, '#push'),
108
+ ('}', Punctuation, '#pop'),
109
+ ],
110
+ 'string': [
111
+ (r'"', String, '#pop'),
112
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
113
+ (r'[^\\"\n]+', String), # all other characters
114
+ (r'\\\n', String), # line continuation
115
+ (r'\\', String), # stray backslash
116
+ ],
117
+ 'macro': [
118
+ (r'[^/\n]+', Comment.Preproc),
119
+ (r'/[*](.|\n)*?[*]/', Comment.Multiline),
120
+ (r'//.*?\n', Comment.Single, '#pop'),
121
+ (r'/', Comment.Preproc),
122
+ (r'(?<=\\)\n', Comment.Preproc),
123
+ (r'\n', Comment.Preproc, '#pop'),
124
+ ],
125
+ 'if0': [
126
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
127
+ (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
128
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
129
+ (r'.*?\n', Comment),
130
+ ]
131
+ }
132
+
133
+ stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t',
134
+ 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list',
135
+ 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t',
136
+ 'wctrans_t', 'wint_t', 'wctype_t']
137
+ c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
138
+ 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t',
139
+ 'int_least16_t', 'int_least32_t', 'int_least64_t',
140
+ 'uint_least8_t', 'uint_least16_t', 'uint_least32_t',
141
+ 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t',
142
+ 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t',
143
+ 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t', 'uintmax_t']
144
+
145
+ def __init__(self, **options):
146
+ self.stdlibhighlighting = get_bool_opt(options,
147
+ 'stdlibhighlighting', True)
148
+ self.c99highlighting = get_bool_opt(options,
149
+ 'c99highlighting', True)
150
+ RegexLexer.__init__(self, **options)
151
+
152
+ def get_tokens_unprocessed(self, text):
153
+ for index, token, value in \
154
+ RegexLexer.get_tokens_unprocessed(self, text):
155
+ if token is Name:
156
+ if self.stdlibhighlighting and value in self.stdlib_types:
157
+ token = Keyword.Type
158
+ elif self.c99highlighting and value in self.c99_types:
159
+ token = Keyword.Type
160
+ yield index, token, value
161
+
162
+ class CppLexer(RegexLexer):
163
+ """
164
+ For C++ source code with preprocessor directives.
165
+ """
166
+ name = 'C++'
167
+ aliases = ['cpp', 'c++']
168
+ filenames = ['*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx']
169
+ mimetypes = ['text/x-c++hdr', 'text/x-c++src']
170
+
171
+ tokens = {
172
+ 'root': [
173
+ (r'^\s*#if\s+0', Comment.Preproc, 'if0'),
174
+ (r'^\s*#', Comment.Preproc, 'macro'),
175
+ (r'\n', Text),
176
+ (r'\s+', Text),
177
+ (r'\\\n', Text), # line continuation
178
+ (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
179
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
180
+ (r'[{}]', Punctuation),
181
+ (r'L?"', String, 'string'),
182
+ (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
183
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
184
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
185
+ (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
186
+ (r'0[0-7]+[Ll]?', Number.Oct),
187
+ (r'\d+[Ll]?', Number.Integer),
188
+ (r'\*/', Error),
189
+ (r'[~!%^&*+=|?:<>/-]', Operator),
190
+ (r'[()\[\],.;]', Punctuation),
191
+ (r'(asm|auto|break|case|catch|const|const_cast|continue|'
192
+ r'default|delete|do|dynamic_cast|else|enum|explicit|export|'
193
+ r'extern|for|friend|goto|if|mutable|namespace|new|operator|'
194
+ r'private|protected|public|register|reinterpret_cast|return|'
195
+ r'restrict|sizeof|static|static_cast|struct|switch|template|'
196
+ r'this|throw|throws|try|typedef|typeid|typename|union|using|'
197
+ r'volatile|virtual|while)\b', Keyword),
198
+ (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
199
+ (r'(bool|int|long|float|short|double|char|unsigned|signed|'
200
+ r'void|wchar_t)\b', Keyword.Type),
201
+ (r'(_{0,2}inline|naked|thread)\b', Keyword.Reserved),
202
+ (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
203
+ r'declspec|finally|int64|try|leave|wchar_t|w64|virtual_inheritance|'
204
+ r'uuidof|unaligned|super|single_inheritance|raise|noop|'
205
+ r'multiple_inheritance|m128i|m128d|m128|m64|interface|'
206
+ r'identifier|forceinline|event|assume)\b', Keyword.Reserved),
207
+ (r'(true|false)\b', Keyword.Constant),
208
+ (r'NULL\b', Name.Builtin),
209
+ ('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label),
210
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
211
+ ],
212
+ 'classname': [
213
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'),
214
+ # template specification
215
+ (r'\s*(?=>)', Text, '#pop'),
216
+ ],
217
+ 'string': [
218
+ (r'"', String, '#pop'),
219
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
220
+ (r'[^\\"\n]+', String), # all other characters
221
+ (r'\\\n', String), # line continuation
222
+ (r'\\', String), # stray backslash
223
+ ],
224
+ 'macro': [
225
+ (r'[^/\n]+', Comment.Preproc),
226
+ (r'/[*](.|\n)*?[*]/', Comment.Multiline),
227
+ (r'//.*?\n', Comment.Single, '#pop'),
228
+ (r'/', Comment.Preproc),
229
+ (r'(?<=\\)\n', Comment.Preproc),
230
+ (r'\n', Comment.Preproc, '#pop'),
231
+ ],
232
+ 'if0': [
233
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
234
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
235
+ (r'.*?\n', Comment),
236
+ ]
237
+ }
238
+
239
+
240
+ class DLexer(RegexLexer):
241
+ """
242
+ For D source.
243
+
244
+ *New in Pygments 1.2.*
245
+ """
246
+ name = 'D'
247
+ filenames = ['*.d', '*.di']
248
+ aliases = ['d']
249
+ mimetypes = ['text/x-dsrc']
250
+
251
+ tokens = {
252
+ 'root': [
253
+ (r'\n', Text),
254
+ (r'\s+', Text),
255
+ #(r'\\\n', Text), # line continuations
256
+ # Comments
257
+ (r'//(.*?)\n', Comment.Single),
258
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
259
+ (r'/\+', Comment.Multiline, 'nested_comment'),
260
+ # Keywords
261
+ (r'(abstract|alias|align|asm|assert|auto|body|break|case|cast'
262
+ r'|catch|class|const|continue|debug|default|delegate|delete'
263
+ r'|deprecated|do|else|enum|export|extern|finally|final'
264
+ r'|foreach_reverse|foreach|for|function|goto|if|import|inout'
265
+ r'|interface|invariant|in|is|lazy|mixin|module|new|nothrow|out'
266
+ r'|override|package|pragma|private|protected|public|pure|ref|return'
267
+ r'|scope|static|struct|super|switch|synchronized|template|this'
268
+ r'|throw|try|typedef|typeid|typeof|union|unittest|version|volatile'
269
+ r'|while|with|__traits)\b', Keyword
270
+ ),
271
+ (r'(bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|float'
272
+ r'|idouble|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong'
273
+ r'|ushort|void|wchar)\b', Keyword.Type
274
+ ),
275
+ (r'(false|true|null)\b', Keyword.Constant),
276
+ (r'macro\b', Keyword.Reserved),
277
+ (r'(string|wstring|dstring)\b', Name.Builtin),
278
+ # FloatLiteral
279
+ # -- HexFloat
280
+ (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
281
+ r'[pP][+\-]?[0-9_]+[fFL]?[i]?', Number.Float),
282
+ # -- DecimalFloat
283
+ (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
284
+ r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?', Number.Float),
285
+ (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?', Number.Float),
286
+ # IntegerLiteral
287
+ # -- Binary
288
+ (r'0[Bb][01_]+', Number),
289
+ # -- Octal
290
+ (r'0[0-7_]+', Number.Oct),
291
+ # -- Hexadecimal
292
+ (r'0[xX][0-9a-fA-F_]+', Number.Hex),
293
+ # -- Decimal
294
+ (r'(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?', Number.Integer),
295
+ # CharacterLiteral
296
+ (r"""'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
297
+ r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'""",
298
+ String.Char
299
+ ),
300
+ # StringLiteral
301
+ # -- WysiwygString
302
+ (r'r"[^"]*"[cwd]?', String),
303
+ # -- AlternateWysiwygString
304
+ (r'`[^`]*`[cwd]?', String),
305
+ # -- DoubleQuotedString
306
+ (r'"(\\\\|\\"|[^"])*"[cwd]?', String),
307
+ # -- EscapeSequence
308
+ (r"\\(['\"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}"
309
+ r"|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)",
310
+ String
311
+ ),
312
+ # -- HexString
313
+ (r'x"[0-9a-fA-F_\s]*"[cwd]?', String),
314
+ # -- DelimitedString
315
+ (r'q"\[', String, 'delimited_bracket'),
316
+ (r'q"\(', String, 'delimited_parenthesis'),
317
+ (r'q"<', String, 'delimited_angle'),
318
+ (r'q"{', String, 'delimited_curly'),
319
+ (r'q"([a-zA-Z_]\w*)\n.*?\n\1"', String),
320
+ (r'q"(.).*?\1"', String),
321
+ # -- TokenString
322
+ (r'q{', String, 'token_string'),
323
+ # Tokens
324
+ (r'(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>='
325
+ r'|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)'
326
+ r'|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]', Punctuation
327
+ ),
328
+ # Identifier
329
+ (r'[a-zA-Z_]\w*', Name),
330
+ ],
331
+ 'nested_comment': [
332
+ (r'[^+/]+', Comment.Multiline),
333
+ (r'/\+', Comment.Multiline, '#push'),
334
+ (r'\+/', Comment.Multiline, '#pop'),
335
+ (r'[+/]', Comment.Multiline),
336
+ ],
337
+ 'token_string': [
338
+ (r'{', Punctuation, 'token_string_nest'),
339
+ (r'}', String, '#pop'),
340
+ include('root'),
341
+ ],
342
+ 'token_string_nest': [
343
+ (r'{', Punctuation, '#push'),
344
+ (r'}', Punctuation, '#pop'),
345
+ include('root'),
346
+ ],
347
+ 'delimited_bracket': [
348
+ (r'[^\[\]]+', String),
349
+ (r'\[', String, 'delimited_inside_bracket'),
350
+ (r'\]"', String, '#pop'),
351
+ ],
352
+ 'delimited_inside_bracket': [
353
+ (r'[^\[\]]+', String),
354
+ (r'\[', String, '#push'),
355
+ (r'\]', String, '#pop'),
356
+ ],
357
+ 'delimited_parenthesis': [
358
+ (r'[^\(\)]+', String),
359
+ (r'\(', String, 'delimited_inside_parenthesis'),
360
+ (r'\)"', String, '#pop'),
361
+ ],
362
+ 'delimited_inside_parenthesis': [
363
+ (r'[^\(\)]+', String),
364
+ (r'\(', String, '#push'),
365
+ (r'\)', String, '#pop'),
366
+ ],
367
+ 'delimited_angle': [
368
+ (r'[^<>]+', String),
369
+ (r'<', String, 'delimited_inside_angle'),
370
+ (r'>"', String, '#pop'),
371
+ ],
372
+ 'delimited_inside_angle': [
373
+ (r'[^<>]+', String),
374
+ (r'<', String, '#push'),
375
+ (r'>', String, '#pop'),
376
+ ],
377
+ 'delimited_curly': [
378
+ (r'[^{}]+', String),
379
+ (r'{', String, 'delimited_inside_curly'),
380
+ (r'}"', String, '#pop'),
381
+ ],
382
+ 'delimited_inside_curly': [
383
+ (r'[^{}]+', String),
384
+ (r'{', String, '#push'),
385
+ (r'}', String, '#pop'),
386
+ ],
387
+ }
388
+
389
+
390
+ class DelphiLexer(Lexer):
391
+ """
392
+ For `Delphi <http://www.borland.com/delphi/>`_ (Borland Object Pascal),
393
+ Turbo Pascal and Free Pascal source code.
394
+
395
+ Additional options accepted:
396
+
397
+ `turbopascal`
398
+ Highlight Turbo Pascal specific keywords (default: ``True``).
399
+ `delphi`
400
+ Highlight Borland Delphi specific keywords (default: ``True``).
401
+ `freepascal`
402
+ Highlight Free Pascal specific keywords (default: ``True``).
403
+ `units`
404
+ A list of units that should be considered builtin, supported are
405
+ ``System``, ``SysUtils``, ``Classes`` and ``Math``.
406
+ Default is to consider all of them builtin.
407
+ """
408
+ name = 'Delphi'
409
+ aliases = ['delphi', 'pas', 'pascal', 'objectpascal']
410
+ filenames = ['*.pas']
411
+ mimetypes = ['text/x-pascal']
412
+
413
+ TURBO_PASCAL_KEYWORDS = [
414
+ 'absolute', 'and', 'array', 'asm', 'begin', 'break', 'case',
415
+ 'const', 'constructor', 'continue', 'destructor', 'div', 'do',
416
+ 'downto', 'else', 'end', 'file', 'for', 'function', 'goto',
417
+ 'if', 'implementation', 'in', 'inherited', 'inline', 'interface',
418
+ 'label', 'mod', 'nil', 'not', 'object', 'of', 'on', 'operator',
419
+ 'or', 'packed', 'procedure', 'program', 'record', 'reintroduce',
420
+ 'repeat', 'self', 'set', 'shl', 'shr', 'string', 'then', 'to',
421
+ 'type', 'unit', 'until', 'uses', 'var', 'while', 'with', 'xor'
422
+ ]
423
+
424
+ DELPHI_KEYWORDS = [
425
+ 'as', 'class', 'except', 'exports', 'finalization', 'finally',
426
+ 'initialization', 'is', 'library', 'on', 'property', 'raise',
427
+ 'threadvar', 'try'
428
+ ]
429
+
430
+ FREE_PASCAL_KEYWORDS = [
431
+ 'dispose', 'exit', 'false', 'new', 'true'
432
+ ]
433
+
434
+ BLOCK_KEYWORDS = set([
435
+ 'begin', 'class', 'const', 'constructor', 'destructor', 'end',
436
+ 'finalization', 'function', 'implementation', 'initialization',
437
+ 'label', 'library', 'operator', 'procedure', 'program', 'property',
438
+ 'record', 'threadvar', 'type', 'unit', 'uses', 'var'
439
+ ])
440
+
441
+ FUNCTION_MODIFIERS = set([
442
+ 'alias', 'cdecl', 'export', 'inline', 'interrupt', 'nostackframe',
443
+ 'pascal', 'register', 'safecall', 'softfloat', 'stdcall',
444
+ 'varargs', 'name', 'dynamic', 'near', 'virtual', 'external',
445
+ 'override', 'assembler'
446
+ ])
447
+
448
+ # XXX: those aren't global. but currently we know no way for defining
449
+ # them just for the type context.
450
+ DIRECTIVES = set([
451
+ 'absolute', 'abstract', 'assembler', 'cppdecl', 'default', 'far',
452
+ 'far16', 'forward', 'index', 'oldfpccall', 'private', 'protected',
453
+ 'published', 'public'
454
+ ])
455
+
456
+ BUILTIN_TYPES = set([
457
+ 'ansichar', 'ansistring', 'bool', 'boolean', 'byte', 'bytebool',
458
+ 'cardinal', 'char', 'comp', 'currency', 'double', 'dword',
459
+ 'extended', 'int64', 'integer', 'iunknown', 'longbool', 'longint',
460
+ 'longword', 'pansichar', 'pansistring', 'pbool', 'pboolean',
461
+ 'pbyte', 'pbytearray', 'pcardinal', 'pchar', 'pcomp', 'pcurrency',
462
+ 'pdate', 'pdatetime', 'pdouble', 'pdword', 'pextended', 'phandle',
463
+ 'pint64', 'pinteger', 'plongint', 'plongword', 'pointer',
464
+ 'ppointer', 'pshortint', 'pshortstring', 'psingle', 'psmallint',
465
+ 'pstring', 'pvariant', 'pwidechar', 'pwidestring', 'pword',
466
+ 'pwordarray', 'pwordbool', 'real', 'real48', 'shortint',
467
+ 'shortstring', 'single', 'smallint', 'string', 'tclass', 'tdate',
468
+ 'tdatetime', 'textfile', 'thandle', 'tobject', 'ttime', 'variant',
469
+ 'widechar', 'widestring', 'word', 'wordbool'
470
+ ])
471
+
472
+ BUILTIN_UNITS = {
473
+ 'System': [
474
+ 'abs', 'acquireexceptionobject', 'addr', 'ansitoutf8',
475
+ 'append', 'arctan', 'assert', 'assigned', 'assignfile',
476
+ 'beginthread', 'blockread', 'blockwrite', 'break', 'chdir',
477
+ 'chr', 'close', 'closefile', 'comptocurrency', 'comptodouble',
478
+ 'concat', 'continue', 'copy', 'cos', 'dec', 'delete',
479
+ 'dispose', 'doubletocomp', 'endthread', 'enummodules',
480
+ 'enumresourcemodules', 'eof', 'eoln', 'erase', 'exceptaddr',
481
+ 'exceptobject', 'exclude', 'exit', 'exp', 'filepos', 'filesize',
482
+ 'fillchar', 'finalize', 'findclasshinstance', 'findhinstance',
483
+ 'findresourcehinstance', 'flush', 'frac', 'freemem',
484
+ 'get8087cw', 'getdir', 'getlasterror', 'getmem',
485
+ 'getmemorymanager', 'getmodulefilename', 'getvariantmanager',
486
+ 'halt', 'hi', 'high', 'inc', 'include', 'initialize', 'insert',
487
+ 'int', 'ioresult', 'ismemorymanagerset', 'isvariantmanagerset',
488
+ 'length', 'ln', 'lo', 'low', 'mkdir', 'move', 'new', 'odd',
489
+ 'olestrtostring', 'olestrtostrvar', 'ord', 'paramcount',
490
+ 'paramstr', 'pi', 'pos', 'pred', 'ptr', 'pucs4chars', 'random',
491
+ 'randomize', 'read', 'readln', 'reallocmem',
492
+ 'releaseexceptionobject', 'rename', 'reset', 'rewrite', 'rmdir',
493
+ 'round', 'runerror', 'seek', 'seekeof', 'seekeoln',
494
+ 'set8087cw', 'setlength', 'setlinebreakstyle',
495
+ 'setmemorymanager', 'setstring', 'settextbuf',
496
+ 'setvariantmanager', 'sin', 'sizeof', 'slice', 'sqr', 'sqrt',
497
+ 'str', 'stringofchar', 'stringtoolestr', 'stringtowidechar',
498
+ 'succ', 'swap', 'trunc', 'truncate', 'typeinfo',
499
+ 'ucs4stringtowidestring', 'unicodetoutf8', 'uniquestring',
500
+ 'upcase', 'utf8decode', 'utf8encode', 'utf8toansi',
501
+ 'utf8tounicode', 'val', 'vararrayredim', 'varclear',
502
+ 'widecharlentostring', 'widecharlentostrvar',
503
+ 'widechartostring', 'widechartostrvar',
504
+ 'widestringtoucs4string', 'write', 'writeln'
505
+ ],
506
+ 'SysUtils': [
507
+ 'abort', 'addexitproc', 'addterminateproc', 'adjustlinebreaks',
508
+ 'allocmem', 'ansicomparefilename', 'ansicomparestr',
509
+ 'ansicomparetext', 'ansidequotedstr', 'ansiextractquotedstr',
510
+ 'ansilastchar', 'ansilowercase', 'ansilowercasefilename',
511
+ 'ansipos', 'ansiquotedstr', 'ansisamestr', 'ansisametext',
512
+ 'ansistrcomp', 'ansistricomp', 'ansistrlastchar', 'ansistrlcomp',
513
+ 'ansistrlicomp', 'ansistrlower', 'ansistrpos', 'ansistrrscan',
514
+ 'ansistrscan', 'ansistrupper', 'ansiuppercase',
515
+ 'ansiuppercasefilename', 'appendstr', 'assignstr', 'beep',
516
+ 'booltostr', 'bytetocharindex', 'bytetocharlen', 'bytetype',
517
+ 'callterminateprocs', 'changefileext', 'charlength',
518
+ 'chartobyteindex', 'chartobytelen', 'comparemem', 'comparestr',
519
+ 'comparetext', 'createdir', 'createguid', 'currentyear',
520
+ 'currtostr', 'currtostrf', 'date', 'datetimetofiledate',
521
+ 'datetimetostr', 'datetimetostring', 'datetimetosystemtime',
522
+ 'datetimetotimestamp', 'datetostr', 'dayofweek', 'decodedate',
523
+ 'decodedatefully', 'decodetime', 'deletefile', 'directoryexists',
524
+ 'diskfree', 'disksize', 'disposestr', 'encodedate', 'encodetime',
525
+ 'exceptionerrormessage', 'excludetrailingbackslash',
526
+ 'excludetrailingpathdelimiter', 'expandfilename',
527
+ 'expandfilenamecase', 'expanduncfilename', 'extractfiledir',
528
+ 'extractfiledrive', 'extractfileext', 'extractfilename',
529
+ 'extractfilepath', 'extractrelativepath', 'extractshortpathname',
530
+ 'fileage', 'fileclose', 'filecreate', 'filedatetodatetime',
531
+ 'fileexists', 'filegetattr', 'filegetdate', 'fileisreadonly',
532
+ 'fileopen', 'fileread', 'filesearch', 'fileseek', 'filesetattr',
533
+ 'filesetdate', 'filesetreadonly', 'filewrite', 'finalizepackage',
534
+ 'findclose', 'findcmdlineswitch', 'findfirst', 'findnext',
535
+ 'floattocurr', 'floattodatetime', 'floattodecimal', 'floattostr',
536
+ 'floattostrf', 'floattotext', 'floattotextfmt', 'fmtloadstr',
537
+ 'fmtstr', 'forcedirectories', 'format', 'formatbuf', 'formatcurr',
538
+ 'formatdatetime', 'formatfloat', 'freeandnil', 'getcurrentdir',
539
+ 'getenvironmentvariable', 'getfileversion', 'getformatsettings',
540
+ 'getlocaleformatsettings', 'getmodulename', 'getpackagedescription',
541
+ 'getpackageinfo', 'gettime', 'guidtostring', 'incamonth',
542
+ 'includetrailingbackslash', 'includetrailingpathdelimiter',
543
+ 'incmonth', 'initializepackage', 'interlockeddecrement',
544
+ 'interlockedexchange', 'interlockedexchangeadd',
545
+ 'interlockedincrement', 'inttohex', 'inttostr', 'isdelimiter',
546
+ 'isequalguid', 'isleapyear', 'ispathdelimiter', 'isvalidident',
547
+ 'languages', 'lastdelimiter', 'loadpackage', 'loadstr',
548
+ 'lowercase', 'msecstotimestamp', 'newstr', 'nextcharindex', 'now',
549
+ 'outofmemoryerror', 'quotedstr', 'raiselastoserror',
550
+ 'raiselastwin32error', 'removedir', 'renamefile', 'replacedate',
551
+ 'replacetime', 'safeloadlibrary', 'samefilename', 'sametext',
552
+ 'setcurrentdir', 'showexception', 'sleep', 'stralloc', 'strbufsize',
553
+ 'strbytetype', 'strcat', 'strcharlength', 'strcomp', 'strcopy',
554
+ 'strdispose', 'strecopy', 'strend', 'strfmt', 'stricomp',
555
+ 'stringreplace', 'stringtoguid', 'strlcat', 'strlcomp', 'strlcopy',
556
+ 'strlen', 'strlfmt', 'strlicomp', 'strlower', 'strmove', 'strnew',
557
+ 'strnextchar', 'strpas', 'strpcopy', 'strplcopy', 'strpos',
558
+ 'strrscan', 'strscan', 'strtobool', 'strtobooldef', 'strtocurr',
559
+ 'strtocurrdef', 'strtodate', 'strtodatedef', 'strtodatetime',
560
+ 'strtodatetimedef', 'strtofloat', 'strtofloatdef', 'strtoint',
561
+ 'strtoint64', 'strtoint64def', 'strtointdef', 'strtotime',
562
+ 'strtotimedef', 'strupper', 'supports', 'syserrormessage',
563
+ 'systemtimetodatetime', 'texttofloat', 'time', 'timestamptodatetime',
564
+ 'timestamptomsecs', 'timetostr', 'trim', 'trimleft', 'trimright',
565
+ 'tryencodedate', 'tryencodetime', 'tryfloattocurr', 'tryfloattodatetime',
566
+ 'trystrtobool', 'trystrtocurr', 'trystrtodate', 'trystrtodatetime',
567
+ 'trystrtofloat', 'trystrtoint', 'trystrtoint64', 'trystrtotime',
568
+ 'unloadpackage', 'uppercase', 'widecomparestr', 'widecomparetext',
569
+ 'widefmtstr', 'wideformat', 'wideformatbuf', 'widelowercase',
570
+ 'widesamestr', 'widesametext', 'wideuppercase', 'win32check',
571
+ 'wraptext'
572
+ ],
573
+ 'Classes': [
574
+ 'activateclassgroup', 'allocatehwnd', 'bintohex', 'checksynchronize',
575
+ 'collectionsequal', 'countgenerations', 'deallocatehwnd', 'equalrect',
576
+ 'extractstrings', 'findclass', 'findglobalcomponent', 'getclass',
577
+ 'groupdescendantswith', 'hextobin', 'identtoint',
578
+ 'initinheritedcomponent', 'inttoident', 'invalidpoint',
579
+ 'isuniqueglobalcomponentname', 'linestart', 'objectbinarytotext',
580
+ 'objectresourcetotext', 'objecttexttobinary', 'objecttexttoresource',
581
+ 'pointsequal', 'readcomponentres', 'readcomponentresex',
582
+ 'readcomponentresfile', 'rect', 'registerclass', 'registerclassalias',
583
+ 'registerclasses', 'registercomponents', 'registerintegerconsts',
584
+ 'registernoicon', 'registernonactivex', 'smallpoint', 'startclassgroup',
585
+ 'teststreamformat', 'unregisterclass', 'unregisterclasses',
586
+ 'unregisterintegerconsts', 'unregistermoduleclasses',
587
+ 'writecomponentresfile'
588
+ ],
589
+ 'Math': [
590
+ 'arccos', 'arccosh', 'arccot', 'arccoth', 'arccsc', 'arccsch', 'arcsec',
591
+ 'arcsech', 'arcsin', 'arcsinh', 'arctan2', 'arctanh', 'ceil',
592
+ 'comparevalue', 'cosecant', 'cosh', 'cot', 'cotan', 'coth', 'csc',
593
+ 'csch', 'cycletodeg', 'cycletograd', 'cycletorad', 'degtocycle',
594
+ 'degtograd', 'degtorad', 'divmod', 'doubledecliningbalance',
595
+ 'ensurerange', 'floor', 'frexp', 'futurevalue', 'getexceptionmask',
596
+ 'getprecisionmode', 'getroundmode', 'gradtocycle', 'gradtodeg',
597
+ 'gradtorad', 'hypot', 'inrange', 'interestpayment', 'interestrate',
598
+ 'internalrateofreturn', 'intpower', 'isinfinite', 'isnan', 'iszero',
599
+ 'ldexp', 'lnxp1', 'log10', 'log2', 'logn', 'max', 'maxintvalue',
600
+ 'maxvalue', 'mean', 'meanandstddev', 'min', 'minintvalue', 'minvalue',
601
+ 'momentskewkurtosis', 'netpresentvalue', 'norm', 'numberofperiods',
602
+ 'payment', 'periodpayment', 'poly', 'popnstddev', 'popnvariance',
603
+ 'power', 'presentvalue', 'radtocycle', 'radtodeg', 'radtograd',
604
+ 'randg', 'randomrange', 'roundto', 'samevalue', 'sec', 'secant',
605
+ 'sech', 'setexceptionmask', 'setprecisionmode', 'setroundmode',
606
+ 'sign', 'simpleroundto', 'sincos', 'sinh', 'slndepreciation', 'stddev',
607
+ 'sum', 'sumint', 'sumofsquares', 'sumsandsquares', 'syddepreciation',
608
+ 'tan', 'tanh', 'totalvariance', 'variance'
609
+ ]
610
+ }
611
+
612
+ ASM_REGISTERS = set([
613
+ 'ah', 'al', 'ax', 'bh', 'bl', 'bp', 'bx', 'ch', 'cl', 'cr0',
614
+ 'cr1', 'cr2', 'cr3', 'cr4', 'cs', 'cx', 'dh', 'di', 'dl', 'dr0',
615
+ 'dr1', 'dr2', 'dr3', 'dr4', 'dr5', 'dr6', 'dr7', 'ds', 'dx',
616
+ 'eax', 'ebp', 'ebx', 'ecx', 'edi', 'edx', 'es', 'esi', 'esp',
617
+ 'fs', 'gs', 'mm0', 'mm1', 'mm2', 'mm3', 'mm4', 'mm5', 'mm6',
618
+ 'mm7', 'si', 'sp', 'ss', 'st0', 'st1', 'st2', 'st3', 'st4', 'st5',
619
+ 'st6', 'st7', 'xmm0', 'xmm1', 'xmm2', 'xmm3', 'xmm4', 'xmm5',
620
+ 'xmm6', 'xmm7'
621
+ ])
622
+
623
+ ASM_INSTRUCTIONS = set([
624
+ 'aaa', 'aad', 'aam', 'aas', 'adc', 'add', 'and', 'arpl', 'bound',
625
+ 'bsf', 'bsr', 'bswap', 'bt', 'btc', 'btr', 'bts', 'call', 'cbw',
626
+ 'cdq', 'clc', 'cld', 'cli', 'clts', 'cmc', 'cmova', 'cmovae',
627
+ 'cmovb', 'cmovbe', 'cmovc', 'cmovcxz', 'cmove', 'cmovg',
628
+ 'cmovge', 'cmovl', 'cmovle', 'cmovna', 'cmovnae', 'cmovnb',
629
+ 'cmovnbe', 'cmovnc', 'cmovne', 'cmovng', 'cmovnge', 'cmovnl',
630
+ 'cmovnle', 'cmovno', 'cmovnp', 'cmovns', 'cmovnz', 'cmovo',
631
+ 'cmovp', 'cmovpe', 'cmovpo', 'cmovs', 'cmovz', 'cmp', 'cmpsb',
632
+ 'cmpsd', 'cmpsw', 'cmpxchg', 'cmpxchg486', 'cmpxchg8b', 'cpuid',
633
+ 'cwd', 'cwde', 'daa', 'das', 'dec', 'div', 'emms', 'enter', 'hlt',
634
+ 'ibts', 'icebp', 'idiv', 'imul', 'in', 'inc', 'insb', 'insd',
635
+ 'insw', 'int', 'int01', 'int03', 'int1', 'int3', 'into', 'invd',
636
+ 'invlpg', 'iret', 'iretd', 'iretw', 'ja', 'jae', 'jb', 'jbe',
637
+ 'jc', 'jcxz', 'jcxz', 'je', 'jecxz', 'jg', 'jge', 'jl', 'jle',
638
+ 'jmp', 'jna', 'jnae', 'jnb', 'jnbe', 'jnc', 'jne', 'jng', 'jnge',
639
+ 'jnl', 'jnle', 'jno', 'jnp', 'jns', 'jnz', 'jo', 'jp', 'jpe',
640
+ 'jpo', 'js', 'jz', 'lahf', 'lar', 'lcall', 'lds', 'lea', 'leave',
641
+ 'les', 'lfs', 'lgdt', 'lgs', 'lidt', 'ljmp', 'lldt', 'lmsw',
642
+ 'loadall', 'loadall286', 'lock', 'lodsb', 'lodsd', 'lodsw',
643
+ 'loop', 'loope', 'loopne', 'loopnz', 'loopz', 'lsl', 'lss', 'ltr',
644
+ 'mov', 'movd', 'movq', 'movsb', 'movsd', 'movsw', 'movsx',
645
+ 'movzx', 'mul', 'neg', 'nop', 'not', 'or', 'out', 'outsb', 'outsd',
646
+ 'outsw', 'pop', 'popa', 'popad', 'popaw', 'popf', 'popfd', 'popfw',
647
+ 'push', 'pusha', 'pushad', 'pushaw', 'pushf', 'pushfd', 'pushfw',
648
+ 'rcl', 'rcr', 'rdmsr', 'rdpmc', 'rdshr', 'rdtsc', 'rep', 'repe',
649
+ 'repne', 'repnz', 'repz', 'ret', 'retf', 'retn', 'rol', 'ror',
650
+ 'rsdc', 'rsldt', 'rsm', 'sahf', 'sal', 'salc', 'sar', 'sbb',
651
+ 'scasb', 'scasd', 'scasw', 'seta', 'setae', 'setb', 'setbe',
652
+ 'setc', 'setcxz', 'sete', 'setg', 'setge', 'setl', 'setle',
653
+ 'setna', 'setnae', 'setnb', 'setnbe', 'setnc', 'setne', 'setng',
654
+ 'setnge', 'setnl', 'setnle', 'setno', 'setnp', 'setns', 'setnz',
655
+ 'seto', 'setp', 'setpe', 'setpo', 'sets', 'setz', 'sgdt', 'shl',
656
+ 'shld', 'shr', 'shrd', 'sidt', 'sldt', 'smi', 'smint', 'smintold',
657
+ 'smsw', 'stc', 'std', 'sti', 'stosb', 'stosd', 'stosw', 'str',
658
+ 'sub', 'svdc', 'svldt', 'svts', 'syscall', 'sysenter', 'sysexit',
659
+ 'sysret', 'test', 'ud1', 'ud2', 'umov', 'verr', 'verw', 'wait',
660
+ 'wbinvd', 'wrmsr', 'wrshr', 'xadd', 'xbts', 'xchg', 'xlat',
661
+ 'xlatb', 'xor'
662
+ ])
663
+
664
+ def __init__(self, **options):
665
+ Lexer.__init__(self, **options)
666
+ self.keywords = set()
667
+ if get_bool_opt(options, 'turbopascal', True):
668
+ self.keywords.update(self.TURBO_PASCAL_KEYWORDS)
669
+ if get_bool_opt(options, 'delphi', True):
670
+ self.keywords.update(self.DELPHI_KEYWORDS)
671
+ if get_bool_opt(options, 'freepascal', True):
672
+ self.keywords.update(self.FREE_PASCAL_KEYWORDS)
673
+ self.builtins = set()
674
+ for unit in get_list_opt(options, 'units', self.BUILTIN_UNITS.keys()):
675
+ self.builtins.update(self.BUILTIN_UNITS[unit])
676
+
677
+ def get_tokens_unprocessed(self, text):
678
+ scanner = Scanner(text, re.DOTALL | re.MULTILINE | re.IGNORECASE)
679
+ stack = ['initial']
680
+ in_function_block = False
681
+ in_property_block = False
682
+ was_dot = False
683
+ next_token_is_function = False
684
+ next_token_is_property = False
685
+ collect_labels = False
686
+ block_labels = set()
687
+ brace_balance = [0, 0]
688
+
689
+ while not scanner.eos:
690
+ token = Error
691
+
692
+ if stack[-1] == 'initial':
693
+ if scanner.scan(r'\s+'):
694
+ token = Text
695
+ elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
696
+ if scanner.match.startswith('$'):
697
+ token = Comment.Preproc
698
+ else:
699
+ token = Comment.Multiline
700
+ elif scanner.scan(r'//.*?$'):
701
+ token = Comment.Single
702
+ elif scanner.scan(r'[-+*\/=<>:;,.@\^]'):
703
+ token = Operator
704
+ # stop label highlighting on next ";"
705
+ if collect_labels and scanner.match == ';':
706
+ collect_labels = False
707
+ elif scanner.scan(r'[\(\)\[\]]+'):
708
+ token = Punctuation
709
+ # abort function naming ``foo = Function(...)``
710
+ next_token_is_function = False
711
+ # if we are in a function block we count the open
712
+ # braces because ootherwise it's impossible to
713
+ # determine the end of the modifier context
714
+ if in_function_block or in_property_block:
715
+ if scanner.match == '(':
716
+ brace_balance[0] += 1
717
+ elif scanner.match == ')':
718
+ brace_balance[0] -= 1
719
+ elif scanner.match == '[':
720
+ brace_balance[1] += 1
721
+ elif scanner.match == ']':
722
+ brace_balance[1] -= 1
723
+ elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
724
+ lowercase_name = scanner.match.lower()
725
+ if lowercase_name == 'result':
726
+ token = Name.Builtin.Pseudo
727
+ elif lowercase_name in self.keywords:
728
+ token = Keyword
729
+ # if we are in a special block and a
730
+ # block ending keyword occours (and the parenthesis
731
+ # is balanced) we end the current block context
732
+ if (in_function_block or in_property_block) and \
733
+ lowercase_name in self.BLOCK_KEYWORDS and \
734
+ brace_balance[0] <= 0 and \
735
+ brace_balance[1] <= 0:
736
+ in_function_block = False
737
+ in_property_block = False
738
+ brace_balance = [0, 0]
739
+ block_labels = set()
740
+ if lowercase_name in ('label', 'goto'):
741
+ collect_labels = True
742
+ elif lowercase_name == 'asm':
743
+ stack.append('asm')
744
+ elif lowercase_name == 'property':
745
+ in_property_block = True
746
+ next_token_is_property = True
747
+ elif lowercase_name in ('procedure', 'operator',
748
+ 'function', 'constructor',
749
+ 'destructor'):
750
+ in_function_block = True
751
+ next_token_is_function = True
752
+ # we are in a function block and the current name
753
+ # is in the set of registered modifiers. highlight
754
+ # it as pseudo keyword
755
+ elif in_function_block and \
756
+ lowercase_name in self.FUNCTION_MODIFIERS:
757
+ token = Keyword.Pseudo
758
+ # if we are in a property highlight some more
759
+ # modifiers
760
+ elif in_property_block and \
761
+ lowercase_name in ('read', 'write'):
762
+ token = Keyword.Pseudo
763
+ next_token_is_function = True
764
+ # if the last iteration set next_token_is_function
765
+ # to true we now want this name highlighted as
766
+ # function. so do that and reset the state
767
+ elif next_token_is_function:
768
+ # Look if the next token is a dot. If yes it's
769
+ # not a function, but a class name and the
770
+ # part after the dot a function name
771
+ if scanner.test(r'\s*\.\s*'):
772
+ token = Name.Class
773
+ # it's not a dot, our job is done
774
+ else:
775
+ token = Name.Function
776
+ next_token_is_function = False
777
+ # same for properties
778
+ elif next_token_is_property:
779
+ token = Name.Property
780
+ next_token_is_property = False
781
+ # Highlight this token as label and add it
782
+ # to the list of known labels
783
+ elif collect_labels:
784
+ token = Name.Label
785
+ block_labels.add(scanner.match.lower())
786
+ # name is in list of known labels
787
+ elif lowercase_name in block_labels:
788
+ token = Name.Label
789
+ elif lowercase_name in self.BUILTIN_TYPES:
790
+ token = Keyword.Type
791
+ elif lowercase_name in self.DIRECTIVES:
792
+ token = Keyword.Pseudo
793
+ # builtins are just builtins if the token
794
+ # before isn't a dot
795
+ elif not was_dot and lowercase_name in self.builtins:
796
+ token = Name.Builtin
797
+ else:
798
+ token = Name
799
+ elif scanner.scan(r"'"):
800
+ token = String
801
+ stack.append('string')
802
+ elif scanner.scan(r'\#(\d+|\$[0-9A-Fa-f]+)'):
803
+ token = String.Char
804
+ elif scanner.scan(r'\$[0-9A-Fa-f]+'):
805
+ token = Number.Hex
806
+ elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
807
+ token = Number.Integer
808
+ elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
809
+ token = Number.Float
810
+ else:
811
+ # if the stack depth is deeper than once, pop
812
+ if len(stack) > 1:
813
+ stack.pop()
814
+ scanner.get_char()
815
+
816
+ elif stack[-1] == 'string':
817
+ if scanner.scan(r"''"):
818
+ token = String.Escape
819
+ elif scanner.scan(r"'"):
820
+ token = String
821
+ stack.pop()
822
+ elif scanner.scan(r"[^']*"):
823
+ token = String
824
+ else:
825
+ scanner.get_char()
826
+ stack.pop()
827
+
828
+ elif stack[-1] == 'asm':
829
+ if scanner.scan(r'\s+'):
830
+ token = Text
831
+ elif scanner.scan(r'end'):
832
+ token = Keyword
833
+ stack.pop()
834
+ elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
835
+ if scanner.match.startswith('$'):
836
+ token = Comment.Preproc
837
+ else:
838
+ token = Comment.Multiline
839
+ elif scanner.scan(r'//.*?$'):
840
+ token = Comment.Single
841
+ elif scanner.scan(r"'"):
842
+ token = String
843
+ stack.append('string')
844
+ elif scanner.scan(r'@@[A-Za-z_][A-Za-z_0-9]*'):
845
+ token = Name.Label
846
+ elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
847
+ lowercase_name = scanner.match.lower()
848
+ if lowercase_name in self.ASM_INSTRUCTIONS:
849
+ token = Keyword
850
+ elif lowercase_name in self.ASM_REGISTERS:
851
+ token = Name.Builtin
852
+ else:
853
+ token = Name
854
+ elif scanner.scan(r'[-+*\/=<>:;,.@\^]+'):
855
+ token = Operator
856
+ elif scanner.scan(r'[\(\)\[\]]+'):
857
+ token = Punctuation
858
+ elif scanner.scan(r'\$[0-9A-Fa-f]+'):
859
+ token = Number.Hex
860
+ elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
861
+ token = Number.Integer
862
+ elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
863
+ token = Number.Float
864
+ else:
865
+ scanner.get_char()
866
+ stack.pop()
867
+
868
+ # save the dot!!!11
869
+ if scanner.match.strip():
870
+ was_dot = scanner.match == '.'
871
+ yield scanner.start_pos, token, scanner.match or ''
872
+
873
+
874
+ class JavaLexer(RegexLexer):
875
+ """
876
+ For `Java <http://www.sun.com/java/>`_ source code.
877
+ """
878
+
879
+ name = 'Java'
880
+ aliases = ['java']
881
+ filenames = ['*.java']
882
+ mimetypes = ['text/x-java']
883
+
884
+ flags = re.MULTILINE | re.DOTALL
885
+
886
+ #: optional Comment or Whitespace
887
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
888
+
889
+ tokens = {
890
+ 'root': [
891
+ # method names
892
+ (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments
893
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
894
+ r'(\s*)(\()', # signature start
895
+ bygroups(using(this), Name.Function, Text, Operator)),
896
+ (r'[^\S\n]+', Text),
897
+ (r'//.*?\n', Comment.Single),
898
+ (r'/\*.*?\*/', Comment.Multiline),
899
+ (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
900
+ (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
901
+ r'if|goto|instanceof|new|return|switch|this|throw|try|while)\b',
902
+ Keyword),
903
+ (r'(abstract|const|enum|extends|final|implements|native|private|'
904
+ r'protected|public|static|strictfp|super|synchronized|throws|'
905
+ r'transient|volatile)\b', Keyword.Declaration),
906
+ (r'(boolean|byte|char|double|float|int|long|short|void)\b',
907
+ Keyword.Type),
908
+ (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
909
+ (r'(true|false|null)\b', Keyword.Constant),
910
+ (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text), 'class'),
911
+ (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
912
+ (r'"(\\\\|\\"|[^"])*"', String),
913
+ (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
914
+ (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
915
+ (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
916
+ (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
917
+ (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
918
+ (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
919
+ (r'0x[0-9a-f]+', Number.Hex),
920
+ (r'[0-9]+L?', Number.Integer),
921
+ (r'\n', Text)
922
+ ],
923
+ 'class': [
924
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
925
+ ],
926
+ 'import': [
927
+ (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
928
+ ],
929
+ }
930
+
931
+
932
+ class ScalaLexer(RegexLexer):
933
+ """
934
+ For `Scala <http://www.scala-lang.org>`_ source code.
935
+ """
936
+
937
+ name = 'Scala'
938
+ aliases = ['scala']
939
+ filenames = ['*.scala']
940
+ mimetypes = ['text/x-scala']
941
+
942
+ flags = re.MULTILINE | re.DOTALL
943
+
944
+ #: optional Comment or Whitespace
945
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
946
+
947
+ # don't use raw unicode strings!
948
+ op = u'[-~\\^\\*!%&\\\\<>\\|+=:/?@\u00a6-\u00a7\u00a9\u00ac\u00ae\u00b0-\u00b1\u00b6\u00d7\u00f7\u03f6\u0482\u0606-\u0608\u060e-\u060f\u06e9\u06fd-\u06fe\u07f6\u09fa\u0b70\u0bf3-\u0bf8\u0bfa\u0c7f\u0cf1-\u0cf2\u0d79\u0f01-\u0f03\u0f13-\u0f17\u0f1a-\u0f1f\u0f34\u0f36\u0f38\u0fbe-\u0fc5\u0fc7-\u0fcf\u109e-\u109f\u1360\u1390-\u1399\u1940\u19e0-\u19ff\u1b61-\u1b6a\u1b74-\u1b7c\u2044\u2052\u207a-\u207c\u208a-\u208c\u2100-\u2101\u2103-\u2106\u2108-\u2109\u2114\u2116-\u2118\u211e-\u2123\u2125\u2127\u2129\u212e\u213a-\u213b\u2140-\u2144\u214a-\u214d\u214f\u2190-\u2328\u232b-\u244a\u249c-\u24e9\u2500-\u2767\u2794-\u27c4\u27c7-\u27e5\u27f0-\u2982\u2999-\u29d7\u29dc-\u29fb\u29fe-\u2b54\u2ce5-\u2cea\u2e80-\u2ffb\u3004\u3012-\u3013\u3020\u3036-\u3037\u303e-\u303f\u3190-\u3191\u3196-\u319f\u31c0-\u31e3\u3200-\u321e\u322a-\u3250\u3260-\u327f\u328a-\u32b0\u32c0-\u33ff\u4dc0-\u4dff\ua490-\ua4c6\ua828-\ua82b\ufb29\ufdfd\ufe62\ufe64-\ufe66\uff0b\uff1c-\uff1e\uff5c\uff5e\uffe2\uffe4\uffe8-\uffee\ufffc-\ufffd]+'
949
+
950
+ letter = u'[a-zA-Z\\$_\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02af\u0370-\u0373\u0376-\u0377\u037b-\u037d\u0386\u0388-\u03f5\u03f7-\u0481\u048a-\u0556\u0561-\u0587\u05d0-\u05f2\u0621-\u063f\u0641-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u0904-\u0939\u093d\u0950\u0958-\u0961\u0972-\u097f\u0985-\u09b9\u09bd\u09ce\u09dc-\u09e1\u09f0-\u09f1\u0a05-\u0a39\u0a59-\u0a5e\u0a72-\u0a74\u0a85-\u0ab9\u0abd\u0ad0-\u0ae1\u0b05-\u0b39\u0b3d\u0b5c-\u0b61\u0b71\u0b83-\u0bb9\u0bd0\u0c05-\u0c3d\u0c58-\u0c61\u0c85-\u0cb9\u0cbd\u0cde-\u0ce1\u0d05-\u0d3d\u0d60-\u0d61\u0d7a-\u0d7f\u0d85-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0eb0\u0eb2-\u0eb3\u0ebd-\u0ec4\u0edc-\u0f00\u0f40-\u0f6c\u0f88-\u0f8b\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065-\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10fa\u1100-\u135a\u1380-\u138f\u13a0-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u16ee-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u1770\u1780-\u17b3\u17dc\u1820-\u1842\u1844-\u18a8\u18aa-\u191c\u1950-\u19a9\u19c1-\u19c7\u1a00-\u1a16\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae-\u1baf\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c77\u1d00-\u1d2b\u1d62-\u1d77\u1d79-\u1d9a\u1e00-\u1fbc\u1fbe\u1fc2-\u1fcc\u1fd0-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ffc\u2071\u207f\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c7c\u2c80-\u2ce4\u2d00-\u2d65\u2d80-\u2dde\u3006-\u3007\u3021-\u3029\u3038-\u303a\u303c\u3041-\u3096\u309f\u30a1-\u30fa\u30ff-\u318e\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\ua014\ua016-\ua48c\ua500-\ua60b\ua610-\ua61f\ua62a-\ua66e\ua680-\ua697\ua722-\ua76f\ua771-\ua787\ua78b-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua90a-\ua925\ua930-\ua946\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uac00-\ud7a3\uf900-\ufb1d\ufb1f-\ufb28\ufb2a-\ufd3d\ufd50-\ufdfb\ufe70-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uff6f\uff71-\uff9d\uffa0-\uffdc]'
951
+
952
+ upper = u'[A-Z\\$_\u00c0-\u00d6\u00d8-\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0132\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0166\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178-\u0179\u017b\u017d\u0181-\u0182\u0184\u0186-\u0187\u0189-\u018b\u018e-\u0191\u0193-\u0194\u0196-\u0198\u019c-\u019d\u019f-\u01a0\u01a2\u01a4\u01a6-\u01a7\u01a9\u01ac\u01ae-\u01af\u01b1-\u01b3\u01b5\u01b7-\u01b8\u01bc\u01c4\u01c7\u01ca\u01cd\u01cf\u01d1\u01d3\u01d5\u01d7\u01d9\u01db\u01de\u01e0\u01e2\u01e4\u01e6\u01e8\u01ea\u01ec\u01ee\u01f1\u01f4\u01f6-\u01f8\u01fa\u01fc\u01fe\u0200\u0202\u0204\u0206\u0208\u020a\u020c\u020e\u0210\u0212\u0214\u0216\u0218\u021a\u021c\u021e\u0220\u0222\u0224\u0226\u0228\u022a\u022c\u022e\u0230\u0232\u023a-\u023b\u023d-\u023e\u0241\u0243-\u0246\u0248\u024a\u024c\u024e\u0370\u0372\u0376\u0386\u0388-\u038f\u0391-\u03ab\u03cf\u03d2-\u03d4\u03d8\u03da\u03dc\u03de\u03e0\u03e2\u03e4\u03e6\u03e8\u03ea\u03ec\u03ee\u03f4\u03f7\u03f9-\u03fa\u03fd-\u042f\u0460\u0462\u0464\u0466\u0468\u046a\u046c\u046e\u0470\u0472\u0474\u0476\u0478\u047a\u047c\u047e\u0480\u048a\u048c\u048e\u0490\u0492\u0494\u0496\u0498\u049a\u049c\u049e\u04a0\u04a2\u04a4\u04a6\u04a8\u04aa\u04ac\u04ae\u04b0\u04b2\u04b4\u04b6\u04b8\u04ba\u04bc\u04be\u04c0-\u04c1\u04c3\u04c5\u04c7\u04c9\u04cb\u04cd\u04d0\u04d2\u04d4\u04d6\u04d8\u04da\u04dc\u04de\u04e0\u04e2\u04e4\u04e6\u04e8\u04ea\u04ec\u04ee\u04f0\u04f2\u04f4\u04f6\u04f8\u04fa\u04fc\u04fe\u0500\u0502\u0504\u0506\u0508\u050a\u050c\u050e\u0510\u0512\u0514\u0516\u0518\u051a\u051c\u051e\u0520\u0522\u0531-\u0556\u10a0-\u10c5\u1e00\u1e02\u1e04\u1e06\u1e08\u1e0a\u1e0c\u1e0e\u1e10\u1e12\u1e14\u1e16\u1e18\u1e1a\u1e1c\u1e1e\u1e20\u1e22\u1e24\u1e26\u1e28\u1e2a\u1e2c\u1e2e\u1e30\u1e32\u1e34\u1e36\u1e38\u1e3a\u1e3c\u1e3e\u1e40\u1e42\u1e44\u1e46\u1e48\u1e4a\u1e4c\u1e4e\u1e50\u1e52\u1e54\u1e56\u1e58\u1e5a\u1e5c\u1e5e\u1e60\u1e62\u1e64\u1e66\u1e68\u1e6a\u1e6c\u1e6e\u1e70\u1e72\u1e74\u1e76\u1e78\u1e7a\u1e7c\u1e7e\u1e80\u1e82\u1e84\u1e86\u1e88\u1e8a\u1e8c\u1e8e\u1e90\u1e92\u1e94\u1e9e\u1ea0\u1ea2\u1ea4\u1ea6\u1ea8\u1eaa\u1eac\u1eae\u1eb0\u1eb2\u1eb4\u1eb6\u1eb8\u1eba\u1ebc\u1ebe\u1ec0\u1ec2\u1ec4\u1ec6\u1ec8\u1eca\u1ecc\u1ece\u1ed0\u1ed2\u1ed4\u1ed6\u1ed8\u1eda\u1edc\u1ede\u1ee0\u1ee2\u1ee4\u1ee6\u1ee8\u1eea\u1eec\u1eee\u1ef0\u1ef2\u1ef4\u1ef6\u1ef8\u1efa\u1efc\u1efe\u1f08-\u1f0f\u1f18-\u1f1d\u1f28-\u1f2f\u1f38-\u1f3f\u1f48-\u1f4d\u1f59-\u1f5f\u1f68-\u1f6f\u1fb8-\u1fbb\u1fc8-\u1fcb\u1fd8-\u1fdb\u1fe8-\u1fec\u1ff8-\u1ffb\u2102\u2107\u210b-\u210d\u2110-\u2112\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u2130-\u2133\u213e-\u213f\u2145\u2183\u2c00-\u2c2e\u2c60\u2c62-\u2c64\u2c67\u2c69\u2c6b\u2c6d-\u2c6f\u2c72\u2c75\u2c80\u2c82\u2c84\u2c86\u2c88\u2c8a\u2c8c\u2c8e\u2c90\u2c92\u2c94\u2c96\u2c98\u2c9a\u2c9c\u2c9e\u2ca0\u2ca2\u2ca4\u2ca6\u2ca8\u2caa\u2cac\u2cae\u2cb0\u2cb2\u2cb4\u2cb6\u2cb8\u2cba\u2cbc\u2cbe\u2cc0\u2cc2\u2cc4\u2cc6\u2cc8\u2cca\u2ccc\u2cce\u2cd0\u2cd2\u2cd4\u2cd6\u2cd8\u2cda\u2cdc\u2cde\u2ce0\u2ce2\ua640\ua642\ua644\ua646\ua648\ua64a\ua64c\ua64e\ua650\ua652\ua654\ua656\ua658\ua65a\ua65c\ua65e\ua662\ua664\ua666\ua668\ua66a\ua66c\ua680\ua682\ua684\ua686\ua688\ua68a\ua68c\ua68e\ua690\ua692\ua694\ua696\ua722\ua724\ua726\ua728\ua72a\ua72c\ua72e\ua732\ua734\ua736\ua738\ua73a\ua73c\ua73e\ua740\ua742\ua744\ua746\ua748\ua74a\ua74c\ua74e\ua750\ua752\ua754\ua756\ua758\ua75a\ua75c\ua75e\ua760\ua762\ua764\ua766\ua768\ua76a\ua76c\ua76e\ua779\ua77b\ua77d-\ua77e\ua780\ua782\ua784\ua786\ua78b\uff21-\uff3a]'
953
+
954
+ idrest = ur'%s(?:%s|[0-9])*(?:(?<=_)%s)?' % (letter, letter, op)
955
+
956
+ tokens = {
957
+ 'root': [
958
+ # method names
959
+ (r'(class|trait|object)(\s+)', bygroups(Keyword, Text), 'class'),
960
+ (ur"'%s" % idrest, Text.Symbol),
961
+ (r'[^\S\n]+', Text),
962
+ (r'//.*?\n', Comment.Single),
963
+ (r'/\*', Comment.Multiline, 'comment'),
964
+ (ur'@%s' % idrest, Name.Decorator),
965
+ (ur'(abstract|ca(?:se|tch)|d(?:ef|o)|e(?:lse|xtends)|'
966
+ ur'f(?:inal(?:ly)?|or(?:Some)?)|i(?:f|mplicit)|'
967
+ ur'lazy|match|new|override|pr(?:ivate|otected)'
968
+ ur'|re(?:quires|turn)|s(?:ealed|uper)|'
969
+ ur't(?:h(?:is|row)|ry)|va[lr]|w(?:hile|ith)|yield)\b|'
970
+ u'(<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\b|(?=\\s)|$)', Keyword),
971
+ (ur':(?!%s)' % op, Keyword, 'type'),
972
+ (ur'%s%s\b' % (upper, idrest), Name.Class),
973
+ (r'(true|false|null)\b', Keyword.Constant),
974
+ (r'(import|package)(\s+)', bygroups(Keyword, Text), 'import'),
975
+ (r'(type)(\s+)', bygroups(Keyword, Text), 'type'),
976
+ (r'"""(?:.|\n)*?"""', String),
977
+ (r'"(\\\\|\\"|[^"])*"', String),
978
+ (ur"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
979
+ # (ur'(\.)(%s|%s|`[^`]+`)' % (idrest, op), bygroups(Operator,
980
+ # Name.Attribute)),
981
+ (idrest, Name),
982
+ (r'`[^`]+`', Name),
983
+ (r'\[', Operator, 'typeparam'),
984
+ (r'[\(\)\{\};,.]', Operator),
985
+ (op, Operator),
986
+ (ur'([0-9][0-9]*\.[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?[fFdD]?',
987
+ Number.Float),
988
+ (r'0x[0-9a-f]+', Number.Hex),
989
+ (r'[0-9]+L?', Number.Integer),
990
+ (r'\n', Text)
991
+ ],
992
+ 'class': [
993
+ (ur'(%s|%s|`[^`]+`)(\s*)(\[)' % (idrest, op),
994
+ bygroups(Name.Class, Text, Operator), 'typeparam'),
995
+ (r'[\s\n]+', Text),
996
+ (r'{', Operator, '#pop'),
997
+ (r'\(', Operator, '#pop'),
998
+ (ur'%s|%s|`[^`]+`' % (idrest, op), Name.Class, '#pop'),
999
+ ],
1000
+ 'type': [
1001
+ (r'\s+', Text),
1002
+ (u'<[%:]|>:|[#_\u21D2]|forSome|type', Keyword),
1003
+ (r'([,\);}]|=>|=)([\s\n]*)', bygroups(Operator, Text), '#pop'),
1004
+ (r'[\(\{]', Operator, '#push'),
1005
+ (ur'((?:%s|%s|`[^`]+`)(?:\.(?:%s|%s|`[^`]+`))*)(\s*)(\[)' %
1006
+ (idrest, op, idrest, op),
1007
+ bygroups(Keyword.Type, Text, Operator), ('#pop', 'typeparam')),
1008
+ (ur'((?:%s|%s|`[^`]+`)(?:\.(?:%s|%s|`[^`]+`))*)(\s*)$' %
1009
+ (idrest, op, idrest, op),
1010
+ bygroups(Keyword.Type, Text), '#pop'),
1011
+ (ur'\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
1012
+ ],
1013
+ 'typeparam': [
1014
+ (r'[\s\n,]+', Text),
1015
+ (u'<[%:]|=>|>:|[#_\u21D2]|forSome|type', Keyword),
1016
+ (r'([\]\)\}])', Operator, '#pop'),
1017
+ (r'[\(\[\{]', Operator, '#push'),
1018
+ (ur'\.|%s|%s|`[^`]+`' % (idrest, op), Keyword.Type)
1019
+ ],
1020
+ 'comment': [
1021
+ (r'[^/\*]+', Comment.Multiline),
1022
+ (r'/\*', Comment.Multiline, '#push'),
1023
+ (r'\*/', Comment.Multiline, '#pop'),
1024
+ (r'[*/]', Comment.Multiline)
1025
+ ],
1026
+ 'import': [
1027
+ (ur'(%s|\.)+' % idrest, Name.Namespace, '#pop')
1028
+ ],
1029
+ }
1030
+
1031
+
1032
+ class DylanLexer(RegexLexer):
1033
+ """
1034
+ For the `Dylan <http://www.opendylan.org/>`_ language.
1035
+
1036
+ *New in Pygments 0.7.*
1037
+ """
1038
+
1039
+ name = 'Dylan'
1040
+ aliases = ['dylan']
1041
+ filenames = ['*.dylan']
1042
+ mimetypes = ['text/x-dylan']
1043
+
1044
+ flags = re.DOTALL
1045
+
1046
+ tokens = {
1047
+ 'root': [
1048
+ (r'\b(subclass|abstract|block|c(on(crete|stant)|lass)|domain'
1049
+ r'|ex(c(eption|lude)|port)|f(unction(|al))|generic|handler'
1050
+ r'|i(n(herited|line|stance|terface)|mport)|library|m(acro|ethod)'
1051
+ r'|open|primary|sealed|si(deways|ngleton)|slot'
1052
+ r'|v(ariable|irtual))\b', Name.Builtin),
1053
+ (r'<\w+>', Keyword.Type),
1054
+ (r'#?"(?:\\.|[^"])+?"', String.Double),
1055
+ (r'//.*?\n', Comment.Single),
1056
+ (r'/\*[\w\W]*?\*/', Comment.Multiline),
1057
+ (r'\'.*?\'', String.Single),
1058
+ (r'=>|\b(a(bove|fterwards)|b(e(gin|low)|y)|c(ase|leanup|reate)'
1059
+ r'|define|else(|if)|end|f(inally|or|rom)|i[fn]|l(et|ocal)|otherwise'
1060
+ r'|rename|s(elect|ignal)|t(hen|o)|u(n(less|til)|se)|wh(en|ile))\b',
1061
+ Keyword),
1062
+ (r'([ \t])([!\$%&\*\/:<=>\?~_^a-zA-Z0-9.+\-]*:)',
1063
+ bygroups(Text, Name.Variable)),
1064
+ (r'([ \t]*)(\S+[^:])([ \t]*)(\()([ \t]*)',
1065
+ bygroups(Text, Name.Function, Text, Punctuation, Text)),
1066
+ (r'-?[0-9.]+', Number),
1067
+ (r'[(),;]', Punctuation),
1068
+ (r'\$[a-zA-Z0-9-]+', Name.Constant),
1069
+ (r'[!$%&*/:<>=?~^.+\[\]{}-]+', Operator),
1070
+ (r'\s+', Text),
1071
+ (r'#[a-zA-Z0-9-]+', Keyword),
1072
+ (r'[a-zA-Z0-9-]+', Name.Variable),
1073
+ ],
1074
+ }
1075
+
1076
+
1077
+ class ObjectiveCLexer(RegexLexer):
1078
+ """
1079
+ For Objective-C source code with preprocessor directives.
1080
+ """
1081
+
1082
+ name = 'Objective-C'
1083
+ aliases = ['objective-c', 'objectivec', 'obj-c', 'objc']
1084
+ #XXX: objc has .h files too :-/
1085
+ filenames = ['*.m']
1086
+ mimetypes = ['text/x-objective-c']
1087
+
1088
+ #: optional Comment or Whitespace
1089
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
1090
+
1091
+ tokens = {
1092
+ 'whitespace': [
1093
+ (r'^(\s*)(#if\s+0)', bygroups(Text, Comment.Preproc), 'if0'),
1094
+ (r'^(\s*)(#)', bygroups(Text, Comment.Preproc), 'macro'),
1095
+ (r'\n', Text),
1096
+ (r'\s+', Text),
1097
+ (r'\\\n', Text), # line continuation
1098
+ (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
1099
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1100
+ ],
1101
+ 'statements': [
1102
+ (r'(L|@)?"', String, 'string'),
1103
+ (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1104
+ String.Char),
1105
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
1106
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
1107
+ (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
1108
+ (r'0[0-7]+[Ll]?', Number.Oct),
1109
+ (r'\d+[Ll]?', Number.Integer),
1110
+ (r'[~!%^&*+=|?:<>/-]', Operator),
1111
+ (r'[()\[\],.]', Punctuation),
1112
+ (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
1113
+ r'for|goto|if|register|restricted|return|sizeof|static|struct|'
1114
+ r'switch|typedef|union|volatile|virtual|while|in|@selector|'
1115
+ r'@private|@protected|@public|@encode|'
1116
+ r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
1117
+ r'@synthesize|@dynamic)\b', Keyword),
1118
+ (r'(int|long|float|short|double|char|unsigned|signed|void|'
1119
+ r'id|BOOL|IBOutlet|IBAction|SEL)\b', Keyword.Type),
1120
+ (r'(_{0,2}inline|naked|restrict|thread|typename)\b',
1121
+ Keyword.Reserved),
1122
+ (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
1123
+ r'declspec|finally|int64|try|leave)\b', Keyword.Reserved),
1124
+ (r'(TRUE|FALSE|nil|NULL)\b', Name.Builtin),
1125
+ ('[a-zA-Z$_][a-zA-Z0-9$_]*:(?!:)', Name.Label),
1126
+ ('[a-zA-Z$_][a-zA-Z0-9$_]*', Name),
1127
+ ],
1128
+ 'root': [
1129
+ include('whitespace'),
1130
+ # functions
1131
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
1132
+ r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name
1133
+ r'(\s*\([^;]*?\))' # signature
1134
+ r'(' + _ws + r')({)',
1135
+ bygroups(using(this), Name.Function,
1136
+ using(this), Text, Punctuation),
1137
+ 'function'),
1138
+ # function declarations
1139
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
1140
+ r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name
1141
+ r'(\s*\([^;]*?\))' # signature
1142
+ r'(' + _ws + r')(;)',
1143
+ bygroups(using(this), Name.Function,
1144
+ using(this), Text, Punctuation)),
1145
+ (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
1146
+ 'classname'),
1147
+ (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text),
1148
+ 'forward_classname'),
1149
+ (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
1150
+ ('', Text, 'statement'),
1151
+ ],
1152
+ 'classname' : [
1153
+ # interface definition that inherits
1154
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?',
1155
+ bygroups(Name.Class, Text, Name.Class), '#pop'),
1156
+ # interface definition for a category
1157
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\([a-zA-Z$_][a-zA-Z0-9$_]*\))',
1158
+ bygroups(Name.Class, Text, Name.Label), '#pop'),
1159
+ # simple interface / implementation
1160
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop')
1161
+ ],
1162
+ 'forward_classname' : [
1163
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*,\s*)',
1164
+ bygroups(Name.Class, Text), 'forward_classname'),
1165
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*;?)',
1166
+ bygroups(Name.Class, Text), '#pop')
1167
+ ],
1168
+ 'statement' : [
1169
+ include('whitespace'),
1170
+ include('statements'),
1171
+ ('[{}]', Punctuation),
1172
+ (';', Punctuation, '#pop'),
1173
+ ],
1174
+ 'function': [
1175
+ include('whitespace'),
1176
+ include('statements'),
1177
+ (';', Punctuation),
1178
+ ('{', Punctuation, '#push'),
1179
+ ('}', Punctuation, '#pop'),
1180
+ ],
1181
+ 'string': [
1182
+ (r'"', String, '#pop'),
1183
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
1184
+ (r'[^\\"\n]+', String), # all other characters
1185
+ (r'\\\n', String), # line continuation
1186
+ (r'\\', String), # stray backslash
1187
+ ],
1188
+ 'macro': [
1189
+ (r'[^/\n]+', Comment.Preproc),
1190
+ (r'/[*](.|\n)*?[*]/', Comment.Multiline),
1191
+ (r'//.*?\n', Comment.Single, '#pop'),
1192
+ (r'/', Comment.Preproc),
1193
+ (r'(?<=\\)\n', Comment.Preproc),
1194
+ (r'\n', Comment.Preproc, '#pop'),
1195
+ ],
1196
+ 'if0': [
1197
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
1198
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
1199
+ (r'.*?\n', Comment),
1200
+ ]
1201
+ }
1202
+
1203
+ def analyse_text(text):
1204
+ if '@"' in text: # strings
1205
+ return True
1206
+ if re.match(r'\[[a-zA-Z0-9.]:', text): # message
1207
+ return True
1208
+ return False
1209
+
1210
+ class FortranLexer(RegexLexer):
1211
+ '''
1212
+ Lexer for FORTRAN 90 code.
1213
+
1214
+ *New in Pygments 0.10.*
1215
+ '''
1216
+ name = 'Fortran'
1217
+ aliases = ['fortran']
1218
+ filenames = ['*.f', '*.f90']
1219
+ mimetypes = ['text/x-fortran']
1220
+ flags = re.IGNORECASE
1221
+
1222
+ # Data Types: INTEGER, REAL, COMPLEX, LOGICAL, CHARACTER and DOUBLE PRECISION
1223
+ # Operators: **, *, +, -, /, <, >, <=, >=, ==, /=
1224
+ # Logical (?): NOT, AND, OR, EQV, NEQV
1225
+
1226
+ # Builtins:
1227
+ # http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Table-of-Intrinsic-Functions.html
1228
+
1229
+ tokens = {
1230
+ 'root': [
1231
+ (r'!.*\n', Comment),
1232
+ include('strings'),
1233
+ include('core'),
1234
+ (r'[a-z][a-z0-9_]*', Name.Variable),
1235
+ include('nums'),
1236
+ (r'[\s]+', Text),
1237
+ ],
1238
+ 'core': [
1239
+ # Statements
1240
+ (r'\b(ACCEPT|ALLOCATABLE|ALLOCATE|ARRAY|ASSIGN|BACKSPACE|BLOCK DATA|'
1241
+ r'BYTE|CALL|CASE|CLOSE|COMMON|CONTAINS|CONTINUE|CYCLE|DATA|'
1242
+ r'DEALLOCATE|DECODE|DIMENSION|DO|ENCODE|END FILE|ENDIF|END|ENTRY|'
1243
+ r'EQUIVALENCE|EXIT|EXTERNAL|EXTRINSIC|FORALL|FORMAT|FUNCTION|GOTO|'
1244
+ r'IF|IMPLICIT|INCLUDE|INQUIRE|INTENT|INTERFACE|INTRINSIC|MODULE|'
1245
+ r'NAMELIST|NULLIFY|NONE|OPEN|OPTIONAL|OPTIONS|PARAMETER|PAUSE|'
1246
+ r'POINTER|PRINT|PRIVATE|PROGRAM|PUBLIC|PURE|READ|RECURSIVE|RETURN|'
1247
+ r'REWIND|SAVE|SELECT|SEQUENCE|STOP|SUBROUTINE|TARGET|TYPE|USE|'
1248
+ r'VOLATILE|WHERE|WRITE|WHILE|THEN|ELSE|ENDIF)\s*\b',
1249
+ Keyword),
1250
+
1251
+ # Data Types
1252
+ (r'\b(CHARACTER|COMPLEX|DOUBLE PRECISION|DOUBLE COMPLEX|INTEGER|'
1253
+ r'LOGICAL|REAL)\s*\b',
1254
+ Keyword.Type),
1255
+
1256
+ # Operators
1257
+ (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator),
1258
+
1259
+ (r'(::)', Keyword.Declaration),
1260
+
1261
+ (r'[(),:&%;]', Punctuation),
1262
+
1263
+ # Intrinsics
1264
+ (r'\b(Abort|Abs|Access|AChar|ACos|AdjustL|AdjustR|AImag|AInt|Alarm|'
1265
+ r'All|Allocated|ALog|AMax|AMin|AMod|And|ANInt|Any|'
1266
+ r'ASin|Associated|ATan|BesJ|BesJN|BesY|BesYN|'
1267
+ r'Bit_Size|BTest|CAbs|CCos|Ceiling|CExp|Char|ChDir|ChMod|CLog|'
1268
+ r'Cmplx|Complex|Conjg|Cos|CosH|Count|CPU_Time|CShift|CSin|CSqRt|'
1269
+ r'CTime|DAbs|DACos|DASin|DATan|Date_and_Time|DbesJ|'
1270
+ r'DbesJ|DbesJN|DbesY|DbesY|DbesYN|Dble|DCos|DCosH|DDiM|DErF|DErFC|'
1271
+ r'DExp|Digits|DiM|DInt|DLog|DLog|DMax|DMin|DMod|DNInt|Dot_Product|'
1272
+ r'DProd|DSign|DSinH|DSin|DSqRt|DTanH|DTan|DTime|EOShift|Epsilon|'
1273
+ r'ErF|ErFC|ETime|Exit|Exp|Exponent|FDate|FGet|FGetC|Float|'
1274
+ r'Floor|Flush|FNum|FPutC|FPut|Fraction|FSeek|FStat|FTell|'
1275
+ r'GError|GetArg|GetCWD|GetEnv|GetGId|GetLog|GetPId|GetUId|'
1276
+ r'GMTime|HostNm|Huge|IAbs|IAChar|IAnd|IArgC|IBClr|IBits|'
1277
+ r'IBSet|IChar|IDate|IDiM|IDInt|IDNInt|IEOr|IErrNo|IFix|Imag|'
1278
+ r'ImagPart|Index|Int|IOr|IRand|IsaTty|IShft|IShftC|ISign|'
1279
+ r'ITime|Kill|Kind|LBound|Len|Len_Trim|LGe|LGt|Link|LLe|LLt|LnBlnk|'
1280
+ r'Loc|Log|Log|Logical|Long|LShift|LStat|LTime|MatMul|Max|'
1281
+ r'MaxExponent|MaxLoc|MaxVal|MClock|Merge|Min|MinExponent|MinLoc|'
1282
+ r'MinVal|Mod|Modulo|MvBits|Nearest|NInt|Not|Or|Pack|PError|'
1283
+ r'Precision|Present|Product|Radix|Rand|Random_Number|Random_Seed|'
1284
+ r'Range|Real|RealPart|Rename|Repeat|Reshape|RRSpacing|RShift|Scale|'
1285
+ r'Scan|Second|Selected_Int_Kind|Selected_Real_Kind|Set_Exponent|'
1286
+ r'Shape|Short|Sign|Signal|SinH|Sin|Sleep|Sngl|Spacing|Spread|SqRt|'
1287
+ r'SRand|Stat|Sum|SymLnk|System|System_Clock|Tan|TanH|Time|'
1288
+ r'Tiny|Transfer|Transpose|Trim|TtyNam|UBound|UMask|Unlink|Unpack|'
1289
+ r'Verify|XOr|ZAbs|ZCos|ZExp|ZLog|ZSin|ZSqRt)\s*\b',
1290
+ Name.Builtin),
1291
+
1292
+ # Booleans
1293
+ (r'\.(true|false)\.', Name.Builtin),
1294
+ # Comparing Operators
1295
+ (r'\.(eq|ne|lt|le|gt|ge|not|and|or|eqv|neqv)\.', Operator.Word),
1296
+ ],
1297
+
1298
+ 'strings': [
1299
+ (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
1300
+ (r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
1301
+ ],
1302
+
1303
+ 'nums': [
1304
+ (r'\d+(?![.Ee])', Number.Integer),
1305
+ (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
1306
+ (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float),
1307
+ ],
1308
+ }
1309
+
1310
+
1311
+ class GLShaderLexer(RegexLexer):
1312
+ """
1313
+ GLSL (OpenGL Shader) lexer.
1314
+
1315
+ *New in Pygments 1.1.*
1316
+ """
1317
+ name = 'GLSL'
1318
+ aliases = ['glsl']
1319
+ filenames = ['*.vert', '*.frag', '*.geo']
1320
+ mimetypes = ['text/x-glslsrc']
1321
+
1322
+ tokens = {
1323
+ 'root': [
1324
+ (r'^#.*', Comment.Preproc),
1325
+ (r'//.*', Comment.Single),
1326
+ (r'/\*[\w\W]*\*/', Comment.Multiline),
1327
+ (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
1328
+ Operator),
1329
+ (r'[?:]', Operator), # quick hack for ternary
1330
+ (r'\bdefined\b', Operator),
1331
+ (r'[;{}(),\[\]]', Punctuation),
1332
+ #FIXME when e is present, no decimal point needed
1333
+ (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
1334
+ (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float),
1335
+ (r'0[xX][0-9a-fA-F]*', Number.Hex),
1336
+ (r'0[0-7]*', Number.Octal),
1337
+ (r'[1-9][0-9]*', Number.Integer),
1338
+ (r'\b(attribute|const|uniform|varying|centroid|break|continue|'
1339
+ r'do|for|while|if|else|in|out|inout|float|int|void|bool|true|'
1340
+ r'false|invariant|discard|return|mat[234]|mat[234]x[234]|'
1341
+ r'vec[234]|[ib]vec[234]|sampler[123]D|samplerCube|'
1342
+ r'sampler[12]DShadow|struct)\b', Keyword),
1343
+ (r'\b(asm|class|union|enum|typedef|template|this|packed|goto|'
1344
+ r'switch|default|inline|noinline|volatile|public|static|extern|'
1345
+ r'external|interface|long|short|double|half|fixed|unsigned|'
1346
+ r'lowp|mediump|highp|precision|input|output|hvec[234]|'
1347
+ r'[df]vec[234]|sampler[23]DRect|sampler2DRectShadow|sizeof|'
1348
+ r'cast|namespace|using)\b', Keyword), #future use
1349
+ (r'[a-zA-Z_][a-zA-Z_0-9]*', Name.Variable),
1350
+ (r'\.', Punctuation),
1351
+ (r'\s+', Text),
1352
+ ],
1353
+ }
1354
+
1355
+ class PrologLexer(RegexLexer):
1356
+ """
1357
+ Lexer for Prolog files.
1358
+ """
1359
+ name = 'Prolog'
1360
+ aliases = ['prolog']
1361
+ filenames = ['*.prolog', '*.pro', '*.pl']
1362
+ mimetypes = ['text/x-prolog']
1363
+
1364
+ flags = re.UNICODE
1365
+
1366
+ tokens = {
1367
+ 'root': [
1368
+ (r'^#.*', Comment.Single),
1369
+ (r'/\*', Comment.Multiline, 'nested-comment'),
1370
+ (r'%.*', Comment.Single),
1371
+ (r'[0-9]+', Number),
1372
+ (r'[\[\](){}|.,;!]', Punctuation),
1373
+ (r':-|-->', Punctuation),
1374
+ (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\U[0-9a-fA-F]{8}|'
1375
+ r'\\[0-7]+\\|\\[\w\W]|[^"])*"', String.Double),
1376
+ (r"'(?:''|[^'])*'", String.Atom), # quoted atom
1377
+ # Needs to not be followed by an atom.
1378
+ #(r'=(?=\s|[a-zA-Z\[])', Operator),
1379
+ (r'(is|<|>|=<|>=|==|=:=|=|/|//|\*|\+|-)(?=\s|[a-zA-Z0-9\[])',
1380
+ Operator),
1381
+ (r'(mod|div|not)\b', Operator),
1382
+ (r'_', Keyword), # The don't-care variable
1383
+ (r'([a-z]+)(:)', bygroups(Name.Namespace, Punctuation)),
1384
+ (u'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
1385
+ u'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)'
1386
+ u'(\\s*)(:-|-->)',
1387
+ bygroups(Name.Function, Text, Operator)), # function defn
1388
+ (u'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
1389
+ u'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)'
1390
+ u'(\\s*)(\\()',
1391
+ bygroups(Name.Function, Text, Punctuation)),
1392
+ (u'[a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
1393
+ u'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*',
1394
+ String.Atom), # atom, characters
1395
+ # This one includes !
1396
+ (u'[#&*+\\-./:<=>?@\\\\^~\u00a1-\u00bf\u2010-\u303f]+',
1397
+ String.Atom), # atom, graphics
1398
+ (r'[A-Z_][A-Za-z0-9_]*', Name.Variable),
1399
+ (u'\\s+|[\u2000-\u200f\ufff0-\ufffe\uffef]', Text),
1400
+ ],
1401
+ 'nested-comment': [
1402
+ (r'\*/', Comment.Multiline, '#pop'),
1403
+ (r'/\*', Comment.Multiline, '#push'),
1404
+ (r'[^*/]+', Comment.Multiline),
1405
+ (r'[*/]', Comment.Multiline),
1406
+ ],
1407
+ }
1408
+
1409
+ def analyse_text(text):
1410
+ return ':-' in text
1411
+
1412
+
1413
+ class CythonLexer(RegexLexer):
1414
+ """
1415
+ For Pyrex and `Cython <http://cython.org>`_ source code.
1416
+
1417
+ *New in Pygments 1.1.*
1418
+ """
1419
+
1420
+ name = 'Cython'
1421
+ aliases = ['cython', 'pyx']
1422
+ filenames = ['*.pyx', '*.pxd', '*.pxi']
1423
+ mimetypes = ['text/x-cython', 'application/x-cython']
1424
+
1425
+ tokens = {
1426
+ 'root': [
1427
+ (r'\n', Text),
1428
+ (r'^(\s*)("""(?:.|\n)*?""")', bygroups(Text, String.Doc)),
1429
+ (r"^(\s*)('''(?:.|\n)*?''')", bygroups(Text, String.Doc)),
1430
+ (r'[^\S\n]+', Text),
1431
+ (r'#.*$', Comment),
1432
+ (r'[]{}:(),;[]', Punctuation),
1433
+ (r'\\\n', Text),
1434
+ (r'\\', Text),
1435
+ (r'(in|is|and|or|not)\b', Operator.Word),
1436
+ (r'(<)([a-zA-Z0-9.?]+)(>)',
1437
+ bygroups(Punctuation, Keyword.Type, Punctuation)),
1438
+ (r'!=|==|<<|>>|[-~+/*%=<>&^|.?]', Operator),
1439
+ (r'(from)(\d+)(<=)(\s+)(<)(\d+)(:)',
1440
+ bygroups(Keyword, Number.Integer, Operator, Name, Operator,
1441
+ Name, Punctuation)),
1442
+ include('keywords'),
1443
+ (r'(def|property)(\s+)', bygroups(Keyword, Text), 'funcname'),
1444
+ (r'(cp?def)(\s+)', bygroups(Keyword, Text), 'cdef'),
1445
+ (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'classname'),
1446
+ (r'(from)(\s+)', bygroups(Keyword, Text), 'fromimport'),
1447
+ (r'(c?import)(\s+)', bygroups(Keyword, Text), 'import'),
1448
+ include('builtins'),
1449
+ include('backtick'),
1450
+ ('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'),
1451
+ ("(?:[rR]|[uU][rR]|[rR][uU])'''", String, 'tsqs'),
1452
+ ('(?:[rR]|[uU][rR]|[rR][uU])"', String, 'dqs'),
1453
+ ("(?:[rR]|[uU][rR]|[rR][uU])'", String, 'sqs'),
1454
+ ('[uU]?"""', String, combined('stringescape', 'tdqs')),
1455
+ ("[uU]?'''", String, combined('stringescape', 'tsqs')),
1456
+ ('[uU]?"', String, combined('stringescape', 'dqs')),
1457
+ ("[uU]?'", String, combined('stringescape', 'sqs')),
1458
+ include('name'),
1459
+ include('numbers'),
1460
+ ],
1461
+ 'keywords': [
1462
+ (r'(assert|break|by|continue|ctypedef|del|elif|else|except\??|exec|'
1463
+ r'finally|for|gil|global|if|include|lambda|nogil|pass|print|raise|'
1464
+ r'return|try|while|yield|as|with)\b', Keyword),
1465
+ (r'(DEF|IF|ELIF|ELSE)\b', Comment.Preproc),
1466
+ ],
1467
+ 'builtins': [
1468
+ (r'(?<!\.)(__import__|abs|all|any|apply|basestring|bin|bool|buffer|'
1469
+ r'bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|'
1470
+ r'complex|delattr|dict|dir|divmod|enumerate|eval|execfile|exit|'
1471
+ r'file|filter|float|frozenset|getattr|globals|hasattr|hash|hex|id|'
1472
+ r'input|int|intern|isinstance|issubclass|iter|len|list|locals|'
1473
+ r'long|map|max|min|next|object|oct|open|ord|pow|property|range|'
1474
+ r'raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|'
1475
+ r'sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|'
1476
+ r'vars|xrange|zip)\b', Name.Builtin),
1477
+ (r'(?<!\.)(self|None|Ellipsis|NotImplemented|False|True|NULL'
1478
+ r')\b', Name.Builtin.Pseudo),
1479
+ (r'(?<!\.)(ArithmeticError|AssertionError|AttributeError|'
1480
+ r'BaseException|DeprecationWarning|EOFError|EnvironmentError|'
1481
+ r'Exception|FloatingPointError|FutureWarning|GeneratorExit|IOError|'
1482
+ r'ImportError|ImportWarning|IndentationError|IndexError|KeyError|'
1483
+ r'KeyboardInterrupt|LookupError|MemoryError|NameError|'
1484
+ r'NotImplemented|NotImplementedError|OSError|OverflowError|'
1485
+ r'OverflowWarning|PendingDeprecationWarning|ReferenceError|'
1486
+ r'RuntimeError|RuntimeWarning|StandardError|StopIteration|'
1487
+ r'SyntaxError|SyntaxWarning|SystemError|SystemExit|TabError|'
1488
+ r'TypeError|UnboundLocalError|UnicodeDecodeError|'
1489
+ r'UnicodeEncodeError|UnicodeError|UnicodeTranslateError|'
1490
+ r'UnicodeWarning|UserWarning|ValueError|Warning|ZeroDivisionError'
1491
+ r')\b', Name.Exception),
1492
+ ],
1493
+ 'numbers': [
1494
+ (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
1495
+ (r'0\d+', Number.Oct),
1496
+ (r'0[xX][a-fA-F0-9]+', Number.Hex),
1497
+ (r'\d+L', Number.Integer.Long),
1498
+ (r'\d+', Number.Integer)
1499
+ ],
1500
+ 'backtick': [
1501
+ ('`.*?`', String.Backtick),
1502
+ ],
1503
+ 'name': [
1504
+ (r'@[a-zA-Z0-9_]+', Name.Decorator),
1505
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
1506
+ ],
1507
+ 'funcname': [
1508
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
1509
+ ],
1510
+ 'cdef': [
1511
+ (r'(public|readonly|extern|api|inline)\b', Keyword.Reserved),
1512
+ (r'(struct|enum|union|class)\b', Keyword),
1513
+ (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(?=[(:#=]|$)',
1514
+ bygroups(Name.Function, Text), '#pop'),
1515
+ (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(,)',
1516
+ bygroups(Name.Function, Text, Punctuation)),
1517
+ (r'from\b', Keyword, '#pop'),
1518
+ (r'as\b', Keyword),
1519
+ (r':', Punctuation, '#pop'),
1520
+ (r'(?=["\'])', Text, '#pop'),
1521
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Keyword.Type),
1522
+ (r'.', Text),
1523
+ ],
1524
+ 'classname': [
1525
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
1526
+ ],
1527
+ 'import': [
1528
+ (r'(\s+)(as)(\s+)', bygroups(Text, Keyword, Text)),
1529
+ (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace),
1530
+ (r'(\s*)(,)(\s*)', bygroups(Text, Operator, Text)),
1531
+ (r'', Text, '#pop') # all else: go back
1532
+ ],
1533
+ 'fromimport': [
1534
+ (r'(\s+)(c?import)\b', bygroups(Text, Keyword), '#pop'),
1535
+ (r'[a-zA-Z_.][a-zA-Z0-9_.]*', Name.Namespace),
1536
+ # ``cdef foo from "header"``, or ``for foo from 0 < i < 10``
1537
+ (r'', Text, '#pop'),
1538
+ ],
1539
+ 'stringescape': [
1540
+ (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
1541
+ r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
1542
+ ],
1543
+ 'strings': [
1544
+ (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
1545
+ '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
1546
+ (r'[^\\\'"%\n]+', String),
1547
+ # quotes, percents and backslashes must be parsed one at a time
1548
+ (r'[\'"\\]', String),
1549
+ # unhandled string formatting sign
1550
+ (r'%', String)
1551
+ # newlines are an error (use "nl" state)
1552
+ ],
1553
+ 'nl': [
1554
+ (r'\n', String)
1555
+ ],
1556
+ 'dqs': [
1557
+ (r'"', String, '#pop'),
1558
+ (r'\\\\|\\"|\\\n', String.Escape), # included here again for raw strings
1559
+ include('strings')
1560
+ ],
1561
+ 'sqs': [
1562
+ (r"'", String, '#pop'),
1563
+ (r"\\\\|\\'|\\\n", String.Escape), # included here again for raw strings
1564
+ include('strings')
1565
+ ],
1566
+ 'tdqs': [
1567
+ (r'"""', String, '#pop'),
1568
+ include('strings'),
1569
+ include('nl')
1570
+ ],
1571
+ 'tsqs': [
1572
+ (r"'''", String, '#pop'),
1573
+ include('strings'),
1574
+ include('nl')
1575
+ ],
1576
+ }
1577
+
1578
+
1579
+ class ValaLexer(RegexLexer):
1580
+ """
1581
+ For Vala source code with preprocessor directives.
1582
+
1583
+ *New in Pygments 1.1.*
1584
+ """
1585
+ name = 'Vala'
1586
+ aliases = ['vala', 'vapi']
1587
+ filenames = ['*.vala', '*.vapi']
1588
+ mimetypes = ['text/x-vala']
1589
+
1590
+ tokens = {
1591
+ 'whitespace': [
1592
+ (r'^\s*#if\s+0', Comment.Preproc, 'if0'),
1593
+ (r'\n', Text),
1594
+ (r'\s+', Text),
1595
+ (r'\\\n', Text), # line continuation
1596
+ (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
1597
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1598
+ ],
1599
+ 'statements': [
1600
+ (r'L?"', String, 'string'),
1601
+ (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1602
+ String.Char),
1603
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
1604
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
1605
+ (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
1606
+ (r'0[0-7]+[Ll]?', Number.Oct),
1607
+ (r'\d+[Ll]?', Number.Integer),
1608
+ (r'[~!%^&*+=|?:<>/-]', Operator),
1609
+ (r'(\[)(Compact|Immutable|(?:Boolean|Simple)Type)(\])',
1610
+ bygroups(Punctuation, Name.Decorator, Punctuation)),
1611
+ # TODO: "correctly" parse complex code attributes
1612
+ (r'(\[)(CCode|(?:Integer|Floating)Type)',
1613
+ bygroups(Punctuation, Name.Decorator)),
1614
+ (r'[()\[\],.]', Punctuation),
1615
+ (r'(as|base|break|case|catch|construct|continue|default|delete|do|'
1616
+ r'else|enum|finally|for|foreach|get|if|in|is|lock|new|out|params|'
1617
+ r'return|set|sizeof|switch|this|throw|try|typeof|while|yield)\b',
1618
+ Keyword),
1619
+ (r'(abstract|const|delegate|dynamic|ensures|extern|inline|internal|'
1620
+ r'override|owned|private|protected|public|ref|requires|signal|'
1621
+ r'static|throws|unowned|var|virtual|volatile|weak|yields)\b',
1622
+ Keyword.Declaration),
1623
+ (r'(namespace|using)(\s+)', bygroups(Keyword.Namespace, Text),
1624
+ 'namespace'),
1625
+ (r'(class|errordomain|interface|struct)(\s+)',
1626
+ bygroups(Keyword.Declaration, Text), 'class'),
1627
+ (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)',
1628
+ bygroups(Operator, Name.Attribute)),
1629
+ # void is an actual keyword, others are in glib-2.0.vapi
1630
+ (r'(void|bool|char|double|float|int|int8|int16|int32|int64|long|'
1631
+ r'short|size_t|ssize_t|string|time_t|uchar|uint|uint8|uint16|'
1632
+ r'uint32|uint64|ulong|unichar|ushort)\b', Keyword.Type),
1633
+ (r'(true|false|null)\b', Name.Builtin),
1634
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
1635
+ ],
1636
+ 'root': [
1637
+ include('whitespace'),
1638
+ ('', Text, 'statement'),
1639
+ ],
1640
+ 'statement' : [
1641
+ include('whitespace'),
1642
+ include('statements'),
1643
+ ('[{}]', Punctuation),
1644
+ (';', Punctuation, '#pop'),
1645
+ ],
1646
+ 'string': [
1647
+ (r'"', String, '#pop'),
1648
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
1649
+ (r'[^\\"\n]+', String), # all other characters
1650
+ (r'\\\n', String), # line continuation
1651
+ (r'\\', String), # stray backslash
1652
+ ],
1653
+ 'if0': [
1654
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
1655
+ (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
1656
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
1657
+ (r'.*?\n', Comment),
1658
+ ],
1659
+ 'class': [
1660
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
1661
+ ],
1662
+ 'namespace': [
1663
+ (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop')
1664
+ ],
1665
+ }
1666
+
1667
+
1668
+ class OocLexer(RegexLexer):
1669
+ """
1670
+ For `Ooc <http://ooc-lang.org/>`_ source code
1671
+
1672
+ *New in Pygments 1.2.*
1673
+ """
1674
+ name = 'Ooc'
1675
+ aliases = ['ooc']
1676
+ filenames = ['*.ooc']
1677
+ mimetypes = ['text/x-ooc']
1678
+
1679
+ tokens = {
1680
+ 'root': [
1681
+ (r'\b(class|interface|implement|abstract|extends|from|'
1682
+ r'this|super|new|const|final|static|import|use|extern|'
1683
+ r'inline|proto|break|continue|fallthrough|operator|if|else|for|'
1684
+ r'while|do|switch|case|as|in|version|return|true|false|null)\b',
1685
+ Keyword),
1686
+ (r'include\b', Keyword, 'include'),
1687
+ (r'(cover)([ \t]+)(from)([ \t]+)([a-zA-Z0-9_]+[*@]?)',
1688
+ bygroups(Keyword, Text, Keyword, Text, Name.Class)),
1689
+ (r'(func)((?:[ \t]|\\\n)+)(~[a-z_][a-zA-Z0-9_]*)',
1690
+ bygroups(Keyword, Text, Name.Function)),
1691
+ (r'\bfunc\b', Keyword),
1692
+ # Note: %= and ^= not listed on http://ooc-lang.org/syntax
1693
+ (r'//.*', Comment),
1694
+ (r'(?s)/\*.*?\*/', Comment.Multiline),
1695
+ (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|'
1696
+ r'&&?|\|\|?|\^=?)', Operator),
1697
+ (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text,
1698
+ Name.Function)),
1699
+ (r'[A-Z][A-Z0-9_]+', Name.Constant),
1700
+ (r'[A-Z][a-zA-Z0-9_]*([@*]|\[[ \t]*\])?', Name.Class),
1701
+
1702
+ (r'([a-z][a-zA-Z0-9_]*(?:~[a-z][a-zA-Z0-9_]*)?)((?:[ \t]|\\\n)*)(?=\()',
1703
+ bygroups(Name.Function, Text)),
1704
+ (r'[a-z][a-zA-Z0-9_]*', Name.Variable),
1705
+
1706
+ # : introduces types
1707
+ (r'[:(){}\[\];,]', Punctuation),
1708
+
1709
+ (r'0x[0-9a-fA-F]+', Number.Hex),
1710
+ (r'0c[0-9]+', Number.Octal),
1711
+ (r'0b[01]+', Number.Binary),
1712
+ (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float),
1713
+ (r'[0-9_]+', Number.Decimal),
1714
+
1715
+ (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\"])*"',
1716
+ String.Double),
1717
+ (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1718
+ String.Char),
1719
+ (r'@', Punctuation), # pointer dereference
1720
+ (r'\.', Punctuation), # imports or chain operator
1721
+
1722
+ (r'\\[ \t\n]', Text),
1723
+ (r'[ \t]+', Text),
1724
+ ],
1725
+ 'include': [
1726
+ (r'[\w/]+', Name),
1727
+ (r',', Punctuation),
1728
+ (r'[ \t]', Text),
1729
+ (r'[;\n]', Text, '#pop'),
1730
+ ],
1731
+ }
1732
+
1733
+
1734
+ class GoLexer(RegexLexer):
1735
+ """
1736
+ For `Go <http://golang.org>`_ source.
1737
+ """
1738
+ name = 'Go'
1739
+ filenames = ['*.go']
1740
+ aliases = ['go']
1741
+ mimetypes = ['text/x-gosrc']
1742
+
1743
+ tokens = {
1744
+ 'root': [
1745
+ (r'\n', Text),
1746
+ (r'\s+', Text),
1747
+ (r'\\\n', Text), # line continuations
1748
+ (r'//(.*?)\n', Comment.Single),
1749
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1750
+ (r'(break|default|func|interface|select'
1751
+ r'|case|defer|go|map|struct'
1752
+ r'|chan|else|goto|package|switch'
1753
+ r'|const|fallthrough|if|range|type'
1754
+ r'|continue|for|import|return|var)\b', Keyword
1755
+ ),
1756
+ # It seems the builtin types aren't actually keywords.
1757
+ (r'(uint8|uint16|uint32|uint64'
1758
+ r'|int8|int16|int32|int64'
1759
+ r'|float32|float64|byte'
1760
+ r'|uint|int|float|uintptr'
1761
+ r'|string|close|closed|len|cap|new|make)\b', Name.Builtin
1762
+ ),
1763
+ # float_lit
1764
+ (r'\d+(\.\d+[eE][+\-]?\d+|'
1765
+ r'\.\d*|[eE][+\-]?\d+)', Number.Float),
1766
+ (r'\.\d+([eE][+\-]?\d+)?', Number.Float),
1767
+ # int_lit
1768
+ # -- octal_lit
1769
+ (r'0[0-7]+', Number.Oct),
1770
+ # -- hex_lit
1771
+ (r'0[xX][0-9a-fA-F]+', Number.Hex),
1772
+ # -- decimal_lit
1773
+ (r'(0|[1-9][0-9]*)', Number.Integer),
1774
+ # char_lit
1775
+ (r"""'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
1776
+ r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'""",
1777
+ String.Char
1778
+ ),
1779
+ # StringLiteral
1780
+ # -- raw_string_lit
1781
+ (r'`[^`]*`', String),
1782
+ # -- interpreted_string_lit
1783
+ (r'"(\\\\|\\"|[^"])*"', String),
1784
+ # Tokens
1785
+ (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|'
1786
+ r'|<-|\+\+|--|==|!=|:=|\.\.\.)|[+\-*/%&|^<>=!()\[\]{}.,;:]',
1787
+ Punctuation
1788
+ ),
1789
+ # identifier
1790
+ (r'[a-zA-Z_]\w*', Name),
1791
+ ]
1792
+ }
1793
+
1794
+
1795
+ class FelixLexer(RegexLexer):
1796
+ """
1797
+ For `Felix <http://www.felix-lang.org>`_ source code.
1798
+
1799
+ *New in Pygments 1.2.*
1800
+ """
1801
+
1802
+ name = 'Felix'
1803
+ aliases = ['felix', 'flx']
1804
+ filenames = ['*.flx', '*.flxh']
1805
+ mimetypes = ['text/x-felix']
1806
+
1807
+ preproc = [
1808
+ 'elif', 'else', 'endif', 'if', 'ifdef', 'ifndef',
1809
+ ]
1810
+
1811
+ keywords = [
1812
+ '_', '_deref', 'all', 'as',
1813
+ 'assert', 'attempt', 'call', 'callback', 'case', 'caseno', 'cclass',
1814
+ 'code', 'compound', 'ctypes', 'do', 'done', 'downto', 'elif', 'else',
1815
+ 'endattempt', 'endcase', 'endif', 'endmatch', 'enum', 'except',
1816
+ 'exceptions', 'expect', 'finally', 'for', 'forall', 'forget', 'fork',
1817
+ 'functor', 'goto', 'ident', 'if', 'incomplete', 'inherit', 'instance',
1818
+ 'interface', 'jump', 'lambda', 'loop', 'match', 'module', 'namespace',
1819
+ 'new', 'noexpand', 'nonterm', 'obj', 'of', 'open', 'parse', 'raise',
1820
+ 'regexp', 'reglex', 'regmatch', 'rename', 'return', 'the', 'then',
1821
+ 'to', 'type', 'typecase', 'typedef', 'typematch', 'typeof', 'upto',
1822
+ 'when', 'whilst', 'with', 'yield',
1823
+ ]
1824
+
1825
+ keyword_directives = [
1826
+ '_gc_pointer', '_gc_type', 'body', 'comment', 'const', 'export',
1827
+ 'header', 'inline', 'lval', 'macro', 'noinline', 'noreturn',
1828
+ 'package', 'private', 'pod', 'property', 'public', 'publish',
1829
+ 'requires', 'todo', 'virtual', 'use',
1830
+ ]
1831
+
1832
+ keyword_declarations = [
1833
+ 'def', 'let', 'ref', 'val', 'var',
1834
+ ]
1835
+
1836
+ keyword_types = [
1837
+ 'unit', 'void', 'any', 'bool',
1838
+ 'byte', 'offset',
1839
+ 'address', 'caddress', 'cvaddress', 'vaddress',
1840
+ 'tiny', 'short', 'int', 'long', 'vlong',
1841
+ 'utiny', 'ushort', 'vshort', 'uint', 'ulong', 'uvlong',
1842
+ 'int8', 'int16', 'int32', 'int64',
1843
+ 'uint8', 'uint16', 'uint32', 'uint64',
1844
+ 'float', 'double', 'ldouble',
1845
+ 'complex', 'dcomplex', 'lcomplex',
1846
+ 'imaginary', 'dimaginary', 'limaginary',
1847
+ 'char', 'wchar', 'uchar',
1848
+ 'charp', 'charcp', 'ucharp', 'ucharcp',
1849
+ 'string', 'wstring', 'ustring',
1850
+ 'cont',
1851
+ 'array', 'varray', 'list',
1852
+ 'lvalue', 'opt', 'slice',
1853
+ ]
1854
+
1855
+ keyword_constants = [
1856
+ 'false', 'true',
1857
+ ]
1858
+
1859
+ operator_words = [
1860
+ 'and', 'not', 'in', 'is', 'isin', 'or', 'xor',
1861
+ ]
1862
+
1863
+ name_builtins = [
1864
+ '_svc', 'while',
1865
+ ]
1866
+
1867
+ name_pseudo = [
1868
+ 'root', 'self', 'this',
1869
+ ]
1870
+
1871
+ decimal_suffixes = '([tTsSiIlLvV]|ll|LL|([iIuU])(8|16|32|64))?'
1872
+
1873
+ tokens = {
1874
+ 'root': [
1875
+ include('whitespace'),
1876
+
1877
+ # Keywords
1878
+ (r'(axiom|ctor|fun|gen|proc|reduce|union)\b', Keyword,
1879
+ 'funcname'),
1880
+ (r'(class|cclass|cstruct|obj|struct)\b', Keyword, 'classname'),
1881
+ (r'(instance|module|typeclass)\b', Keyword, 'modulename'),
1882
+
1883
+ (r'(%s)\b' % '|'.join(keywords), Keyword),
1884
+ (r'(%s)\b' % '|'.join(keyword_directives), Name.Decorator),
1885
+ (r'(%s)\b' % '|'.join(keyword_declarations), Keyword.Declaration),
1886
+ (r'(%s)\b' % '|'.join(keyword_types), Keyword.Type),
1887
+ (r'(%s)\b' % '|'.join(keyword_constants), Keyword.Constant),
1888
+
1889
+ # Operators
1890
+ include('operators'),
1891
+
1892
+ # Float Literal
1893
+ # -- Hex Float
1894
+ (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
1895
+ r'[pP][+\-]?[0-9_]+[lLfFdD]?', Number.Float),
1896
+ # -- DecimalFloat
1897
+ (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
1898
+ r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[lLfFdD]?', Number.Float),
1899
+ (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[lLfFdD]?',
1900
+ Number.Float),
1901
+
1902
+ # IntegerLiteral
1903
+ # -- Binary
1904
+ (r'0[Bb][01_]+%s' % decimal_suffixes, Number),
1905
+ # -- Octal
1906
+ (r'0[0-7_]+%s' % decimal_suffixes, Number.Oct),
1907
+ # -- Hexadecimal
1908
+ (r'0[xX][0-9a-fA-F_]+%s' % decimal_suffixes, Number.Hex),
1909
+ # -- Decimal
1910
+ (r'(0|[1-9][0-9_]*)%s' % decimal_suffixes, Number.Integer),
1911
+
1912
+ # Strings
1913
+ ('([rR][cC]?|[cC][rR])"""', String, 'tdqs'),
1914
+ ("([rR][cC]?|[cC][rR])'''", String, 'tsqs'),
1915
+ ('([rR][cC]?|[cC][rR])"', String, 'dqs'),
1916
+ ("([rR][cC]?|[cC][rR])'", String, 'sqs'),
1917
+ ('[cCfFqQwWuU]?"""', String, combined('stringescape', 'tdqs')),
1918
+ ("[cCfFqQwWuU]?'''", String, combined('stringescape', 'tsqs')),
1919
+ ('[cCfFqQwWuU]?"', String, combined('stringescape', 'dqs')),
1920
+ ("[cCfFqQwWuU]?'", String, combined('stringescape', 'sqs')),
1921
+
1922
+ # Punctuation
1923
+ (r'[\[\]{}:(),;?]', Punctuation),
1924
+
1925
+ # Labels
1926
+ (r'[a-zA-Z_]\w*:>', Name.Label),
1927
+
1928
+ # Identifiers
1929
+ (r'(%s)\b' % '|'.join(name_builtins), Name.Builtin),
1930
+ (r'(%s)\b' % '|'.join(name_pseudo), Name.Builtin.Pseudo),
1931
+ (r'[a-zA-Z_]\w*', Name),
1932
+ ],
1933
+ 'whitespace': [
1934
+ (r'\n', Text),
1935
+ (r'\s+', Text),
1936
+
1937
+ include('comment'),
1938
+
1939
+ # Preprocessor
1940
+ (r'#\s*if\s+0', Comment.Preproc, 'if0'),
1941
+ (r'#', Comment.Preproc, 'macro'),
1942
+ ],
1943
+ 'operators': [
1944
+ (r'(%s)\b' % '|'.join(operator_words), Operator.Word),
1945
+ (r'!=|==|<<|>>|\|\||&&|[-~+/*%=<>&^|.$]', Operator),
1946
+ ],
1947
+ 'comment': [
1948
+ (r'//(.*?)\n', Comment.Single),
1949
+ (r'/[*]', Comment.Multiline, 'comment2'),
1950
+ ],
1951
+ 'comment2': [
1952
+ (r'[^\/*]', Comment.Multiline),
1953
+ (r'/[*]', Comment.Multiline, '#push'),
1954
+ (r'[*]/', Comment.Multiline, '#pop'),
1955
+ (r'[\/*]', Comment.Multiline),
1956
+ ],
1957
+ 'if0': [
1958
+ (r'^\s*#if.*?(?<!\\)\n', Comment, '#push'),
1959
+ (r'^\s*#endif.*?(?<!\\)\n', Comment, '#pop'),
1960
+ (r'.*?\n', Comment),
1961
+ ],
1962
+ 'macro': [
1963
+ include('comment'),
1964
+ (r'(import|include)(\s+)(<[^>]*?>)',
1965
+ bygroups(Comment.Preproc, Text, String), '#pop'),
1966
+ (r'(import|include)(\s+)("[^"]*?")',
1967
+ bygroups(Comment.Preproc, Text, String), '#pop'),
1968
+ (r"(import|include)(\s+)('[^']*?')",
1969
+ bygroups(Comment.Preproc, Text, String), '#pop'),
1970
+ (r'[^/\n]+', Comment.Preproc),
1971
+ ##(r'/[*](.|\n)*?[*]/', Comment),
1972
+ ##(r'//.*?\n', Comment, '#pop'),
1973
+ (r'/', Comment.Preproc),
1974
+ (r'(?<=\\)\n', Comment.Preproc),
1975
+ (r'\n', Comment.Preproc, '#pop'),
1976
+ ],
1977
+ 'funcname': [
1978
+ include('whitespace'),
1979
+ (r'[a-zA-Z_]\w*', Name.Function, '#pop'),
1980
+ # anonymous functions
1981
+ (r'(?=\()', Text, '#pop'),
1982
+ ],
1983
+ 'classname': [
1984
+ include('whitespace'),
1985
+ (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
1986
+ # anonymous classes
1987
+ (r'(?=\{)', Text, '#pop'),
1988
+ ],
1989
+ 'modulename': [
1990
+ include('whitespace'),
1991
+ (r'\[', Punctuation, ('modulename2', 'tvarlist')),
1992
+ (r'', Error, 'modulename2'),
1993
+ ],
1994
+ 'modulename2': [
1995
+ include('whitespace'),
1996
+ (r'([a-zA-Z_]\w*)', Name.Namespace, '#pop:2'),
1997
+ ],
1998
+ 'tvarlist': [
1999
+ include('whitespace'),
2000
+ include('operators'),
2001
+ (r'\[', Punctuation, '#push'),
2002
+ (r'\]', Punctuation, '#pop'),
2003
+ (r',', Punctuation),
2004
+ (r'(with|where)\b', Keyword),
2005
+ (r'[a-zA-Z_]\w*', Name),
2006
+ ],
2007
+ 'stringescape': [
2008
+ (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
2009
+ r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
2010
+ ],
2011
+ 'strings': [
2012
+ (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
2013
+ '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
2014
+ (r'[^\\\'"%\n]+', String),
2015
+ # quotes, percents and backslashes must be parsed one at a time
2016
+ (r'[\'"\\]', String),
2017
+ # unhandled string formatting sign
2018
+ (r'%', String)
2019
+ # newlines are an error (use "nl" state)
2020
+ ],
2021
+ 'nl': [
2022
+ (r'\n', String)
2023
+ ],
2024
+ 'dqs': [
2025
+ (r'"', String, '#pop'),
2026
+ # included here again for raw strings
2027
+ (r'\\\\|\\"|\\\n', String.Escape),
2028
+ include('strings')
2029
+ ],
2030
+ 'sqs': [
2031
+ (r"'", String, '#pop'),
2032
+ # included here again for raw strings
2033
+ (r"\\\\|\\'|\\\n", String.Escape),
2034
+ include('strings')
2035
+ ],
2036
+ 'tdqs': [
2037
+ (r'"""', String, '#pop'),
2038
+ include('strings'),
2039
+ include('nl')
2040
+ ],
2041
+ 'tsqs': [
2042
+ (r"'''", String, '#pop'),
2043
+ include('strings'),
2044
+ include('nl')
2045
+ ],
2046
+ }
2047
+
2048
+
2049
+ class AdaLexer(RegexLexer):
2050
+ """
2051
+ For Ada source code.
2052
+
2053
+ *New in Pygments 1.3.*
2054
+ """
2055
+
2056
+ name = 'Ada'
2057
+ aliases = ['ada', 'ada95' 'ada2005']
2058
+ filenames = ['*.adb', '*.ads', '*.ada']
2059
+ mimetypes = ['text/x-ada']
2060
+
2061
+ flags = re.MULTILINE | re.I # Ignore case
2062
+
2063
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
2064
+
2065
+ tokens = {
2066
+ 'root': [
2067
+ (r'[^\S\n]+', Text),
2068
+ (r'--.*?\n', Comment.Single),
2069
+ (r'[^\S\n]+', Text),
2070
+ (r'function|procedure|entry', Keyword.Declaration, 'subprogram'),
2071
+ (r'(subtype|type)(\s+)([a-z0-9_]+)',
2072
+ bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'),
2073
+ (r'task|protected', Keyword.Declaration),
2074
+ (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)),
2075
+ (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'),
2076
+ (r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text,
2077
+ Comment.Preproc)),
2078
+ (r'(true|false|null)\b', Keyword.Constant),
2079
+ (r'(Byte|Character|Float|Integer|Long_Float|Long_Integer|'
2080
+ r'Long_Long_Float|Long_Long_Integer|Natural|Positive|Short_Float|'
2081
+ r'Short_Integer|Short_Short_Float|Short_Short_Integer|String|'
2082
+ r'Wide_String|Duration)\b', Keyword.Type),
2083
+ (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word),
2084
+ (r'generic|private', Keyword.Declaration),
2085
+ (r'package', Keyword.Declaration, 'package'),
2086
+ (r'array\b', Keyword.Reserved, 'array_def'),
2087
+ (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
2088
+ (r'([a-z0-9_]+)(\s*)(:)(\s*)(constant)',
2089
+ bygroups(Name.Constant, Text, Punctuation, Text,
2090
+ Keyword.Reserved)),
2091
+ (r'<<[a-z0-9_]+>>', Name.Label),
2092
+ (r'([a-z0-9_]+)(\s*)(:)(\s*)(declare|begin|loop|for|while)',
2093
+ bygroups(Name.Label, Text, Punctuation, Text, Keyword.Reserved)),
2094
+ (r'\b(abort|abs|abstract|accept|access|aliased|all|array|at|begin|'
2095
+ r'body|case|constant|declare|delay|delta|digits|do|else|elsif|end|'
2096
+ r'entry|exception|exit|interface|for|goto|if|is|limited|loop|new|'
2097
+ r'null|of|or|others|out|overriding|pragma|protected|raise|range|'
2098
+ r'record|renames|requeue|return|reverse|select|separate|subtype|'
2099
+ r'synchronized|task|tagged|terminate|then|type|until|when|while|'
2100
+ r'xor)\b',
2101
+ Keyword.Reserved),
2102
+ (r'"[^"]*"', String),
2103
+ include('attribute'),
2104
+ include('numbers'),
2105
+ (r"'[^']'", String.Character),
2106
+ (r'([a-z0-9_]+)(\s*|[(,])', bygroups(Name, using(this))),
2107
+ (r"(<>|=>|:=|[\(\)\|:;,.'])", Punctuation),
2108
+ (r'[*<>+=/&-]', Operator),
2109
+ (r'\n+', Text),
2110
+ ],
2111
+ 'numbers' : [
2112
+ (r'[0-9_]+#[0-9a-f]+#', Number.Hex),
2113
+ (r'[0-9_]+\.[0-9_]*', Number.Float),
2114
+ (r'[0-9_]+', Number.Integer),
2115
+ ],
2116
+ 'attribute' : [
2117
+ (r"(')([a-zA-Z0-9_]+)", bygroups(Punctuation, Name.Attribute)),
2118
+ ],
2119
+ 'subprogram' : [
2120
+ (r'\(', Punctuation, ('#pop', 'formal_part')),
2121
+ (r';', Punctuation, '#pop'),
2122
+ (r'is\b', Keyword.Reserved, '#pop'),
2123
+ (r'"[^"]+"|[a-z0-9_]+', Name.Function),
2124
+ include('root'),
2125
+ ],
2126
+ 'end' : [
2127
+ ('(if|case|record|loop|select)', Keyword.Reserved),
2128
+ ('"[^"]+"|[a-zA-Z0-9_]+', Name.Function),
2129
+ ('[\n\s]+', Text),
2130
+ (';', Punctuation, '#pop'),
2131
+ ],
2132
+ 'type_def': [
2133
+ (r';', Punctuation, '#pop'),
2134
+ (r'\(', Punctuation, 'formal_part'),
2135
+ (r'with|and|use', Keyword.Reserved),
2136
+ (r'array\b', Keyword.Reserved, ('#pop', 'array_def')),
2137
+ (r'record\b', Keyword.Reserved, ('formal_part')),
2138
+ include('root'),
2139
+ ],
2140
+ 'array_def' : [
2141
+ (r';', Punctuation, '#pop'),
2142
+ (r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text,
2143
+ Keyword.Reserved)),
2144
+ include('root'),
2145
+ ],
2146
+ 'import': [
2147
+ (r'[a-z0-9_.]+', Name.Namespace, '#pop'),
2148
+ ],
2149
+ 'formal_part' : [
2150
+ (r'\)', Punctuation, '#pop'),
2151
+ (r'([a-z0-9_]+)(\s*)(,|:[^=])', bygroups(Name.Variable,
2152
+ Text, Punctuation)),
2153
+ (r'(in|not|null|out|access)\b', Keyword.Reserved),
2154
+ include('root'),
2155
+ ],
2156
+ 'package': [
2157
+ ('body', Keyword.Declaration),
2158
+ ('is\s+new|renames', Keyword.Reserved),
2159
+ ('is', Keyword.Reserved, '#pop'),
2160
+ (';', Punctuation, '#pop'),
2161
+ ('\(', Punctuation, 'package_instantiation'),
2162
+ ('([a-zA-Z0-9_.]+)', Name.Class),
2163
+ include('root'),
2164
+ ],
2165
+ 'package_instantiation': [
2166
+ (r'("[^"]+"|[a-z0-9_]+)(\s+)(=>)', bygroups(Name.Variable,
2167
+ Text, Punctuation)),
2168
+ (r'[a-z0-9._\'"]', Text),
2169
+ (r'\)', Punctuation, '#pop'),
2170
+ include('root'),
2171
+ ],
2172
+ }
2173
+
2174
+
2175
+ class Modula2Lexer(RegexLexer):
2176
+ """
2177
+ For `Modula-2 <http://www.modula2.org/>`_ source code.
2178
+
2179
+ Additional options that determine which keywords are highlighted:
2180
+
2181
+ `pim`
2182
+ Select PIM Modula-2 dialect (default: True).
2183
+ `iso`
2184
+ Select ISO Modula-2 dialect (default: False).
2185
+ `objm2`
2186
+ Select Objective Modula-2 dialect (default: False).
2187
+ `gm2ext`
2188
+ Also highlight GNU extensions (default: False).
2189
+
2190
+ *New in Pygments 1.3.*
2191
+ """
2192
+ name = 'Modula-2'
2193
+ aliases = ['modula2', 'm2']
2194
+ filenames = ['*.def', '*.mod']
2195
+ mimetypes = ['text/x-modula2']
2196
+
2197
+ flags = re.MULTILINE | re.DOTALL
2198
+
2199
+ tokens = {
2200
+ 'whitespace': [
2201
+ (r'\n+', Text), # blank lines
2202
+ (r'\s+', Text), # whitespace
2203
+ ],
2204
+ 'identifiers': [
2205
+ (r'([a-zA-Z_\$][a-zA-Z0-9_\$]*)', Name),
2206
+ ],
2207
+ 'numliterals': [
2208
+ (r'[01]+B', Number.Binary), # binary number (ObjM2)
2209
+ (r'[0-7]+B', Number.Oct), # octal number (PIM + ISO)
2210
+ (r'[0-7]+C', Number.Oct), # char code (PIM + ISO)
2211
+ (r'[0-9A-F]+C', Number.Hex), # char code (ObjM2)
2212
+ (r'[0-9A-F]+H', Number.Hex), # hexadecimal number
2213
+ (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number
2214
+ (r'[0-9]+\.[0-9]+', Number.Float), # real number
2215
+ (r'[0-9]+', Number.Integer), # decimal whole number
2216
+ ],
2217
+ 'strings': [
2218
+ (r"'(\\\\|\\'|[^'])*'", String), # single quoted string
2219
+ (r'"(\\\\|\\"|[^"])*"', String), # double quoted string
2220
+ ],
2221
+ 'operators': [
2222
+ (r'[*/+=#~&<>\^-]', Operator),
2223
+ (r':=', Operator), # assignment
2224
+ (r'@', Operator), # pointer deref (ISO)
2225
+ (r'\.\.', Operator), # ellipsis or range
2226
+ (r'`', Operator), # Smalltalk message (ObjM2)
2227
+ (r'::', Operator), # type conversion (ObjM2)
2228
+ ],
2229
+ 'punctuation': [
2230
+ (r'[\(\)\[\]{},.:;|]', Punctuation),
2231
+ ],
2232
+ 'comments': [
2233
+ (r'//.*?\n', Comment.Single), # ObjM2
2234
+ (r'/\*(.*?)\*/', Comment.Multiline), # ObjM2
2235
+ (r'\(\*([^\$].*?)\*\)', Comment.Multiline),
2236
+ # TO DO: nesting of (* ... *) comments
2237
+ ],
2238
+ 'pragmas': [
2239
+ (r'\(\*\$(.*?)\*\)', Comment.Preproc), # PIM
2240
+ (r'<\*(.*?)\*>', Comment.Preproc), # ISO + ObjM2
2241
+ ],
2242
+ 'root': [
2243
+ include('whitespace'),
2244
+ include('comments'),
2245
+ include('pragmas'),
2246
+ include('identifiers'),
2247
+ include('numliterals'),
2248
+ include('strings'),
2249
+ include('operators'),
2250
+ include('punctuation'),
2251
+ ]
2252
+ }
2253
+
2254
+ pim_reserved_words = [
2255
+ # 40 reserved words
2256
+ 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION',
2257
+ 'DIV', 'DO', 'ELSE', 'ELSIF', 'END', 'EXIT', 'EXPORT', 'FOR',
2258
+ 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN', 'LOOP', 'MOD',
2259
+ 'MODULE', 'NOT', 'OF', 'OR', 'POINTER', 'PROCEDURE', 'QUALIFIED',
2260
+ 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE',
2261
+ 'UNTIL', 'VAR', 'WHILE', 'WITH',
2262
+ ]
2263
+
2264
+ pim_pervasives = [
2265
+ # 31 pervasives
2266
+ 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'DEC',
2267
+ 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH', 'INC', 'INCL',
2268
+ 'INTEGER', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW', 'NIL', 'ODD',
2269
+ 'ORD', 'PROC', 'REAL', 'SIZE', 'TRUE', 'TRUNC', 'VAL',
2270
+ ]
2271
+
2272
+ iso_reserved_words = [
2273
+ # 46 reserved words
2274
+ 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV',
2275
+ 'DO', 'ELSE', 'ELSIF', 'END', 'EXCEPT', 'EXIT', 'EXPORT', 'FINALLY',
2276
+ 'FOR', 'FORWARD', 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN',
2277
+ 'LOOP', 'MOD', 'MODULE', 'NOT', 'OF', 'OR', 'PACKEDSET', 'POINTER',
2278
+ 'PROCEDURE', 'QUALIFIED', 'RECORD', 'REPEAT', 'REM', 'RETRY',
2279
+ 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', 'UNTIL', 'VAR', 'WHILE',
2280
+ 'WITH',
2281
+ ]
2282
+
2283
+ iso_pervasives = [
2284
+ # 42 pervasives
2285
+ 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'CMPLX',
2286
+ 'COMPLEX', 'DEC', 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH',
2287
+ 'IM', 'INC', 'INCL', 'INT', 'INTEGER', 'INTERRUPTIBLE', 'LENGTH',
2288
+ 'LFLOAT', 'LONGCOMPLEX', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW',
2289
+ 'NIL', 'ODD', 'ORD', 'PROC', 'PROTECTION', 'RE', 'REAL', 'SIZE',
2290
+ 'TRUE', 'TRUNC', 'UNINTERRUBTIBLE', 'VAL',
2291
+ ]
2292
+
2293
+ objm2_reserved_words = [
2294
+ # base language, 42 reserved words
2295
+ 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV',
2296
+ 'DO', 'ELSE', 'ELSIF', 'END', 'ENUM', 'EXIT', 'FOR', 'FROM', 'IF',
2297
+ 'IMMUTABLE', 'IMPLEMENTATION', 'IMPORT', 'IN', 'IS', 'LOOP', 'MOD',
2298
+ 'MODULE', 'NOT', 'OF', 'OPAQUE', 'OR', 'POINTER', 'PROCEDURE',
2299
+ 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE',
2300
+ 'UNTIL', 'VAR', 'VARIADIC', 'WHILE',
2301
+ # OO extensions, 16 reserved words
2302
+ 'BYCOPY', 'BYREF', 'CLASS', 'CONTINUE', 'CRITICAL', 'INOUT', 'METHOD',
2303
+ 'ON', 'OPTIONAL', 'OUT', 'PRIVATE', 'PROTECTED', 'PROTOCOL', 'PUBLIC',
2304
+ 'SUPER', 'TRY',
2305
+ ]
2306
+
2307
+ objm2_pervasives = [
2308
+ # base language, 38 pervasives
2309
+ 'ABS', 'BITSET', 'BOOLEAN', 'CARDINAL', 'CHAR', 'CHR', 'DISPOSE',
2310
+ 'FALSE', 'HALT', 'HIGH', 'INTEGER', 'INRANGE', 'LENGTH', 'LONGCARD',
2311
+ 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEG', 'NEW', 'NEXTV', 'NIL',
2312
+ 'OCTET', 'ODD', 'ORD', 'PRED', 'PROC', 'READ', 'REAL', 'SUCC', 'TMAX',
2313
+ 'TMIN', 'TRUE', 'TSIZE', 'UNICHAR', 'VAL', 'WRITE', 'WRITEF',
2314
+ # OO extensions, 3 pervasives
2315
+ 'OBJECT', 'NO', 'YES',
2316
+ ]
2317
+
2318
+ gnu_reserved_words = [
2319
+ # 10 additional reserved words
2320
+ 'ASM', '__ATTRIBUTE__', '__BUILTIN__', '__COLUMN__', '__DATE__',
2321
+ '__FILE__', '__FUNCTION__', '__LINE__', '__MODULE__', 'VOLATILE',
2322
+ ]
2323
+
2324
+ gnu_pervasives = [
2325
+ # 21 identifiers, actually from pseudo-module SYSTEM
2326
+ # but we will highlight them as if they were pervasives
2327
+ 'BITSET8', 'BITSET16', 'BITSET32', 'CARDINAL8', 'CARDINAL16',
2328
+ 'CARDINAL32', 'CARDINAL64', 'COMPLEX32', 'COMPLEX64', 'COMPLEX96',
2329
+ 'COMPLEX128', 'INTEGER8', 'INTEGER16', 'INTEGER32', 'INTEGER64',
2330
+ 'REAL8', 'REAL16', 'REAL32', 'REAL96', 'REAL128', 'THROW',
2331
+ ]
2332
+
2333
+ def __init__(self, **options):
2334
+ self.reserved_words = set()
2335
+ self.pervasives = set()
2336
+ # ISO Modula-2
2337
+ if get_bool_opt(options, 'iso', False):
2338
+ self.reserved_words.update(self.iso_reserved_words)
2339
+ self.pervasives.update(self.iso_pervasives)
2340
+ # Objective Modula-2
2341
+ elif get_bool_opt(options, 'objm2', False):
2342
+ self.reserved_words.update(self.objm2_reserved_words)
2343
+ self.pervasives.update(self.objm2_pervasives)
2344
+ # PIM Modula-2 (DEFAULT)
2345
+ else:
2346
+ self.reserved_words.update(self.pim_reserved_words)
2347
+ self.pervasives.update(self.pim_pervasives)
2348
+ # GNU extensions
2349
+ if get_bool_opt(options, 'gm2ext', False):
2350
+ self.reserved_words.update(self.gnu_reserved_words)
2351
+ self.pervasives.update(self.gnu_pervasives)
2352
+ # initialise
2353
+ RegexLexer.__init__(self, **options)
2354
+
2355
+ def get_tokens_unprocessed(self, text):
2356
+ for index, token, value in \
2357
+ RegexLexer.get_tokens_unprocessed(self, text):
2358
+ # check for reserved words and pervasives
2359
+ if token is Name:
2360
+ if value in self.reserved_words:
2361
+ token = Keyword.Reserved
2362
+ elif value in self.pervasives:
2363
+ token = Keyword.Pervasive
2364
+ # return result
2365
+ yield index, token, value