ThirdParty/Pygments/pygments/lexers/dotnet.py

changeset 4172
4f20dba37ab6
parent 3145
a9de05d4a22f
child 4697
c2e9bf425554
equal deleted inserted replaced
4170:8bc578136279 4172:4f20dba37ab6
3 pygments.lexers.dotnet 3 pygments.lexers.dotnet
4 ~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for .net languages. 6 Lexers for .net languages.
7 7
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 from __future__ import unicode_literals
12
13 import re 11 import re
14 12
15 from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, include, \ 13 from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, include, \
16 using, this 14 using, this, default
17 from pygments.token import Punctuation, \ 15 from pygments.token import Punctuation, \
18 Text, Comment, Operator, Keyword, Name, String, Number, Literal, Other 16 Text, Comment, Operator, Keyword, Name, String, Number, Literal, Other
19 from pygments.util import get_choice_opt 17 from pygments.util import get_choice_opt, iteritems
20 from pygments import unistring as uni 18 from pygments import unistring as uni
21 19
22 from pygments.lexers.web import XmlLexer 20 from pygments.lexers.html import XmlLexer
23 21
24 __all__ = ['CSharpLexer', 'NemerleLexer', 'BooLexer', 'VbNetLexer', 22 __all__ = ['CSharpLexer', 'NemerleLexer', 'BooLexer', 'VbNetLexer',
25 'CSharpAspxLexer', 'VbNetAspxLexer', 'FSharpLexer'] 23 'CSharpAspxLexer', 'VbNetAspxLexer', 'FSharpLexer']
26 24
27 25
44 are allowed. Note that this means a considerable slowdown since the 42 are allowed. Note that this means a considerable slowdown since the
45 ``Lo`` category has more than 40,000 characters in it! 43 ``Lo`` category has more than 40,000 characters in it!
46 44
47 The default value is ``basic``. 45 The default value is ``basic``.
48 46
49 *New in Pygments 0.8.* 47 .. versionadded:: 0.8
50 """ 48 """
51 49
52 name = 'C#' 50 name = 'C#'
53 aliases = ['csharp', 'c#'] 51 aliases = ['csharp', 'c#']
54 filenames = ['*.cs'] 52 filenames = ['*.cs']
55 mimetypes = ['text/x-csharp'] # inferred 53 mimetypes = ['text/x-csharp'] # inferred
56 54
57 flags = re.MULTILINE | re.DOTALL | re.UNICODE 55 flags = re.MULTILINE | re.DOTALL | re.UNICODE
58 56
59 # for the range of allowed unicode characters in identifiers, 57 # for the range of allowed unicode characters in identifiers, see
60 # see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf 58 # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf
61 59
62 levels = { 60 levels = {
63 'none': '@?[_a-zA-Z][a-zA-Z0-9_]*', 61 'none': '@?[_a-zA-Z]\w*',
64 'basic': ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + 62 'basic': ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +
65 '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + 63 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc',
66 uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), 64 'Cf', 'Mn', 'Mc') + ']*'),
67 'full': ('@?(?:_|[^' + 65 'full': ('@?(?:_|[^' +
68 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' 66 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])'
69 + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 67 + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',
70 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'), 68 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'),
71 } 69 }
72 70
73 tokens = {} 71 tokens = {}
74 token_variants = True 72 token_variants = True
75 73
76 for levelname, cs_ident in list(levels.items()): 74 for levelname, cs_ident in iteritems(levels):
77 tokens[levelname] = { 75 tokens[levelname] = {
78 'root': [ 76 'root': [
79 # method names 77 # method names
80 (r'^([ \t]*(?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type 78 (r'^([ \t]*(?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type
81 r'(' + cs_ident + ')' # method name 79 r'(' + cs_ident + ')' # method name
82 r'(\s*)(\()', # signature start 80 r'(\s*)(\()', # signature start
83 bygroups(using(this), Name.Function, Text, Punctuation)), 81 bygroups(using(this), Name.Function, Text, Punctuation)),
84 (r'^\s*\[.*?\]', Name.Attribute), 82 (r'^\s*\[.*?\]', Name.Attribute),
85 (r'[^\S\n]+', Text), 83 (r'[^\S\n]+', Text),
86 (r'\\\n', Text), # line continuation 84 (r'\\\n', Text), # line continuation
87 (r'//.*?\n', Comment.Single), 85 (r'//.*?\n', Comment.Single),
88 (r'/[*].*?[*]/', Comment.Multiline), 86 (r'/[*].*?[*]/', Comment.Multiline),
89 (r'\n', Text), 87 (r'\n', Text),
90 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation), 88 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation),
91 (r'[{}]', Punctuation), 89 (r'[{}]', Punctuation),
117 (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'class'), 115 (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'class'),
118 (r'(namespace|using)(\s+)', bygroups(Keyword, Text), 'namespace'), 116 (r'(namespace|using)(\s+)', bygroups(Keyword, Text), 'namespace'),
119 (cs_ident, Name), 117 (cs_ident, Name),
120 ], 118 ],
121 'class': [ 119 'class': [
122 (cs_ident, Name.Class, '#pop') 120 (cs_ident, Name.Class, '#pop'),
121 default('#pop'),
123 ], 122 ],
124 'namespace': [ 123 'namespace': [
125 (r'(?=\()', Text, '#pop'), # using (resource) 124 (r'(?=\()', Text, '#pop'), # using (resource)
126 ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop') 125 ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop'),
127 ] 126 ]
128 } 127 }
129 128
130 def __init__(self, **options): 129 def __init__(self, **options):
131 level = get_choice_opt(options, 'unicodelevel', list(self.tokens.keys()), 'basic') 130 level = get_choice_opt(options, 'unicodelevel', list(self.tokens), 'basic')
132 if level not in self._all_tokens: 131 if level not in self._all_tokens:
133 # compile the regexes now 132 # compile the regexes now
134 self._tokens = self.__class__.process_tokendef(level) 133 self._tokens = self.__class__.process_tokendef(level)
135 else: 134 else:
136 self._tokens = self._all_tokens[level] 135 self._tokens = self._all_tokens[level]
156 are allowed. Note that this means a considerable slowdown since the 155 are allowed. Note that this means a considerable slowdown since the
157 ``Lo`` category has more than 40,000 characters in it! 156 ``Lo`` category has more than 40,000 characters in it!
158 157
159 The default value is ``basic``. 158 The default value is ``basic``.
160 159
161 *New in Pygments 1.5.* 160 .. versionadded:: 1.5
162 """ 161 """
163 162
164 name = 'Nemerle' 163 name = 'Nemerle'
165 aliases = ['nemerle'] 164 aliases = ['nemerle']
166 filenames = ['*.n'] 165 filenames = ['*.n']
167 mimetypes = ['text/x-nemerle'] # inferred 166 mimetypes = ['text/x-nemerle'] # inferred
168 167
169 flags = re.MULTILINE | re.DOTALL | re.UNICODE 168 flags = re.MULTILINE | re.DOTALL | re.UNICODE
170 169
171 # for the range of allowed unicode characters in identifiers, see 170 # for the range of allowed unicode characters in identifiers, see
172 # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf 171 # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf
173 172
174 levels = dict( 173 levels = {
175 none = '@?[_a-zA-Z][a-zA-Z0-9_]*', 174 'none': '@?[_a-zA-Z]\w*',
176 basic = ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + 175 'basic': ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +
177 '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + 176 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc',
178 uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), 177 'Cf', 'Mn', 'Mc') + ']*'),
179 full = ('@?(?:_|[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 178 'full': ('@?(?:_|[^' +
180 'Nl') + '])' 179 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])'
181 + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 180 + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',
182 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'), 181 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'),
183 ) 182 }
184 183
185 tokens = {} 184 tokens = {}
186 token_variants = True 185 token_variants = True
187 186
188 for levelname, cs_ident in list(levels.items()): 187 for levelname, cs_ident in iteritems(levels):
189 tokens[levelname] = { 188 tokens[levelname] = {
190 'root': [ 189 'root': [
191 # method names 190 # method names
192 (r'^([ \t]*(?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type 191 (r'^([ \t]*(?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type
193 r'(' + cs_ident + ')' # method name 192 r'(' + cs_ident + ')' # method name
194 r'(\s*)(\()', # signature start 193 r'(\s*)(\()', # signature start
195 bygroups(using(this), Name.Function, Text, Punctuation)), 194 bygroups(using(this), Name.Function, Text, Punctuation)),
196 (r'^\s*\[.*?\]', Name.Attribute), 195 (r'^\s*\[.*?\]', Name.Attribute),
197 (r'[^\S\n]+', Text), 196 (r'[^\S\n]+', Text),
198 (r'\\\n', Text), # line continuation 197 (r'\\\n', Text), # line continuation
199 (r'//.*?\n', Comment.Single), 198 (r'//.*?\n', Comment.Single),
200 (r'/[*].*?[*]/', Comment.Multiline), 199 (r'/[*].*?[*]/', Comment.Multiline),
201 (r'\n', Text), 200 (r'\n', Text),
202 (r'\$\s*"', String, 'splice-string'), 201 (r'\$\s*"', String, 'splice-string'),
203 (r'\$\s*<#', String, 'splice-string2'), 202 (r'\$\s*<#', String, 'splice-string2'),
249 ], 248 ],
250 'class': [ 249 'class': [
251 (cs_ident, Name.Class, '#pop') 250 (cs_ident, Name.Class, '#pop')
252 ], 251 ],
253 'namespace': [ 252 'namespace': [
254 (r'(?=\()', Text, '#pop'), # using (resource) 253 (r'(?=\()', Text, '#pop'), # using (resource)
255 ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop') 254 ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop')
256 ], 255 ],
257 'splice-string': [ 256 'splice-string': [
258 (r'[^"$]', String), 257 (r'[^"$]', String),
259 (r'\$' + cs_ident, Name), 258 (r'\$' + cs_ident, Name),
284 (r'\)', Punctuation, '#pop') 283 (r'\)', Punctuation, '#pop')
285 ] 284 ]
286 } 285 }
287 286
288 def __init__(self, **options): 287 def __init__(self, **options):
289 level = get_choice_opt(options, 'unicodelevel', list(self.tokens.keys()), 288 level = get_choice_opt(options, 'unicodelevel', list(self.tokens),
290 'basic') 289 'basic')
291 if level not in self._all_tokens: 290 if level not in self._all_tokens:
292 # compile the regexes now 291 # compile the regexes now
293 self._tokens = self.__class__.process_tokendef(level) 292 self._tokens = self.__class__.process_tokendef(level)
294 else: 293 else:
336 r'rawArrayIndexing|required|typeof|unchecked|using|' 335 r'rawArrayIndexing|required|typeof|unchecked|using|'
337 r'yieldAll|zip)\b', Name.Builtin), 336 r'yieldAll|zip)\b', Name.Builtin),
338 (r'"""(\\\\|\\"|.*?)"""', String.Double), 337 (r'"""(\\\\|\\"|.*?)"""', String.Double),
339 (r'"(\\\\|\\"|[^"]*?)"', String.Double), 338 (r'"(\\\\|\\"|[^"]*?)"', String.Double),
340 (r"'(\\\\|\\'|[^']*?)'", String.Single), 339 (r"'(\\\\|\\'|[^']*?)'", String.Single),
341 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name), 340 (r'[a-zA-Z_]\w*', Name),
342 (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float), 341 (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float),
343 (r'[0-9][0-9\.]*(ms?|d|h|s)', Number), 342 (r'[0-9][0-9.]*(ms?|d|h|s)', Number),
344 (r'0\d+', Number.Oct), 343 (r'0\d+', Number.Oct),
345 (r'0x[a-fA-F0-9]+', Number.Hex), 344 (r'0x[a-fA-F0-9]+', Number.Hex),
346 (r'\d+L', Number.Integer.Long), 345 (r'\d+L', Number.Integer.Long),
347 (r'\d+', Number.Integer), 346 (r'\d+', Number.Integer),
348 ], 347 ],
351 ('[*]/', Comment.Multiline, '#pop'), 350 ('[*]/', Comment.Multiline, '#pop'),
352 ('[^/*]', Comment.Multiline), 351 ('[^/*]', Comment.Multiline),
353 ('[*/]', Comment.Multiline) 352 ('[*/]', Comment.Multiline)
354 ], 353 ],
355 'funcname': [ 354 'funcname': [
356 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop') 355 ('[a-zA-Z_]\w*', Name.Function, '#pop')
357 ], 356 ],
358 'classname': [ 357 'classname': [
359 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') 358 ('[a-zA-Z_]\w*', Name.Class, '#pop')
360 ], 359 ],
361 'namespace': [ 360 'namespace': [
362 ('[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop') 361 ('[a-zA-Z_][\w.]*', Name.Namespace, '#pop')
363 ] 362 ]
364 } 363 }
365 364
366 365
367 class VbNetLexer(RegexLexer): 366 class VbNetLexer(RegexLexer):
372 """ 371 """
373 372
374 name = 'VB.net' 373 name = 'VB.net'
375 aliases = ['vb.net', 'vbnet'] 374 aliases = ['vb.net', 'vbnet']
376 filenames = ['*.vb', '*.bas'] 375 filenames = ['*.vb', '*.bas']
377 mimetypes = ['text/x-vbnet', 'text/x-vba'] # (?) 376 mimetypes = ['text/x-vbnet', 'text/x-vba'] # (?)
377
378 uni_name = '[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' + \
379 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc',
380 'Cf', 'Mn', 'Mc') + ']*'
378 381
379 flags = re.MULTILINE | re.IGNORECASE 382 flags = re.MULTILINE | re.IGNORECASE
380 tokens = { 383 tokens = {
381 'root': [ 384 'root': [
382 (r'^\s*<.*?>', Name.Attribute), 385 (r'^\s*<.*?>', Name.Attribute),
383 (r'\s+', Text), 386 (r'\s+', Text),
384 (r'\n', Text), 387 (r'\n', Text),
385 (r'rem\b.*?\n', Comment), 388 (r'rem\b.*?\n', Comment),
386 (r"'.*?\n", Comment), 389 (r"'.*?\n", Comment),
387 (r'#If\s.*?\sThen|#ElseIf\s.*?\sThen|#End\s+If|#Const|' 390 (r'#If\s.*?\sThen|#ElseIf\s.*?\sThen|#Else|#End\s+If|#Const|'
388 r'#ExternalSource.*?\n|#End\s+ExternalSource|' 391 r'#ExternalSource.*?\n|#End\s+ExternalSource|'
389 r'#Region.*?\n|#End\s+Region|#ExternalChecksum', 392 r'#Region.*?\n|#End\s+Region|#ExternalChecksum',
390 Comment.Preproc), 393 Comment.Preproc),
391 (r'[\(\){}!#,.:]', Punctuation), 394 (r'[(){}!#,.:]', Punctuation),
392 (r'Option\s+(Strict|Explicit|Compare)\s+' 395 (r'Option\s+(Strict|Explicit|Compare)\s+'
393 r'(On|Off|Binary|Text)', Keyword.Declaration), 396 r'(On|Off|Binary|Text)', Keyword.Declaration),
394 (r'(?<!\.)(AddHandler|Alias|' 397 (r'(?<!\.)(AddHandler|Alias|'
395 r'ByRef|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|' 398 r'ByRef|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|'
396 r'CDec|CDbl|CInt|CLng|CObj|Continue|CSByte|CShort|' 399 r'CDec|CDbl|CInt|CLng|CObj|Continue|CSByte|CShort|'
422 r'Object|SByte|Short|Single|String|Variant|UInteger|ULong|' 425 r'Object|SByte|Short|Single|String|Variant|UInteger|ULong|'
423 r'UShort)\b', Keyword.Type), 426 r'UShort)\b', Keyword.Type),
424 (r'(?<!\.)(AddressOf|And|AndAlso|As|GetType|In|Is|IsNot|Like|Mod|' 427 (r'(?<!\.)(AddressOf|And|AndAlso|As|GetType|In|Is|IsNot|Like|Mod|'
425 r'Or|OrElse|TypeOf|Xor)\b', Operator.Word), 428 r'Or|OrElse|TypeOf|Xor)\b', Operator.Word),
426 (r'&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|' 429 (r'&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|'
427 r'<=|>=|<>|[-&*/\\^+=<>]', 430 r'<=|>=|<>|[-&*/\\^+=<>\[\]]',
428 Operator), 431 Operator),
429 ('"', String, 'string'), 432 ('"', String, 'string'),
430 ('[a-zA-Z_][a-zA-Z0-9_]*[%&@!#$]?', Name), 433 (r'_\n', Text), # Line continuation (must be before Name)
434 (uni_name + '[%&@!#$]?', Name),
431 ('#.*?#', Literal.Date), 435 ('#.*?#', Literal.Date),
432 (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float), 436 (r'(\d+\.\d*|\d*\.\d+)(F[+-]?[0-9]+)?', Number.Float),
433 (r'\d+([SILDFR]|US|UI|UL)?', Number.Integer), 437 (r'\d+([SILDFR]|US|UI|UL)?', Number.Integer),
434 (r'&H[0-9a-f]+([SILDFR]|US|UI|UL)?', Number.Integer), 438 (r'&H[0-9a-f]+([SILDFR]|US|UI|UL)?', Number.Integer),
435 (r'&O[0-7]+([SILDFR]|US|UI|UL)?', Number.Integer), 439 (r'&O[0-7]+([SILDFR]|US|UI|UL)?', Number.Integer),
436 (r'_\n', Text), # Line continuation
437 ], 440 ],
438 'string': [ 441 'string': [
439 (r'""', String), 442 (r'""', String),
440 (r'"C?', String, '#pop'), 443 (r'"C?', String, '#pop'),
441 (r'[^"]+', String), 444 (r'[^"]+', String),
442 ], 445 ],
443 'dim': [ 446 'dim': [
444 (r'[a-z_][a-z0-9_]*', Name.Variable, '#pop'), 447 (uni_name, Name.Variable, '#pop'),
445 (r'', Text, '#pop'), # any other syntax 448 default('#pop'), # any other syntax
446 ], 449 ],
447 'funcname': [ 450 'funcname': [
448 (r'[a-z_][a-z0-9_]*', Name.Function, '#pop'), 451 (uni_name, Name.Function, '#pop'),
449 ], 452 ],
450 'classname': [ 453 'classname': [
451 (r'[a-z_][a-z0-9_]*', Name.Class, '#pop'), 454 (uni_name, Name.Class, '#pop'),
452 ], 455 ],
453 'namespace': [ 456 'namespace': [
454 (r'[a-z_][a-z0-9_.]*', Name.Namespace, '#pop'), 457 (uni_name, Name.Namespace),
458 (r'\.', Name.Namespace),
459 default('#pop'),
455 ], 460 ],
456 'end': [ 461 'end': [
457 (r'\s+', Text), 462 (r'\s+', Text),
458 (r'(Function|Sub|Property|Class|Structure|Enum|Module|Namespace)\b', 463 (r'(Function|Sub|Property|Class|Structure|Enum|Module|Namespace)\b',
459 Keyword, '#pop'), 464 Keyword, '#pop'),
460 (r'', Text, '#pop'), 465 default('#pop'),
461 ] 466 ]
462 } 467 }
468
469 def analyse_text(text):
470 if re.search(r'^\s*(#If|Module|Namespace)', text, re.MULTILINE):
471 return 0.5
463 472
464 473
465 class GenericAspxLexer(RegexLexer): 474 class GenericAspxLexer(RegexLexer):
466 """ 475 """
467 Lexer for ASP.NET pages. 476 Lexer for ASP.NET pages.
483 (r'.+', using(XmlLexer)), 492 (r'.+', using(XmlLexer)),
484 ], 493 ],
485 } 494 }
486 495
487 496
488 #TODO support multiple languages within the same source file 497 # TODO support multiple languages within the same source file
489 class CSharpAspxLexer(DelegatingLexer): 498 class CSharpAspxLexer(DelegatingLexer):
490 """ 499 """
491 Lexer for highligting C# within ASP.NET pages. 500 Lexer for highlighting C# within ASP.NET pages.
492 """ 501 """
493 502
494 name = 'aspx-cs' 503 name = 'aspx-cs'
495 aliases = ['aspx-cs'] 504 aliases = ['aspx-cs']
496 filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'] 505 filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd']
497 mimetypes = [] 506 mimetypes = []
498 507
499 def __init__(self, **options): 508 def __init__(self, **options):
500 super(CSharpAspxLexer, self).__init__(CSharpLexer,GenericAspxLexer, 509 super(CSharpAspxLexer, self).__init__(CSharpLexer, GenericAspxLexer,
501 **options) 510 **options)
502 511
503 def analyse_text(text): 512 def analyse_text(text):
504 if re.search(r'Page\s*Language="C#"', text, re.I) is not None: 513 if re.search(r'Page\s*Language="C#"', text, re.I) is not None:
505 return 0.2 514 return 0.2
507 return 0.15 516 return 0.15
508 517
509 518
510 class VbNetAspxLexer(DelegatingLexer): 519 class VbNetAspxLexer(DelegatingLexer):
511 """ 520 """
512 Lexer for highligting Visual Basic.net within ASP.NET pages. 521 Lexer for highlighting Visual Basic.net within ASP.NET pages.
513 """ 522 """
514 523
515 name = 'aspx-vb' 524 name = 'aspx-vb'
516 aliases = ['aspx-vb'] 525 aliases = ['aspx-vb']
517 filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'] 526 filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd']
518 mimetypes = [] 527 mimetypes = []
519 528
520 def __init__(self, **options): 529 def __init__(self, **options):
521 super(VbNetAspxLexer, self).__init__(VbNetLexer,GenericAspxLexer, 530 super(VbNetAspxLexer, self).__init__(VbNetLexer, GenericAspxLexer,
522 **options) 531 **options)
523 532
524 def analyse_text(text): 533 def analyse_text(text):
525 if re.search(r'Page\s*Language="Vb"', text, re.I) is not None: 534 if re.search(r'Page\s*Language="Vb"', text, re.I) is not None:
526 return 0.2 535 return 0.2
527 elif re.search(r'script[^>]+language=["\']vb', text, re.I) is not None: 536 elif re.search(r'script[^>]+language=["\']vb', text, re.I) is not None:
529 538
530 539
531 # Very close to functional.OcamlLexer 540 # Very close to functional.OcamlLexer
532 class FSharpLexer(RegexLexer): 541 class FSharpLexer(RegexLexer):
533 """ 542 """
534 For the F# language. 543 For the F# language (version 3.0).
535 544
536 *New in Pygments 1.5.* 545 AAAAACK Strings
546 http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html#_Toc335818775
547
548 .. versionadded:: 1.5
537 """ 549 """
538 550
539 name = 'FSharp' 551 name = 'FSharp'
540 aliases = ['fsharp'] 552 aliases = ['fsharp']
541 filenames = ['*.fs', '*.fsi'] 553 filenames = ['*.fs', '*.fsi']
542 mimetypes = ['text/x-fsharp'] 554 mimetypes = ['text/x-fsharp']
543 555
544 keywords = [ 556 keywords = [
545 'abstract', 'and', 'as', 'assert', 'base', 'begin', 'class', 557 'abstract', 'as', 'assert', 'base', 'begin', 'class', 'default',
546 'default', 'delegate', 'do', 'do!', 'done', 'downcast', 558 'delegate', 'do!', 'do', 'done', 'downcast', 'downto', 'elif', 'else',
547 'downto', 'elif', 'else', 'end', 'exception', 'extern', 559 'end', 'exception', 'extern', 'false', 'finally', 'for', 'function',
548 'false', 'finally', 'for', 'fun', 'function', 'global', 'if', 560 'fun', 'global', 'if', 'inherit', 'inline', 'interface', 'internal',
549 'in', 'inherit', 'inline', 'interface', 'internal', 'lazy', 561 'in', 'lazy', 'let!', 'let', 'match', 'member', 'module', 'mutable',
550 'let', 'let!', 'match', 'member', 'module', 'mutable', 562 'namespace', 'new', 'null', 'of', 'open', 'override', 'private', 'public',
551 'namespace', 'new', 'null', 'of', 'open', 'or', 'override', 563 'rec', 'return!', 'return', 'select', 'static', 'struct', 'then', 'to',
552 'private', 'public', 'rec', 'return', 'return!', 'sig', 564 'true', 'try', 'type', 'upcast', 'use!', 'use', 'val', 'void', 'when',
553 'static', 'struct', 'then', 'to', 'true', 'try', 'type', 565 'while', 'with', 'yield!', 'yield',
554 'upcast', 'use', 'use!', 'val', 'void', 'when', 'while', 566 ]
555 'with', 'yield', 'yield!' 567 # Reserved words; cannot hurt to color them as keywords too.
568 keywords += [
569 'atomic', 'break', 'checked', 'component', 'const', 'constraint',
570 'constructor', 'continue', 'eager', 'event', 'external', 'fixed',
571 'functor', 'include', 'method', 'mixin', 'object', 'parallel',
572 'process', 'protected', 'pure', 'sealed', 'tailcall', 'trait',
573 'virtual', 'volatile',
556 ] 574 ]
557 keyopts = [ 575 keyopts = [
558 '!=','#','&&','&','\(','\)','\*','\+',',','-\.', 576 '!=', '#', '&&', '&', '\(', '\)', '\*', '\+', ',', '-\.',
559 '->','-','\.\.','\.','::',':=',':>',':',';;',';','<-', 577 '->', '-', '\.\.', '\.', '::', ':=', ':>', ':', ';;', ';', '<-',
560 '<','>]','>','\?\?','\?','\[<','\[>','\[\|','\[', 578 '<\]', '<', '>\]', '>', '\?\?', '\?', '\[<', '\[\|', '\[', '\]',
561 ']','_','`','{','\|\]','\|','}','~','<@','=','@>' 579 '_', '`', '\{', '\|\]', '\|', '\}', '~', '<@@', '<@', '=', '@>', '@@>',
562 ] 580 ]
563 581
564 operators = r'[!$%&*+\./:<=>?@^|~-]' 582 operators = r'[!$%&*+\./:<=>?@^|~-]'
565 word_operators = ['and', 'asr', 'land', 'lor', 'lsl', 'lxor', 'mod', 'not', 'or'] 583 word_operators = ['and', 'or', 'not']
566 prefix_syms = r'[!?~]' 584 prefix_syms = r'[!?~]'
567 infix_syms = r'[=<>@^|&+\*/$%-]' 585 infix_syms = r'[=<>@^|&+\*/$%-]'
568 primitives = ['unit', 'int', 'float', 'bool', 'string', 'char', 'list', 'array', 586 primitives = [
569 'byte', 'sbyte', 'int16', 'uint16', 'uint32', 'int64', 'uint64' 587 'sbyte', 'byte', 'char', 'nativeint', 'unativeint', 'float32', 'single',
570 'nativeint', 'unativeint', 'decimal', 'void', 'float32', 'single', 588 'float', 'double', 'int8', 'uint8', 'int16', 'uint16', 'int32',
571 'double'] 589 'uint32', 'int64', 'uint64', 'decimal', 'unit', 'bool', 'string',
590 'list', 'exn', 'obj', 'enum',
591 ]
592
593 # See http://msdn.microsoft.com/en-us/library/dd233181.aspx and/or
594 # http://fsharp.org/about/files/spec.pdf for reference. Good luck.
572 595
573 tokens = { 596 tokens = {
574 'escape-sequence': [ 597 'escape-sequence': [
575 (r'\\[\\\"\'ntbr]', String.Escape), 598 (r'\\[\\"\'ntbrafv]', String.Escape),
576 (r'\\[0-9]{3}', String.Escape), 599 (r'\\[0-9]{3}', String.Escape),
577 (r'\\x[0-9a-fA-F]{2}', String.Escape), 600 (r'\\u[0-9a-fA-F]{4}', String.Escape),
601 (r'\\U[0-9a-fA-F]{8}', String.Escape),
578 ], 602 ],
579 'root': [ 603 'root': [
580 (r'\s+', Text), 604 (r'\s+', Text),
581 (r'false|true|\(\)|\[\]', Name.Builtin.Pseudo), 605 (r'\(\)|\[\]', Name.Builtin.Pseudo),
582 (r'\b([A-Z][A-Za-z0-9_\']*)(?=\s*\.)', 606 (r'\b(?<!\.)([A-Z][\w\']*)(?=\s*\.)',
583 Name.Namespace, 'dotted'), 607 Name.Namespace, 'dotted'),
584 (r'\b([A-Z][A-Za-z0-9_\']*)', Name.Class), 608 (r'\b([A-Z][\w\']*)', Name),
609 (r'///.*?\n', String.Doc),
585 (r'//.*?\n', Comment.Single), 610 (r'//.*?\n', Comment.Single),
586 (r'\(\*(?!\))', Comment, 'comment'), 611 (r'\(\*(?!\))', Comment, 'comment'),
612
613 (r'@"', String, 'lstring'),
614 (r'"""', String, 'tqs'),
615 (r'"', String, 'string'),
616
617 (r'\b(open|module)(\s+)([\w.]+)',
618 bygroups(Keyword, Text, Name.Namespace)),
619 (r'\b(let!?)(\s+)(\w+)',
620 bygroups(Keyword, Text, Name.Variable)),
621 (r'\b(type)(\s+)(\w+)',
622 bygroups(Keyword, Text, Name.Class)),
623 (r'\b(member|override)(\s+)(\w+)(\.)(\w+)',
624 bygroups(Keyword, Text, Name, Punctuation, Name.Function)),
587 (r'\b(%s)\b' % '|'.join(keywords), Keyword), 625 (r'\b(%s)\b' % '|'.join(keywords), Keyword),
626 (r'``([^`\n\r\t]|`[^`\n\r\t])+``', Name),
588 (r'(%s)' % '|'.join(keyopts), Operator), 627 (r'(%s)' % '|'.join(keyopts), Operator),
589 (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator), 628 (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator),
590 (r'\b(%s)\b' % '|'.join(word_operators), Operator.Word), 629 (r'\b(%s)\b' % '|'.join(word_operators), Operator.Word),
591 (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type), 630 (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type),
592 631 (r'#[ \t]*(if|endif|else|line|nowarn|light|\d+)\b.*?\n',
593 (r'#[ \t]*(if|endif|else|line|nowarn|light)\b.*?\n',
594 Comment.Preproc), 632 Comment.Preproc),
595 633
596 (r"[^\W\d][\w']*", Name), 634 (r"[^\W\d][\w']*", Name),
597 635
598 (r'\d[\d_]*', Number.Integer), 636 (r'\d[\d_]*[uU]?[yslLnQRZINGmM]?', Number.Integer),
599 (r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex), 637 (r'0[xX][\da-fA-F][\da-fA-F_]*[uU]?[yslLn]?[fF]?', Number.Hex),
600 (r'0[oO][0-7][0-7_]*', Number.Oct), 638 (r'0[oO][0-7][0-7_]*[uU]?[yslLn]?', Number.Oct),
601 (r'0[bB][01][01_]*', Number.Binary), 639 (r'0[bB][01][01_]*[uU]?[yslLn]?', Number.Bin),
602 (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float), 640 (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)[fFmM]?',
603 641 Number.Float),
604 (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'", 642
643 (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'B?",
605 String.Char), 644 String.Char),
606 (r"'.'", String.Char), 645 (r"'.'", String.Char),
607 (r"'", Keyword), # a stray quote is another syntax element 646 (r"'", Keyword), # a stray quote is another syntax element
608 647
609 (r'"', String.Double, 'string'), 648 (r'@?"', String.Double, 'string'),
610 649
611 (r'[~?][a-z][\w\']*:', Name.Variable), 650 (r'[~?][a-z][\w\']*:', Name.Variable),
612 ],
613 'comment': [
614 (r'[^(*)]+', Comment),
615 (r'\(\*', Comment, '#push'),
616 (r'\*\)', Comment, '#pop'),
617 (r'[(*)]', Comment),
618 ],
619 'string': [
620 (r'[^\\"]+', String.Double),
621 include('escape-sequence'),
622 (r'\\\n', String.Double),
623 (r'"', String.Double, '#pop'),
624 ], 651 ],
625 'dotted': [ 652 'dotted': [
626 (r'\s+', Text), 653 (r'\s+', Text),
627 (r'\.', Punctuation), 654 (r'\.', Punctuation),
628 (r'[A-Z][A-Za-z0-9_\']*(?=\s*\.)', Name.Namespace), 655 (r'[A-Z][\w\']*(?=\s*\.)', Name.Namespace),
629 (r'[A-Z][A-Za-z0-9_\']*', Name.Class, '#pop'), 656 (r'[A-Z][\w\']*', Name, '#pop'),
630 (r'[a-z_][A-Za-z0-9_\']*', Name, '#pop'), 657 (r'[a-z_][\w\']*', Name, '#pop'),
658 # e.g. dictionary index access
659 default('#pop'),
660 ],
661 'comment': [
662 (r'[^(*)@"]+', Comment),
663 (r'\(\*', Comment, '#push'),
664 (r'\*\)', Comment, '#pop'),
665 # comments cannot be closed within strings in comments
666 (r'@"', String, 'lstring'),
667 (r'"""', String, 'tqs'),
668 (r'"', String, 'string'),
669 (r'[(*)@]', Comment),
670 ],
671 'string': [
672 (r'[^\\"]+', String),
673 include('escape-sequence'),
674 (r'\\\n', String),
675 (r'\n', String), # newlines are allowed in any string
676 (r'"B?', String, '#pop'),
677 ],
678 'lstring': [
679 (r'[^"]+', String),
680 (r'\n', String),
681 (r'""', String),
682 (r'"B?', String, '#pop'),
683 ],
684 'tqs': [
685 (r'[^"]+', String),
686 (r'\n', String),
687 (r'"""B?', String, '#pop'),
688 (r'"', String),
631 ], 689 ],
632 } 690 }

eric ide

mercurial