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

133 statements  

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

1""" 

2 pygments.lexers.dotnet 

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

4 

5 Lexers for .net languages. 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10import re 

11 

12from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, include, \ 

13 using, this, default, words 

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

15 Name, String, Number, Literal, Other, Whitespace 

16from pygments.util import get_choice_opt 

17from pygments import unistring as uni 

18 

19from pygments.lexers.html import XmlLexer 

20 

21__all__ = ['CSharpLexer', 'NemerleLexer', 'BooLexer', 'VbNetLexer', 

22 'CSharpAspxLexer', 'VbNetAspxLexer', 'FSharpLexer', 'XppLexer'] 

23 

24 

25class CSharpLexer(RegexLexer): 

26 """ 

27 For C# source code. 

28 

29 Additional options accepted: 

30 

31 `unicodelevel` 

32 Determines which Unicode characters this lexer allows for identifiers. 

33 The possible values are: 

34 

35 * ``none`` -- only the ASCII letters and numbers are allowed. This 

36 is the fastest selection. 

37 * ``basic`` -- all Unicode characters from the specification except 

38 category ``Lo`` are allowed. 

39 * ``full`` -- all Unicode characters as specified in the C# specs 

40 are allowed. Note that this means a considerable slowdown since the 

41 ``Lo`` category has more than 40,000 characters in it! 

42 

43 The default value is ``basic``. 

44 

45 .. versionadded:: 0.8 

46 """ 

47 

48 name = 'C#' 

49 url = 'https://docs.microsoft.com/en-us/dotnet/csharp/' 

50 aliases = ['csharp', 'c#', 'cs'] 

51 filenames = ['*.cs'] 

52 mimetypes = ['text/x-csharp'] # inferred 

53 

54 flags = re.MULTILINE | re.DOTALL 

55 

56 # for the range of allowed unicode characters in identifiers, see 

57 # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf 

58 

59 levels = { 

60 'none': r'@?[_a-zA-Z]\w*', 

61 'basic': ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' + 

62 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 

63 'Cf', 'Mn', 'Mc') + ']*'), 

64 'full': ('@?(?:_|[^' + 

65 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' + 

66 '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 

67 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'), 

68 } 

69 

70 tokens = {} 

71 token_variants = True 

72 

73 for levelname, cs_ident in levels.items(): 

74 tokens[levelname] = { 

75 'root': [ 

76 # method names 

77 (r'^([ \t]*)((?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type 

78 r'(' + cs_ident + ')' # method name 

79 r'(\s*)(\()', # signature start 

80 bygroups(Whitespace, using(this), Name.Function, Whitespace, 

81 Punctuation)), 

82 (r'^(\s*)(\[.*?\])', bygroups(Whitespace, Name.Attribute)), 

83 (r'[^\S\n]+', Whitespace), 

84 (r'(\\)(\n)', bygroups(Text, Whitespace)), # line continuation 

85 (r'//.*?\n', Comment.Single), 

86 (r'/[*].*?[*]/', Comment.Multiline), 

87 (r'\n', Whitespace), 

88 (words(( 

89 '>>>=', '>>=', '<<=', '<=', '>=', '+=', '-=', '*=', '/=', 

90 '%=', '&=', '|=', '^=', '??=', '=>', '??', '?.', '!=', '==', 

91 '&&', '||', '>>>', '>>', '<<', '++', '--', '+', '-', '*', 

92 '/', '%', '&', '|', '^', '<', '>', '?', '!', '~', '=', 

93 )), Operator), 

94 (r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator), 

95 (r'[()\[\];:,.]', Punctuation), 

96 (r'[{}]', Punctuation), 

97 (r'@"(""|[^"])*"', String), 

98 (r'\$?"(\\\\|\\[^\\]|[^"\\\n])*["\n]', String), 

99 (r"'\\.'|'[^\\]'", String.Char), 

100 (r"[0-9]+(\.[0-9]*)?([eE][+-][0-9]+)?" 

101 r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number), 

102 (r'(#)([ \t]*)(if|endif|else|elif|define|undef|' 

103 r'line|error|warning|region|endregion|pragma)\b(.*?)(\n)', 

104 bygroups(Comment.Preproc, Whitespace, Comment.Preproc, 

105 Comment.Preproc, Whitespace)), 

106 (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Whitespace, 

107 Keyword)), 

108 (r'(abstract|as|async|await|base|break|by|case|catch|' 

109 r'checked|const|continue|default|delegate|' 

110 r'do|else|enum|event|explicit|extern|false|finally|' 

111 r'fixed|for|foreach|goto|if|implicit|in|interface|' 

112 r'internal|is|let|lock|new|null|on|operator|' 

113 r'out|override|params|private|protected|public|readonly|' 

114 r'ref|return|sealed|sizeof|stackalloc|static|' 

115 r'switch|this|throw|true|try|typeof|' 

116 r'unchecked|unsafe|virtual|void|while|' 

117 r'get|set|new|partial|yield|add|remove|value|alias|ascending|' 

118 r'descending|from|group|into|orderby|select|thenby|where|' 

119 r'join|equals)\b', Keyword), 

120 (r'(global)(::)', bygroups(Keyword, Punctuation)), 

121 (r'(bool|byte|char|decimal|double|dynamic|float|int|long|object|' 

122 r'sbyte|short|string|uint|ulong|ushort|var)\b\??', Keyword.Type), 

123 (r'(class|struct)(\s+)', bygroups(Keyword, Whitespace), 'class'), 

124 (r'(namespace|using)(\s+)', bygroups(Keyword, Whitespace), 'namespace'), 

125 (cs_ident, Name), 

126 ], 

127 'class': [ 

128 (cs_ident, Name.Class, '#pop'), 

129 default('#pop'), 

130 ], 

131 'namespace': [ 

132 (r'(?=\()', Text, '#pop'), # using (resource) 

133 ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop'), 

134 ] 

135 } 

136 

137 def __init__(self, **options): 

138 level = get_choice_opt(options, 'unicodelevel', list(self.tokens), 'basic') 

139 if level not in self._all_tokens: 

140 # compile the regexes now 

141 self._tokens = self.__class__.process_tokendef(level) 

142 else: 

143 self._tokens = self._all_tokens[level] 

144 

145 RegexLexer.__init__(self, **options) 

146 

147 

148class NemerleLexer(RegexLexer): 

149 """ 

150 For Nemerle source code. 

151 

152 Additional options accepted: 

153 

154 `unicodelevel` 

155 Determines which Unicode characters this lexer allows for identifiers. 

156 The possible values are: 

157 

158 * ``none`` -- only the ASCII letters and numbers are allowed. This 

159 is the fastest selection. 

160 * ``basic`` -- all Unicode characters from the specification except 

161 category ``Lo`` are allowed. 

162 * ``full`` -- all Unicode characters as specified in the C# specs 

163 are allowed. Note that this means a considerable slowdown since the 

164 ``Lo`` category has more than 40,000 characters in it! 

165 

166 The default value is ``basic``. 

167 

168 .. versionadded:: 1.5 

169 """ 

170 

171 name = 'Nemerle' 

172 url = 'http://nemerle.org' 

173 aliases = ['nemerle'] 

174 filenames = ['*.n'] 

175 mimetypes = ['text/x-nemerle'] # inferred 

176 

177 flags = re.MULTILINE | re.DOTALL 

178 

179 # for the range of allowed unicode characters in identifiers, see 

180 # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf 

181 

182 levels = { 

183 'none': r'@?[_a-zA-Z]\w*', 

184 'basic': ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' + 

185 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 

186 'Cf', 'Mn', 'Mc') + ']*'), 

187 'full': ('@?(?:_|[^' + 

188 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' + 

189 '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 

190 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'), 

191 } 

192 

193 tokens = {} 

194 token_variants = True 

195 

196 for levelname, cs_ident in levels.items(): 

197 tokens[levelname] = { 

198 'root': [ 

199 # method names 

200 (r'^([ \t]*)((?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type 

201 r'(' + cs_ident + ')' # method name 

202 r'(\s*)(\()', # signature start 

203 bygroups(Whitespace, using(this), Name.Function, Whitespace, \ 

204 Punctuation)), 

205 (r'^(\s*)(\[.*?\])', bygroups(Whitespace, Name.Attribute)), 

206 (r'[^\S\n]+', Whitespace), 

207 (r'(\\)(\n)', bygroups(Text, Whitespace)), # line continuation 

208 (r'//.*?\n', Comment.Single), 

209 (r'/[*].*?[*]/', Comment.Multiline), 

210 (r'\n', Whitespace), 

211 (r'(\$)(\s*)(")', bygroups(String, Whitespace, String), 

212 'splice-string'), 

213 (r'(\$)(\s*)(<#)', bygroups(String, Whitespace, String), 

214 'splice-string2'), 

215 (r'<#', String, 'recursive-string'), 

216 

217 (r'(<\[)(\s*)(' + cs_ident + ':)?', 

218 bygroups(Keyword, Whitespace, Keyword)), 

219 (r'\]\>', Keyword), 

220 

221 # quasiquotation only 

222 (r'\$' + cs_ident, Name), 

223 (r'(\$)(\()', bygroups(Name, Punctuation), 

224 'splice-string-content'), 

225 

226 (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation), 

227 (r'[{}]', Punctuation), 

228 (r'@"(""|[^"])*"', String), 

229 (r'"(\\\\|\\[^\\]|[^"\\\n])*["\n]', String), 

230 (r"'\\.'|'[^\\]'", String.Char), 

231 (r"0[xX][0-9a-fA-F]+[Ll]?", Number), 

232 (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFLdD]?", Number), 

233 (r'(#)([ \t]*)(if|endif|else|elif|define|undef|' 

234 r'line|error|warning|region|endregion|pragma)\b', 

235 bygroups(Comment.Preproc, Whitespace, Comment.Preproc), 'preproc'), 

236 (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Whitespace, Keyword)), 

237 (r'(abstract|and|as|base|catch|def|delegate|' 

238 r'enum|event|extern|false|finally|' 

239 r'fun|implements|interface|internal|' 

240 r'is|macro|match|matches|module|mutable|new|' 

241 r'null|out|override|params|partial|private|' 

242 r'protected|public|ref|sealed|static|' 

243 r'syntax|this|throw|true|try|type|typeof|' 

244 r'virtual|volatile|when|where|with|' 

245 r'assert|assert2|async|break|checked|continue|do|else|' 

246 r'ensures|for|foreach|if|late|lock|new|nolate|' 

247 r'otherwise|regexp|repeat|requires|return|surroundwith|' 

248 r'unchecked|unless|using|while|yield)\b', Keyword), 

249 (r'(global)(::)', bygroups(Keyword, Punctuation)), 

250 (r'(bool|byte|char|decimal|double|float|int|long|object|sbyte|' 

251 r'short|string|uint|ulong|ushort|void|array|list)\b\??', 

252 Keyword.Type), 

253 (r'(:>?)(\s*)(' + cs_ident + r'\??)', 

254 bygroups(Punctuation, Whitespace, Keyword.Type)), 

255 (r'(class|struct|variant|module)(\s+)', 

256 bygroups(Keyword, Whitespace), 'class'), 

257 (r'(namespace|using)(\s+)', bygroups(Keyword, Whitespace), 

258 'namespace'), 

259 (cs_ident, Name), 

260 ], 

261 'class': [ 

262 (cs_ident, Name.Class, '#pop') 

263 ], 

264 'preproc': [ 

265 (r'\w+', Comment.Preproc), 

266 (r'[ \t]+', Whitespace), 

267 (r'\n', Whitespace, '#pop') 

268 ], 

269 'namespace': [ 

270 (r'(?=\()', Text, '#pop'), # using (resource) 

271 ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop') 

272 ], 

273 'splice-string': [ 

274 (r'[^"$]', String), 

275 (r'\$' + cs_ident, Name), 

276 (r'(\$)(\()', bygroups(Name, Punctuation), 

277 'splice-string-content'), 

278 (r'\\"', String), 

279 (r'"', String, '#pop') 

280 ], 

281 'splice-string2': [ 

282 (r'[^#<>$]', String), 

283 (r'\$' + cs_ident, Name), 

284 (r'(\$)(\()', bygroups(Name, Punctuation), 

285 'splice-string-content'), 

286 (r'<#', String, '#push'), 

287 (r'#>', String, '#pop') 

288 ], 

289 'recursive-string': [ 

290 (r'[^#<>]', String), 

291 (r'<#', String, '#push'), 

292 (r'#>', String, '#pop') 

293 ], 

294 'splice-string-content': [ 

295 (r'if|match', Keyword), 

296 (r'[~!%^&*+=|\[\]:;,.<>/?-\\"$ ]', Punctuation), 

297 (cs_ident, Name), 

298 (r'\d+', Number), 

299 (r'\(', Punctuation, '#push'), 

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

301 ] 

302 } 

303 

304 def __init__(self, **options): 

305 level = get_choice_opt(options, 'unicodelevel', list(self.tokens), 

306 'basic') 

307 if level not in self._all_tokens: 

308 # compile the regexes now 

309 self._tokens = self.__class__.process_tokendef(level) 

310 else: 

311 self._tokens = self._all_tokens[level] 

312 

313 RegexLexer.__init__(self, **options) 

314 

315 def analyse_text(text): 

316 """Nemerle is quite similar to Python, but @if is relatively uncommon 

317 elsewhere.""" 

318 result = 0 

319 

320 if '@if' in text: 

321 result += 0.1 

322 

323 return result 

324 

325 

326class BooLexer(RegexLexer): 

327 """ 

328 For Boo source code. 

329 """ 

330 

331 name = 'Boo' 

332 url = 'https://github.com/boo-lang/boo' 

333 aliases = ['boo'] 

334 filenames = ['*.boo'] 

335 mimetypes = ['text/x-boo'] 

336 

337 tokens = { 

338 'root': [ 

339 (r'\s+', Whitespace), 

340 (r'(#|//).*$', Comment.Single), 

341 (r'/[*]', Comment.Multiline, 'comment'), 

342 (r'[]{}:(),.;[]', Punctuation), 

343 (r'(\\)(\n)', bygroups(Text, Whitespace)), 

344 (r'\\', Text), 

345 (r'(in|is|and|or|not)\b', Operator.Word), 

346 (r'/(\\\\|\\[^\\]|[^/\\\s])/', String.Regex), 

347 (r'@/(\\\\|\\[^\\]|[^/\\])*/', String.Regex), 

348 (r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator), 

349 (r'(as|abstract|callable|constructor|destructor|do|import|' 

350 r'enum|event|final|get|interface|internal|of|override|' 

351 r'partial|private|protected|public|return|set|static|' 

352 r'struct|transient|virtual|yield|super|and|break|cast|' 

353 r'continue|elif|else|ensure|except|for|given|goto|if|in|' 

354 r'is|isa|not|or|otherwise|pass|raise|ref|try|unless|when|' 

355 r'while|from|as)\b', Keyword), 

356 (r'def(?=\s+\(.*?\))', Keyword), 

357 (r'(def)(\s+)', bygroups(Keyword, Whitespace), 'funcname'), 

358 (r'(class)(\s+)', bygroups(Keyword, Whitespace), 'classname'), 

359 (r'(namespace)(\s+)', bygroups(Keyword, Whitespace), 'namespace'), 

360 (r'(?<!\.)(true|false|null|self|__eval__|__switch__|array|' 

361 r'assert|checked|enumerate|filter|getter|len|lock|map|' 

362 r'matrix|max|min|normalArrayIndexing|print|property|range|' 

363 r'rawArrayIndexing|required|typeof|unchecked|using|' 

364 r'yieldAll|zip)\b', Name.Builtin), 

365 (r'"""(\\\\|\\"|.*?)"""', String.Double), 

366 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), 

367 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single), 

368 (r'[a-zA-Z_]\w*', Name), 

369 (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float), 

370 (r'[0-9][0-9.]*(ms?|d|h|s)', Number), 

371 (r'0\d+', Number.Oct), 

372 (r'0x[a-fA-F0-9]+', Number.Hex), 

373 (r'\d+L', Number.Integer.Long), 

374 (r'\d+', Number.Integer), 

375 ], 

376 'comment': [ 

377 ('/[*]', Comment.Multiline, '#push'), 

378 ('[*]/', Comment.Multiline, '#pop'), 

379 ('[^/*]', Comment.Multiline), 

380 ('[*/]', Comment.Multiline) 

381 ], 

382 'funcname': [ 

383 (r'[a-zA-Z_]\w*', Name.Function, '#pop') 

384 ], 

385 'classname': [ 

386 (r'[a-zA-Z_]\w*', Name.Class, '#pop') 

387 ], 

388 'namespace': [ 

389 (r'[a-zA-Z_][\w.]*', Name.Namespace, '#pop') 

390 ] 

391 } 

392 

393 

394class VbNetLexer(RegexLexer): 

395 """ 

396 For Visual Basic.NET source code. 

397 Also LibreOffice Basic, OpenOffice Basic, and StarOffice Basic. 

398 """ 

399 

400 name = 'VB.net' 

401 url = 'https://docs.microsoft.com/en-us/dotnet/visual-basic/' 

402 aliases = ['vb.net', 'vbnet', 'lobas', 'oobas', 'sobas'] 

403 filenames = ['*.vb', '*.bas'] 

404 mimetypes = ['text/x-vbnet', 'text/x-vba'] # (?) 

405 

406 uni_name = '[_' + uni.combine('Ll', 'Lt', 'Lm', 'Nl') + ']' + \ 

407 '[' + uni.combine('Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 

408 'Cf', 'Mn', 'Mc') + ']*' 

409 

410 flags = re.MULTILINE | re.IGNORECASE 

411 tokens = { 

412 'root': [ 

413 (r'^\s*<.*?>', Name.Attribute), 

414 (r'\s+', Whitespace), 

415 (r'\n', Whitespace), 

416 (r'(rem\b.*?)(\n)', bygroups(Comment, Whitespace)), 

417 (r"('.*?)(\n)", bygroups(Comment, Whitespace)), 

418 (r'#If\s.*?\sThen|#ElseIf\s.*?\sThen|#Else|#End\s+If|#Const|' 

419 r'#ExternalSource.*?\n|#End\s+ExternalSource|' 

420 r'#Region.*?\n|#End\s+Region|#ExternalChecksum', 

421 Comment.Preproc), 

422 (r'[(){}!#,.:]', Punctuation), 

423 (r'(Option)(\s+)(Strict|Explicit|Compare)(\s+)' 

424 r'(On|Off|Binary|Text)', 

425 bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration, 

426 Whitespace, Keyword.Declaration)), 

427 (words(( 

428 'AddHandler', 'Alias', 'ByRef', 'ByVal', 'Call', 'Case', 

429 'Catch', 'CBool', 'CByte', 'CChar', 'CDate', 'CDec', 'CDbl', 

430 'CInt', 'CLng', 'CObj', 'Continue', 'CSByte', 'CShort', 'CSng', 

431 'CStr', 'CType', 'CUInt', 'CULng', 'CUShort', 'Declare', 

432 'Default', 'Delegate', 'DirectCast', 'Do', 'Each', 'Else', 

433 'ElseIf', 'EndIf', 'Erase', 'Error', 'Event', 'Exit', 'False', 

434 'Finally', 'For', 'Friend', 'Get', 'Global', 'GoSub', 'GoTo', 

435 'Handles', 'If', 'Implements', 'Inherits', 'Interface', 'Let', 

436 'Lib', 'Loop', 'Me', 'MustInherit', 'MustOverride', 'MyBase', 

437 'MyClass', 'Narrowing', 'New', 'Next', 'Not', 'Nothing', 

438 'NotInheritable', 'NotOverridable', 'Of', 'On', 'Operator', 

439 'Option', 'Optional', 'Overloads', 'Overridable', 'Overrides', 

440 'ParamArray', 'Partial', 'Private', 'Protected', 'Public', 

441 'RaiseEvent', 'ReadOnly', 'ReDim', 'RemoveHandler', 'Resume', 

442 'Return', 'Select', 'Set', 'Shadows', 'Shared', 'Single', 

443 'Static', 'Step', 'Stop', 'SyncLock', 'Then', 'Throw', 'To', 

444 'True', 'Try', 'TryCast', 'Wend', 'Using', 'When', 'While', 

445 'Widening', 'With', 'WithEvents', 'WriteOnly'), 

446 prefix=r'(?<!\.)', suffix=r'\b'), Keyword), 

447 (r'(?<!\.)End\b', Keyword, 'end'), 

448 (r'(?<!\.)(Dim|Const)\b', Keyword, 'dim'), 

449 (r'(?<!\.)(Function|Sub|Property)(\s+)', 

450 bygroups(Keyword, Whitespace), 'funcname'), 

451 (r'(?<!\.)(Class|Structure|Enum)(\s+)', 

452 bygroups(Keyword, Whitespace), 'classname'), 

453 (r'(?<!\.)(Module|Namespace|Imports)(\s+)', 

454 bygroups(Keyword, Whitespace), 'namespace'), 

455 (r'(?<!\.)(Boolean|Byte|Char|Date|Decimal|Double|Integer|Long|' 

456 r'Object|SByte|Short|Single|String|Variant|UInteger|ULong|' 

457 r'UShort)\b', Keyword.Type), 

458 (r'(?<!\.)(AddressOf|And|AndAlso|As|GetType|In|Is|IsNot|Like|Mod|' 

459 r'Or|OrElse|TypeOf|Xor)\b', Operator.Word), 

460 (r'&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|' 

461 r'<=|>=|<>|[-&*/\\^+=<>\[\]]', 

462 Operator), 

463 ('"', String, 'string'), 

464 (r'(_)(\n)', bygroups(Text, Whitespace)), # Line continuation (must be before Name) 

465 (uni_name + '[%&@!#$]?', Name), 

466 ('#.*?#', Literal.Date), 

467 (r'(\d+\.\d*|\d*\.\d+)(F[+-]?[0-9]+)?', Number.Float), 

468 (r'\d+([SILDFR]|US|UI|UL)?', Number.Integer), 

469 (r'&H[0-9a-f]+([SILDFR]|US|UI|UL)?', Number.Integer), 

470 (r'&O[0-7]+([SILDFR]|US|UI|UL)?', Number.Integer), 

471 ], 

472 'string': [ 

473 (r'""', String), 

474 (r'"C?', String, '#pop'), 

475 (r'[^"]+', String), 

476 ], 

477 'dim': [ 

478 (uni_name, Name.Variable, '#pop'), 

479 default('#pop'), # any other syntax 

480 ], 

481 'funcname': [ 

482 (uni_name, Name.Function, '#pop'), 

483 ], 

484 'classname': [ 

485 (uni_name, Name.Class, '#pop'), 

486 ], 

487 'namespace': [ 

488 (uni_name, Name.Namespace), 

489 (r'\.', Name.Namespace), 

490 default('#pop'), 

491 ], 

492 'end': [ 

493 (r'\s+', Whitespace), 

494 (r'(Function|Sub|Property|Class|Structure|Enum|Module|Namespace)\b', 

495 Keyword, '#pop'), 

496 default('#pop'), 

497 ] 

498 } 

499 

500 def analyse_text(text): 

501 if re.search(r'^\s*(#If|Module|Namespace)', text, re.MULTILINE): 

502 return 0.5 

503 

504 

505class GenericAspxLexer(RegexLexer): 

506 """ 

507 Lexer for ASP.NET pages. 

508 """ 

509 

510 name = 'aspx-gen' 

511 filenames = [] 

512 mimetypes = [] 

513 

514 flags = re.DOTALL 

515 

516 tokens = { 

517 'root': [ 

518 (r'(<%[@=#]?)(.*?)(%>)', bygroups(Name.Tag, Other, Name.Tag)), 

519 (r'(<script.*?>)(.*?)(</script>)', bygroups(using(XmlLexer), 

520 Other, 

521 using(XmlLexer))), 

522 (r'(.+?)(?=<)', using(XmlLexer)), 

523 (r'.+', using(XmlLexer)), 

524 ], 

525 } 

526 

527 

528# TODO support multiple languages within the same source file 

529class CSharpAspxLexer(DelegatingLexer): 

530 """ 

531 Lexer for highlighting C# within ASP.NET pages. 

532 """ 

533 

534 name = 'aspx-cs' 

535 aliases = ['aspx-cs'] 

536 filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'] 

537 mimetypes = [] 

538 

539 def __init__(self, **options): 

540 super().__init__(CSharpLexer, GenericAspxLexer, **options) 

541 

542 def analyse_text(text): 

543 if re.search(r'Page\s*Language="C#"', text, re.I) is not None: 

544 return 0.2 

545 elif re.search(r'script[^>]+language=["\']C#', text, re.I) is not None: 

546 return 0.15 

547 

548 

549class VbNetAspxLexer(DelegatingLexer): 

550 """ 

551 Lexer for highlighting Visual Basic.net within ASP.NET pages. 

552 """ 

553 

554 name = 'aspx-vb' 

555 aliases = ['aspx-vb'] 

556 filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'] 

557 mimetypes = [] 

558 

559 def __init__(self, **options): 

560 super().__init__(VbNetLexer, GenericAspxLexer, **options) 

561 

562 def analyse_text(text): 

563 if re.search(r'Page\s*Language="Vb"', text, re.I) is not None: 

564 return 0.2 

565 elif re.search(r'script[^>]+language=["\']vb', text, re.I) is not None: 

566 return 0.15 

567 

568 

569# Very close to functional.OcamlLexer 

570class FSharpLexer(RegexLexer): 

571 """ 

572 For the F# language (version 3.0). 

573 

574 .. versionadded:: 1.5 

575 """ 

576 

577 name = 'F#' 

578 url = 'https://fsharp.org/' 

579 aliases = ['fsharp', 'f#'] 

580 filenames = ['*.fs', '*.fsi', '*.fsx'] 

581 mimetypes = ['text/x-fsharp'] 

582 

583 keywords = [ 

584 'abstract', 'as', 'assert', 'base', 'begin', 'class', 'default', 

585 'delegate', 'do!', 'do', 'done', 'downcast', 'downto', 'elif', 'else', 

586 'end', 'exception', 'extern', 'false', 'finally', 'for', 'function', 

587 'fun', 'global', 'if', 'inherit', 'inline', 'interface', 'internal', 

588 'in', 'lazy', 'let!', 'let', 'match', 'member', 'module', 'mutable', 

589 'namespace', 'new', 'null', 'of', 'open', 'override', 'private', 'public', 

590 'rec', 'return!', 'return', 'select', 'static', 'struct', 'then', 'to', 

591 'true', 'try', 'type', 'upcast', 'use!', 'use', 'val', 'void', 'when', 

592 'while', 'with', 'yield!', 'yield', 

593 ] 

594 # Reserved words; cannot hurt to color them as keywords too. 

595 keywords += [ 

596 'atomic', 'break', 'checked', 'component', 'const', 'constraint', 

597 'constructor', 'continue', 'eager', 'event', 'external', 'fixed', 

598 'functor', 'include', 'method', 'mixin', 'object', 'parallel', 

599 'process', 'protected', 'pure', 'sealed', 'tailcall', 'trait', 

600 'virtual', 'volatile', 

601 ] 

602 keyopts = [ 

603 '!=', '#', '&&', '&', r'\(', r'\)', r'\*', r'\+', ',', r'-\.', 

604 '->', '-', r'\.\.', r'\.', '::', ':=', ':>', ':', ';;', ';', '<-', 

605 r'<\]', '<', r'>\]', '>', r'\?\?', r'\?', r'\[<', r'\[\|', r'\[', r'\]', 

606 '_', '`', r'\{', r'\|\]', r'\|', r'\}', '~', '<@@', '<@', '=', '@>', '@@>', 

607 ] 

608 

609 operators = r'[!$%&*+\./:<=>?@^|~-]' 

610 word_operators = ['and', 'or', 'not'] 

611 prefix_syms = r'[!?~]' 

612 infix_syms = r'[=<>@^|&+\*/$%-]' 

613 primitives = [ 

614 'sbyte', 'byte', 'char', 'nativeint', 'unativeint', 'float32', 'single', 

615 'float', 'double', 'int8', 'uint8', 'int16', 'uint16', 'int32', 

616 'uint32', 'int64', 'uint64', 'decimal', 'unit', 'bool', 'string', 

617 'list', 'exn', 'obj', 'enum', 

618 ] 

619 

620 # See http://msdn.microsoft.com/en-us/library/dd233181.aspx and/or 

621 # http://fsharp.org/about/files/spec.pdf for reference. Good luck. 

622 

623 tokens = { 

624 'escape-sequence': [ 

625 (r'\\[\\"\'ntbrafv]', String.Escape), 

626 (r'\\[0-9]{3}', String.Escape), 

627 (r'\\u[0-9a-fA-F]{4}', String.Escape), 

628 (r'\\U[0-9a-fA-F]{8}', String.Escape), 

629 ], 

630 'root': [ 

631 (r'\s+', Whitespace), 

632 (r'\(\)|\[\]', Name.Builtin.Pseudo), 

633 (r'\b(?<!\.)([A-Z][\w\']*)(?=\s*\.)', 

634 Name.Namespace, 'dotted'), 

635 (r'\b([A-Z][\w\']*)', Name), 

636 (r'(///.*?)(\n)', bygroups(String.Doc, Whitespace)), 

637 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)), 

638 (r'\(\*(?!\))', Comment, 'comment'), 

639 

640 (r'@"', String, 'lstring'), 

641 (r'"""', String, 'tqs'), 

642 (r'"', String, 'string'), 

643 

644 (r'\b(open|module)(\s+)([\w.]+)', 

645 bygroups(Keyword, Whitespace, Name.Namespace)), 

646 (r'\b(let!?)(\s+)(\w+)', 

647 bygroups(Keyword, Whitespace, Name.Variable)), 

648 (r'\b(type)(\s+)(\w+)', 

649 bygroups(Keyword, Whitespace, Name.Class)), 

650 (r'\b(member|override)(\s+)(\w+)(\.)(\w+)', 

651 bygroups(Keyword, Whitespace, Name, Punctuation, Name.Function)), 

652 (r'\b(%s)\b' % '|'.join(keywords), Keyword), 

653 (r'``([^`\n\r\t]|`[^`\n\r\t])+``', Name), 

654 (r'(%s)' % '|'.join(keyopts), Operator), 

655 (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator), 

656 (r'\b(%s)\b' % '|'.join(word_operators), Operator.Word), 

657 (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type), 

658 (r'(#)([ \t]*)(if|endif|else|line|nowarn|light|\d+)\b(.*?)(\n)', 

659 bygroups(Comment.Preproc, Whitespace, Comment.Preproc, 

660 Comment.Preproc, Whitespace)), 

661 

662 (r"[^\W\d][\w']*", Name), 

663 

664 (r'\d[\d_]*[uU]?[yslLnQRZINGmM]?', Number.Integer), 

665 (r'0[xX][\da-fA-F][\da-fA-F_]*[uU]?[yslLn]?[fF]?', Number.Hex), 

666 (r'0[oO][0-7][0-7_]*[uU]?[yslLn]?', Number.Oct), 

667 (r'0[bB][01][01_]*[uU]?[yslLn]?', Number.Bin), 

668 (r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)[fFmM]?', 

669 Number.Float), 

670 

671 (r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'B?", 

672 String.Char), 

673 (r"'.'", String.Char), 

674 (r"'", Keyword), # a stray quote is another syntax element 

675 

676 (r'@?"', String.Double, 'string'), 

677 

678 (r'[~?][a-z][\w\']*:', Name.Variable), 

679 ], 

680 'dotted': [ 

681 (r'\s+', Whitespace), 

682 (r'\.', Punctuation), 

683 (r'[A-Z][\w\']*(?=\s*\.)', Name.Namespace), 

684 (r'[A-Z][\w\']*', Name, '#pop'), 

685 (r'[a-z_][\w\']*', Name, '#pop'), 

686 # e.g. dictionary index access 

687 default('#pop'), 

688 ], 

689 'comment': [ 

690 (r'[^(*)@"]+', Comment), 

691 (r'\(\*', Comment, '#push'), 

692 (r'\*\)', Comment, '#pop'), 

693 # comments cannot be closed within strings in comments 

694 (r'@"', String, 'lstring'), 

695 (r'"""', String, 'tqs'), 

696 (r'"', String, 'string'), 

697 (r'[(*)@]', Comment), 

698 ], 

699 'string': [ 

700 (r'[^\\"]+', String), 

701 include('escape-sequence'), 

702 (r'\\\n', String), 

703 (r'\n', String), # newlines are allowed in any string 

704 (r'"B?', String, '#pop'), 

705 ], 

706 'lstring': [ 

707 (r'[^"]+', String), 

708 (r'\n', String), 

709 (r'""', String), 

710 (r'"B?', String, '#pop'), 

711 ], 

712 'tqs': [ 

713 (r'[^"]+', String), 

714 (r'\n', String), 

715 (r'"""B?', String, '#pop'), 

716 (r'"', String), 

717 ], 

718 } 

719 

720 def analyse_text(text): 

721 """F# doesn't have that many unique features -- |> and <| are weak 

722 indicators.""" 

723 result = 0 

724 if '|>' in text: 

725 result += 0.05 

726 if '<|' in text: 

727 result += 0.05 

728 

729 return result 

730 

731 

732class XppLexer(RegexLexer): 

733 

734 """ 

735 For X++ source code. This is based loosely on the CSharpLexer 

736 

737 .. versionadded:: 2.15 

738 """ 

739 

740 name = 'X++' 

741 url = 'https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/dev-ref/xpp-language-reference' 

742 aliases = ['xpp', 'x++'] 

743 filenames = ['*.xpp'] 

744 

745 flags = re.MULTILINE 

746 

747 XPP_CHARS = ('@?(?:_|[^' + 

748 uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])' + 

749 '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', 

750 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'); 

751 # Temporary, see 

752 # https://github.com/thatch/regexlint/pull/49 

753 XPP_CHARS = XPP_CHARS.replace('\x00', '\x01') 

754 

755 OPERATORS = ( 

756 '<=', '>=', '+=', '-=', '*=', '/=', '!=', '==', 

757 '&&', '||', '>>', '<<', '++', '--', '+', '-', '*', 

758 '/', '%', '&', '|', '^', '<', '>', '?', '!', '~', '=', 

759 ) 

760 KEYWORDS = ('abstract','anytype','as','async','asc','at','avg','break','breakpoint','by','byref','case','catch', 

761 'changecompany','client','container','continue','count','crosscompany','default','delegate', 

762 'delete_from','desc','display','div','do','edit','else','element','eventhandler','exists','false','final', 

763 'firstfast','firstonly','firstonly10','firstonly100','firstonly1000','flush','for','forceliterals', 

764 'forcenestedloop','forceplaceholders','forceselectorder','forupdate','from','group','if','insert_recordset', 

765 'interface','is','join','like','maxof','minof','mod','new','next','nofetch','notexists','null','optimisticlock','order', 

766 'outer','pause','pessimisticlock','print','private','protected','public','repeatableread','retry','return', 

767 'reverse','select','server','setting','static','sum','super','switch','tablelock','this','throw','true','try','ttsabort','ttsbegin', 

768 'ttscommit','update_recordset','validtimestate','void','where','while','window') 

769 RUNTIME_FUNCTIONS = ('_duration','abs','acos','any2Date','any2Enum','any2Guid','any2Int','any2Int64','any2Real','any2Str','anytodate', 

770 'anytoenum','anytoguid','anytoint','anytoint64','anytoreal','anytostr','asin','atan','beep','cTerm','char2Num','classIdGet', 

771 'corrFlagGet','corrFlagSet','cos','cosh','curExt','curUserId','date2Num','date2Str','datetime2Str','dayName','dayOfMth', 

772 'dayOfWk','dayOfYr','ddb','decRound','dg','dimOf','endMth','enum2str','exp','exp10','fV','fieldId2Name','fieldId2PName', 

773 'fieldName2Id','frac','funcName','getCurrentPartition','getCurrentPartitionRecId','getPrefix','guid2Str','idg','indexId2Name', 

774 'indexName2Id','int2Str','int642Str','intvMax','intvName','intvNo','intvNorm','log10','logN','match','max','min','mkDate','mthName', 

775 'mthOfYr','newGuid','nextMth','nextQtr','nextYr','num2Char','num2Date','num2Str','pmt','power','prevMth','prevQtr','prevYr', 

776 'prmIsDefault','pt','pv','rate','refPrintAll','round','runAs','sessionId','setPrefix','sin','sinh','sleep','sln','str2Date', 

777 'str2Datetime','str2Enum','str2Guid','str2Int','str2Int64','str2Num','str2Time','strAlpha','strCmp','strColSeq','strDel', 

778 'strFind','strFmt','strIns','strKeep','strLTrim','strLen','strLine','strLwr','strNFind','strPoke','strPrompt','strRTrim', 

779 'strRem','strRep','strScan','strUpr','subStr','syd','systemDateGet','systemDateSet','tableId2Name', 

780 'tableId2PName','tableName2Id','tan','tanh','term','time2Str','timeNow','today','trunc','typeOf','uint2Str','wkOfYr','year') 

781 COMPILE_FUNCTIONS = ('attributeStr','classNum','classStr','configurationKeyNum','configurationKeyStr','dataEntityDataSourceStr','delegateStr', 

782 'dimensionHierarchyLevelStr','dimensionHierarchyStr','dimensionReferenceStr','dutyStr','enumCnt','enumLiteralStr','enumNum','enumStr', 

783 'extendedTypeNum','extendedTypeStr','fieldNum','fieldPName','fieldStr','formControlStr','formDataFieldStr','formDataSourceStr', 

784 'formMethodStr','formStr','identifierStr','indexNum','indexStr','licenseCodeNum','licenseCodeStr','literalStr','maxDate','maxInt', 

785 'measureStr','measurementStr','menuItemActionStr','menuItemDisplayStr','menuItemOutputStr','menuStr','methodStr','minInt','privilegeStr', 

786 'queryDatasourceStr','queryMethodStr','queryStr','reportStr','resourceStr','roleStr','ssrsReportStr','staticDelegateStr','staticMethodStr', 

787 'tableCollectionStr','tableFieldGroupStr','tableMethodStr','tableNum','tablePName','tableStaticMethodStr','tableStr','tileStr','varStr', 

788 'webActionItemStr','webDisplayContentItemStr','webFormStr','webMenuStr','webOutputContentItemStr','webReportStr','webSiteTempStr', 

789 'webStaticFileStr','webUrlItemStr','webWebPartStr','webletItemStr','webpageDefStr','websiteDefStr','workflowApprovalStr', 

790 'workflowCategoryStr','workflowTaskStr','workflowTypeStr') 

791 

792 tokens = {} 

793 

794 tokens = { 

795 'root': [ 

796 # method names 

797 (r'(\s*)\b(else|if)\b([^\n])', bygroups(Whitespace, Keyword, using(this))), # ensure that if is not treated like a function 

798 (r'^([ \t]*)((?:' + XPP_CHARS + r'(?:\[\])?\s+)+?)' # return type 

799 r'(' + XPP_CHARS + ')' # method name 

800 r'(\s*)(\()', # signature start 

801 bygroups(Whitespace, using(this), Name.Function, Whitespace, 

802 Punctuation)), 

803 (r'^(\s*)(\[)([^\n]*?)(\])', bygroups(Whitespace, Name.Attribute, Name.Variable.Class, Name.Attribute)), 

804 (r'[^\S\n]+', Whitespace), 

805 (r'(\\)(\n)', bygroups(Text, Whitespace)), # line continuation 

806 (r'//[^\n]*?\n', Comment.Single), 

807 (r'/[*][^\n]*?[*]/', Comment.Multiline), 

808 (r'\n', Whitespace), 

809 (words(OPERATORS), Operator), 

810 (r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator), 

811 (r'[()\[\];:,.#@]', Punctuation), 

812 (r'[{}]', Punctuation), 

813 (r'@"(""|[^"])*"', String), 

814 (r'\$?"(\\\\|\\[^\\]|[^"\\\n])*["\n]', String), 

815 (r"'\\.'|'[^\\]'", String.Char), 

816 (r"[0-9]+(\.[0-9]*)?([eE][+-][0-9]+)?" 

817 r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number), 

818 (words(KEYWORDS, suffix=r'\b'), Keyword), 

819 (r'(boolean|int|int64|str|real|guid|date)\b\??', Keyword.Type), 

820 (r'(class|struct|extends|implements)(\s+)', bygroups(Keyword, Whitespace), 'class'), 

821 (r'('+XPP_CHARS+')(::)', bygroups(Name.Variable.Class, Punctuation)), 

822 (r'(\s*)(\w+)(\s+\w+(,|=)?[^\n]*;)', bygroups(Whitespace, Name.Variable.Class, using(this))), # declaration 

823 # x++ specific function to get field should highlight the classname 

824 (r'(fieldNum\()('+XPP_CHARS+r')(\s*,\s*)('+XPP_CHARS+r')(\s*\))', 

825 bygroups(using(this), Name.Variable.Class, using(this), Name.Property, using(this))), 

826 # x++ specific function to get table should highlight the classname 

827 (r'(tableNum\()('+XPP_CHARS+r')(\s*\))', 

828 bygroups(using(this), Name.Variable.Class, using(this))), 

829 (words(RUNTIME_FUNCTIONS, suffix=r'(?=\()'), Name.Function.Magic), 

830 (words(COMPILE_FUNCTIONS, suffix=r'(?=\()'), Name.Function.Magic), 

831 (XPP_CHARS, Name), 

832 ], 

833 'class': [ 

834 (XPP_CHARS, Name.Class, '#pop'), 

835 default('#pop'), 

836 ], 

837 'namespace': [ 

838 (r'(?=\()', Text, '#pop'), # using (resource) 

839 ('(' + XPP_CHARS + r'|\.)+', Name.Namespace, '#pop'), 

840 ] 

841 }