Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/jvm.py: 91%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

202 statements  

1""" 

2 pygments.lexers.jvm 

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

4 

5 Pygments lexers for JVM languages. 

6 

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

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11import re 

12 

13from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \ 

14 this, combined, default, words 

15from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

16 Number, Punctuation, Whitespace 

17from pygments.util import shebang_matches 

18from pygments import unistring as uni 

19 

20__all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer', 

21 'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'ClojureScriptLexer', 

22 'KotlinLexer', 'XtendLexer', 'AspectJLexer', 'CeylonLexer', 

23 'PigLexer', 'GoloLexer', 'JasminLexer', 'SarlLexer'] 

24 

25 

26class JavaLexer(RegexLexer): 

27 """ 

28 For Java source code. 

29 """ 

30 

31 name = 'Java' 

32 url = 'https://www.oracle.com/technetwork/java/' 

33 aliases = ['java'] 

34 filenames = ['*.java'] 

35 mimetypes = ['text/x-java'] 

36 version_added = '' 

37 

38 flags = re.MULTILINE | re.DOTALL 

39 

40 tokens = { 

41 'root': [ 

42 (r'(^\s*)((?:(?:public|private|protected|static|strictfp)(?:\s+))*)(record)\b', 

43 bygroups(Whitespace, using(this), Keyword.Declaration), 'class'), 

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

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

46 (r'/\*.*?\*/', Comment.Multiline), 

47 # keywords: go before method names to avoid lexing "throw new XYZ" 

48 # as a method signature 

49 (r'(assert|break|case|catch|continue|default|do|else|finally|for|' 

50 r'if|goto|instanceof|new|return|switch|this|throw|try|while)\b', 

51 Keyword), 

52 # method names 

53 (r'((?:(?:[^\W\d]|\$)[\w.\[\]$<>?]*\s+)+?)' # return arguments 

54 r'((?:[^\W\d]|\$)[\w$]*)' # method name 

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

56 bygroups(using(this), Name.Function, Whitespace, Punctuation)), 

57 (r'@[^\W\d][\w.]*', Name.Decorator), 

58 (r'(abstract|const|enum|exports|extends|final|implements|native|non-sealed|' 

59 r'open|opens|permits|private|protected|provides|public|requires|sealed|static|strictfp|' 

60 r'super|synchronized|throws|to|transient|transitive|uses|volatile|with|yield)\b', Keyword.Declaration), 

61 (r'(boolean|byte|char|double|float|int|long|short|void)\b', 

62 Keyword.Type), 

63 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'), 

64 (r'(true|false|null)\b', Keyword.Constant), 

65 (r'(class|interface)\b', Keyword.Declaration, 'class'), 

66 (r'(module)\b', Keyword.Declaration, 'module'), 

67 (r'(var)(\s+)', bygroups(Keyword.Declaration, Whitespace), 'var'), 

68 (r'(import(?:\s+(?:static|module))?)(\s+)', bygroups(Keyword.Namespace, Whitespace), 

69 'import'), 

70 (r'"""\n', String, 'multiline_string'), 

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

72 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char), 

73 (r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Punctuation, 

74 Name.Attribute)), 

75 (r'^(\s*)(default)(:)', bygroups(Whitespace, Keyword, Punctuation)), 

76 (r'^(\s*)((?:[^\W\d]|\$)[\w$]*)(:)', bygroups(Whitespace, Name.Label, 

77 Punctuation)), 

78 (r'([^\W\d]|\$)[\w$]*', Name), 

79 (r'([0-9][0-9_]*\.([0-9][0-9_]*)?|' 

80 r'\.[0-9][0-9_]*)' 

81 r'([eE][+\-]?[0-9][0-9_]*)?[fFdD]?|' 

82 r'[0-9][eE][+\-]?[0-9][0-9_]*[fFdD]?|' 

83 r'[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFdD]|' 

84 r'0[xX]([0-9a-fA-F][0-9a-fA-F_]*\.?|' 

85 r'([0-9a-fA-F][0-9a-fA-F_]*)?\.[0-9a-fA-F][0-9a-fA-F_]*)' 

86 r'[pP][+\-]?[0-9][0-9_]*[fFdD]?', Number.Float), 

87 (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?', Number.Hex), 

88 (r'0[bB][01][01_]*[lL]?', Number.Bin), 

89 (r'0[0-7_]+[lL]?', Number.Oct), 

90 (r'0|[1-9][0-9_]*[lL]?', Number.Integer), 

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

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

93 (r'\n', Whitespace) 

94 ], 

95 'class': [ 

96 (r'\s+', Text), 

97 (r'([^\W\d]|\$)[\w$]*', Name.Class, '#pop') 

98 ], 

99 'module': [ 

100 (r'\s+', Text), 

101 (r'([^\W\d]|\$)[\w$]*', Name.Class, '#pop') 

102 ], 

103 'var': [ 

104 (r'([^\W\d]|\$)[\w$]*', Name, '#pop') 

105 ], 

106 'import': [ 

107 (r'[\w.]+\*?', Name.Namespace, '#pop') 

108 ], 

109 'multiline_string': [ 

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

111 (r'"', String), 

112 include('string') 

113 ], 

114 'string': [ 

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

116 (r'\\\\', String), # Escaped backslash 

117 (r'\\"', String), # Escaped quote 

118 (r'\\', String), # Bare backslash 

119 (r'"', String, '#pop'), # Closing quote 

120 ], 

121 } 

122 

123 

124class AspectJLexer(JavaLexer): 

125 """ 

126 For AspectJ source code. 

127 """ 

128 

129 name = 'AspectJ' 

130 url = 'http://www.eclipse.org/aspectj/' 

131 aliases = ['aspectj'] 

132 filenames = ['*.aj'] 

133 mimetypes = ['text/x-aspectj'] 

134 version_added = '1.6' 

135 

136 aj_keywords = { 

137 'aspect', 'pointcut', 'privileged', 'call', 'execution', 

138 'initialization', 'preinitialization', 'handler', 'get', 'set', 

139 'staticinitialization', 'target', 'args', 'within', 'withincode', 

140 'cflow', 'cflowbelow', 'annotation', 'before', 'after', 'around', 

141 'proceed', 'throwing', 'returning', 'adviceexecution', 'declare', 

142 'parents', 'warning', 'error', 'soft', 'precedence', 'thisJoinPoint', 

143 'thisJoinPointStaticPart', 'thisEnclosingJoinPointStaticPart', 

144 'issingleton', 'perthis', 'pertarget', 'percflow', 'percflowbelow', 

145 'pertypewithin', 'lock', 'unlock', 'thisAspectInstance' 

146 } 

147 aj_inter_type = {'parents:', 'warning:', 'error:', 'soft:', 'precedence:'} 

148 aj_inter_type_annotation = {'@type', '@method', '@constructor', '@field'} 

149 

150 def get_tokens_unprocessed(self, text): 

151 for index, token, value in JavaLexer.get_tokens_unprocessed(self, text): 

152 if token is Name and value in self.aj_keywords: 

153 yield index, Keyword, value 

154 elif token is Name.Label and value in self.aj_inter_type: 

155 yield index, Keyword, value[:-1] 

156 yield index, Operator, value[-1] 

157 elif token is Name.Decorator and value in self.aj_inter_type_annotation: 

158 yield index, Keyword, value 

159 else: 

160 yield index, token, value 

161 

162 

163class ScalaLexer(RegexLexer): 

164 """ 

165 For Scala source code. 

166 """ 

167 

168 name = 'Scala' 

169 url = 'http://www.scala-lang.org' 

170 aliases = ['scala'] 

171 filenames = ['*.scala'] 

172 mimetypes = ['text/x-scala'] 

173 version_added = '' 

174 

175 flags = re.MULTILINE | re.DOTALL 

176 

177 opchar = '[!#%&*\\-\\/:?@^' + uni.combine('Sm', 'So') + ']' 

178 letter = '[_\\$' + uni.combine('Ll', 'Lu', 'Lo', 'Nl', 'Lt') + ']' 

179 upperLetter = '[' + uni.combine('Lu', 'Lt') + ']' 

180 letterOrDigit = f'(?:{letter}|[0-9])' 

181 letterOrDigitNoDollarSign = '(?:{}|[0-9])'.format(letter.replace('\\$', '')) 

182 alphaId = f'{letter}+' 

183 simpleInterpolatedVariable = f'{letter}{letterOrDigitNoDollarSign}*' 

184 idrest = f'{letter}{letterOrDigit}*(?:(?<=_){opchar}+)?' 

185 idUpper = f'{upperLetter}{letterOrDigit}*(?:(?<=_){opchar}+)?' 

186 plainid = f'(?:{idrest}|{opchar}+)' 

187 backQuotedId = r'`[^`]+`' 

188 anyId = rf'(?:{plainid}|{backQuotedId})' 

189 notStartOfComment = r'(?!//|/\*)' 

190 endOfLineMaybeWithComment = r'(?=\s*(//|$))' 

191 

192 keywords = ( 

193 'new', 'return', 'throw', 'classOf', 'isInstanceOf', 'asInstanceOf', 

194 'else', 'if', 'then', 'do', 'while', 'for', 'yield', 'match', 'case', 

195 'catch', 'finally', 'try' 

196 ) 

197 

198 operators = ( 

199 '<%', '=:=', '<:<', '<%<', '>:', '<:', '=', '==', '!=', '<=', '>=', 

200 '<>', '<', '>', '<-', '←', '->', '→', '=>', '⇒', '?', '@', '|', '-', 

201 '+', '*', '%', '~', '\\' 

202 ) 

203 

204 storage_modifiers = ( 

205 'private', 'protected', 'synchronized', '@volatile', 'abstract', 

206 'final', 'lazy', 'sealed', 'implicit', 'override', '@transient', 

207 '@native' 

208 ) 

209 

210 tokens = { 

211 'root': [ 

212 include('whitespace'), 

213 include('comments'), 

214 include('script-header'), 

215 include('imports'), 

216 include('exports'), 

217 include('storage-modifiers'), 

218 include('annotations'), 

219 include('using'), 

220 include('declarations'), 

221 include('inheritance'), 

222 include('extension'), 

223 include('end'), 

224 include('constants'), 

225 include('strings'), 

226 include('symbols'), 

227 include('singleton-type'), 

228 include('inline'), 

229 include('quoted'), 

230 include('keywords'), 

231 include('operators'), 

232 include('punctuation'), 

233 include('names'), 

234 ], 

235 

236 # Includes: 

237 'whitespace': [ 

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

239 ], 

240 'comments': [ 

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

242 (r'/\*', Comment.Multiline, 'comment'), 

243 ], 

244 'script-header': [ 

245 (r'^#!([^\n]*)$', Comment.Hashbang), 

246 ], 

247 'imports': [ 

248 (r'\b(import)(\s+)', bygroups(Keyword, Whitespace), 'import-path'), 

249 ], 

250 'exports': [ 

251 (r'\b(export)(\s+)(given)(\s+)', 

252 bygroups(Keyword, Whitespace, Keyword, Whitespace), 'export-path'), 

253 (r'\b(export)(\s+)', bygroups(Keyword, Whitespace), 'export-path'), 

254 ], 

255 'storage-modifiers': [ 

256 (words(storage_modifiers, prefix=r'\b', suffix=r'\b'), Keyword), 

257 # Only highlight soft modifiers if they are eventually followed by 

258 # the correct keyword. Note that soft modifiers can be followed by a 

259 # sequence of regular modifiers; [a-z\s]* skips those, and we just 

260 # check that the soft modifier is applied to a supported statement. 

261 (r'\b(transparent|opaque|infix|open|inline)\b(?=[a-z\s]*\b' 

262 r'(def|val|var|given|type|class|trait|object|enum)\b)', Keyword), 

263 ], 

264 'annotations': [ 

265 (rf'@{idrest}', Name.Decorator), 

266 ], 

267 'using': [ 

268 # using is a soft keyword, can only be used in the first position of 

269 # a parameter or argument list. 

270 (r'(\()(\s*)(using)(\s)', bygroups(Punctuation, Whitespace, Keyword, Whitespace)), 

271 ], 

272 'declarations': [ 

273 (rf'\b(def)\b(\s*){notStartOfComment}({anyId})?', 

274 bygroups(Keyword, Whitespace, Name.Function)), 

275 (rf'\b(trait)\b(\s*){notStartOfComment}({anyId})?', 

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

277 (rf'\b(?:(case)(\s+))?(class|object|enum)\b(\s*){notStartOfComment}({anyId})?', 

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

279 (rf'(?<!\.)\b(type)\b(\s*){notStartOfComment}({anyId})?', 

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

281 (r'\b(val|var)\b', Keyword.Declaration), 

282 (rf'\b(package)(\s+)(object)\b(\s*){notStartOfComment}({anyId})?', 

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

284 (r'\b(package)(\s+)', bygroups(Keyword, Whitespace), 'package'), 

285 (rf'\b(given)\b(\s*)({idUpper})', 

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

287 (rf'\b(given)\b(\s*)({anyId})?', 

288 bygroups(Keyword, Whitespace, Name)), 

289 ], 

290 'inheritance': [ 

291 (r'\b(extends|with|derives)\b(\s*)' 

292 rf'({idUpper}|{backQuotedId}|(?=\([^\)]+=>)|(?={plainid})|(?="))?', 

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

294 ], 

295 'extension': [ 

296 (r'\b(extension)(\s+)(?=[\[\(])', bygroups(Keyword, Whitespace)), 

297 ], 

298 'end': [ 

299 # end is a soft keyword, should only be highlighted in certain cases 

300 (r'\b(end)(\s+)(if|while|for|match|new|extension|val|var)\b', 

301 bygroups(Keyword, Whitespace, Keyword)), 

302 (rf'\b(end)(\s+)({idUpper}){endOfLineMaybeWithComment}', 

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

304 (rf'\b(end)(\s+)({backQuotedId}|{plainid})?{endOfLineMaybeWithComment}', 

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

306 ], 

307 'punctuation': [ 

308 (r'[{}()\[\];,.]', Punctuation), 

309 (r'(?<!:):(?!:)', Punctuation), 

310 ], 

311 'keywords': [ 

312 (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword), 

313 ], 

314 'operators': [ 

315 (rf'({opchar}{{2,}})(\s+)', bygroups(Operator, Whitespace)), 

316 (r'/(?![/*])', Operator), 

317 (words(operators), Operator), 

318 (rf'(?<!{opchar})(!|&&|\|\|)(?!{opchar})', Operator), 

319 ], 

320 'constants': [ 

321 (r'\b(this|super)\b', Name.Builtin.Pseudo), 

322 (r'(true|false|null)\b', Keyword.Constant), 

323 (r'0[xX][0-9a-fA-F_]*', Number.Hex), 

324 (r'([0-9][0-9_]*\.[0-9][0-9_]*|\.[0-9][0-9_]*)' 

325 r'([eE][+-]?[0-9][0-9_]*)?[fFdD]?', Number.Float), 

326 (r'[0-9]+([eE][+-]?[0-9]+)?[fFdD]', Number.Float), 

327 (r'[0-9]+([eE][+-]?[0-9]+)[fFdD]?', Number.Float), 

328 (r'[0-9]+[lL]', Number.Integer.Long), 

329 (r'[0-9]+', Number.Integer), 

330 (r'""".*?"""(?!")', String), 

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

332 (r"(')(\\.)(')", bygroups(String.Char, String.Escape, String.Char)), 

333 (r"'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char), 

334 ], 

335 "strings": [ 

336 (r'[fs]"""', String, 'interpolated-string-triple'), 

337 (r'[fs]"', String, 'interpolated-string'), 

338 (r'raw"(\\\\|\\"|[^"])*"', String), 

339 ], 

340 'symbols': [ 

341 (rf"('{plainid})(?!')", String.Symbol), 

342 ], 

343 'singleton-type': [ 

344 (r'(\.)(type)\b', bygroups(Punctuation, Keyword)), 

345 ], 

346 'inline': [ 

347 # inline is a soft modifier, only highlighted if followed by if, 

348 # match or parameters. 

349 (rf'\b(inline)(?=\s+({plainid}|{backQuotedId})\s*:)', 

350 Keyword), 

351 (r'\b(inline)\b(?=(?:.(?!\b(?:val|def|given)\b))*\b(if|match)\b)', 

352 Keyword), 

353 ], 

354 'quoted': [ 

355 # '{...} or ${...} 

356 (r"['$]\{(?!')", Punctuation), 

357 # '[...] 

358 (r"'\[(?!')", Punctuation), 

359 ], 

360 'names': [ 

361 (idUpper, Name.Class), 

362 (anyId, Name), 

363 ], 

364 

365 # States 

366 'comment': [ 

367 (r'[^/*]+', Comment.Multiline), 

368 (r'/\*', Comment.Multiline, '#push'), 

369 (r'\*/', Comment.Multiline, '#pop'), 

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

371 ], 

372 'import-path': [ 

373 (r'(?<=[\n;:])', Text, '#pop'), 

374 include('comments'), 

375 (r'\b(given)\b', Keyword), 

376 include('qualified-name'), 

377 (r'\{', Punctuation, 'import-path-curly-brace'), 

378 ], 

379 'import-path-curly-brace': [ 

380 include('whitespace'), 

381 include('comments'), 

382 (r'\b(given)\b', Keyword), 

383 (r'=>', Operator), 

384 (r'\}', Punctuation, '#pop'), 

385 (r',', Punctuation), 

386 (r'[\[\]]', Punctuation), 

387 include('qualified-name'), 

388 ], 

389 'export-path': [ 

390 (r'(?<=[\n;:])', Text, '#pop'), 

391 include('comments'), 

392 include('qualified-name'), 

393 (r'\{', Punctuation, 'export-path-curly-brace'), 

394 ], 

395 'export-path-curly-brace': [ 

396 include('whitespace'), 

397 include('comments'), 

398 (r'=>', Operator), 

399 (r'\}', Punctuation, '#pop'), 

400 (r',', Punctuation), 

401 include('qualified-name'), 

402 ], 

403 'package': [ 

404 (r'(?<=[\n;])', Text, '#pop'), 

405 (r':', Punctuation, '#pop'), 

406 include('comments'), 

407 include('qualified-name'), 

408 ], 

409 'interpolated-string-triple': [ 

410 (r'"""(?!")', String, '#pop'), 

411 (r'"', String), 

412 include('interpolated-string-common'), 

413 ], 

414 'interpolated-string': [ 

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

416 include('interpolated-string-common'), 

417 ], 

418 'interpolated-string-brace': [ 

419 (r'\}', String.Interpol, '#pop'), 

420 (r'\{', Punctuation, 'interpolated-string-nested-brace'), 

421 include('root'), 

422 ], 

423 'interpolated-string-nested-brace': [ 

424 (r'\{', Punctuation, '#push'), 

425 (r'\}', Punctuation, '#pop'), 

426 include('root'), 

427 ], 

428 

429 # Helpers 

430 'qualified-name': [ 

431 (idUpper, Name.Class), 

432 (rf'({anyId})(\.)', bygroups(Name.Namespace, Punctuation)), 

433 (r'\.', Punctuation), 

434 (anyId, Name), 

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

436 ], 

437 'interpolated-string-common': [ 

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

439 (r'\$\$', String.Escape), 

440 (rf'(\$)({simpleInterpolatedVariable})', 

441 bygroups(String.Interpol, Name)), 

442 (r'\$\{', String.Interpol, 'interpolated-string-brace'), 

443 (r'\\.', String), 

444 ], 

445 } 

446 

447 

448class GosuLexer(RegexLexer): 

449 """ 

450 For Gosu source code. 

451 """ 

452 

453 name = 'Gosu' 

454 aliases = ['gosu'] 

455 filenames = ['*.gs', '*.gsx', '*.gsp', '*.vark'] 

456 mimetypes = ['text/x-gosu'] 

457 url = 'https://gosu-lang.github.io' 

458 version_added = '1.5' 

459 

460 flags = re.MULTILINE | re.DOTALL 

461 

462 tokens = { 

463 'root': [ 

464 # method names 

465 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # modifiers etc. 

466 r'([a-zA-Z_]\w*)' # method name 

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

468 bygroups(using(this), Name.Function, Whitespace, Operator)), 

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

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

471 (r'/\*.*?\*/', Comment.Multiline), 

472 (r'@[a-zA-Z_][\w.]*', Name.Decorator), 

473 (r'(in|as|typeof|statictypeof|typeis|typeas|if|else|foreach|for|' 

474 r'index|while|do|continue|break|return|try|catch|finally|this|' 

475 r'throw|new|switch|case|default|eval|super|outer|classpath|' 

476 r'using)\b', Keyword), 

477 (r'(var|delegate|construct|function|private|internal|protected|' 

478 r'public|abstract|override|final|static|extends|transient|' 

479 r'implements|represents|readonly)\b', Keyword.Declaration), 

480 (r'(property)(\s+)(get|set)?', bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration)), 

481 (r'(boolean|byte|char|double|float|int|long|short|void|block)\b', 

482 Keyword.Type), 

483 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace)), 

484 (r'(true|false|null|NaN|Infinity)\b', Keyword.Constant), 

485 (r'(class|interface|enhancement|enum)(\s+)([a-zA-Z_]\w*)', 

486 bygroups(Keyword.Declaration, Whitespace, Name.Class)), 

487 (r'(uses)(\s+)([\w.]+\*?)', 

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

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

490 (r'(\??[.#])([a-zA-Z_]\w*)', 

491 bygroups(Operator, Name.Attribute)), 

492 (r'(:)([a-zA-Z_]\w*)', 

493 bygroups(Operator, Name.Attribute)), 

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

495 (r'and|or|not|[\\~^*!%&\[\](){}<>|+=:;,./?-]', Operator), 

496 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

497 (r'[0-9]+', Number.Integer), 

498 (r'\n', Whitespace) 

499 ], 

500 'templateText': [ 

501 (r'(\\<)|(\\\$)', String), 

502 (r'(<%@\s+)(extends|params)', 

503 bygroups(Operator, Name.Decorator), 'stringTemplate'), 

504 (r'<%!--.*?--%>', Comment.Multiline), 

505 (r'(<%)|(<%=)', Operator, 'stringTemplate'), 

506 (r'\$\{', Operator, 'stringTemplateShorthand'), 

507 (r'.', String) 

508 ], 

509 'string': [ 

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

511 include('templateText') 

512 ], 

513 'stringTemplate': [ 

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

515 (r'%>', Operator, '#pop'), 

516 include('root') 

517 ], 

518 'stringTemplateShorthand': [ 

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

520 (r'\{', Operator, 'stringTemplateShorthand'), 

521 (r'\}', Operator, '#pop'), 

522 include('root') 

523 ], 

524 } 

525 

526 

527class GosuTemplateLexer(Lexer): 

528 """ 

529 For Gosu templates. 

530 """ 

531 

532 name = 'Gosu Template' 

533 aliases = ['gst'] 

534 filenames = ['*.gst'] 

535 mimetypes = ['text/x-gosu-template'] 

536 url = 'https://gosu-lang.github.io' 

537 version_added = '1.5' 

538 

539 def get_tokens_unprocessed(self, text): 

540 lexer = GosuLexer() 

541 stack = ['templateText'] 

542 yield from lexer.get_tokens_unprocessed(text, stack) 

543 

544 

545class GroovyLexer(RegexLexer): 

546 """ 

547 For Groovy source code. 

548 """ 

549 

550 name = 'Groovy' 

551 url = 'https://groovy-lang.org/' 

552 aliases = ['groovy'] 

553 filenames = ['*.groovy','*.gradle'] 

554 mimetypes = ['text/x-groovy'] 

555 version_added = '1.5' 

556 

557 flags = re.MULTILINE | re.DOTALL 

558 

559 tokens = { 

560 'root': [ 

561 # Groovy allows a file to start with a shebang 

562 (r'#!(.*?)$', Comment.Preproc, 'base'), 

563 default('base'), 

564 ], 

565 'base': [ 

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

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

568 (r'/\*.*?\*/', Comment.Multiline), 

569 # keywords: go before method names to avoid lexing "throw new XYZ" 

570 # as a method signature 

571 (r'(assert|break|case|catch|continue|default|do|else|finally|for|' 

572 r'if|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b', 

573 Keyword), 

574 # method names 

575 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments 

576 r'(' 

577 r'[a-zA-Z_]\w*' # method name 

578 r'|"(?:\\\\|\\[^\\]|[^"\\])*"' # or double-quoted method name 

579 r"|'(?:\\\\|\\[^\\]|[^'\\])*'" # or single-quoted method name 

580 r')' 

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

582 bygroups(using(this), Name.Function, Whitespace, Operator)), 

583 (r'@[a-zA-Z_][\w.]*', Name.Decorator), 

584 (r'(abstract|const|enum|extends|final|implements|native|private|' 

585 r'protected|public|static|strictfp|super|synchronized|throws|' 

586 r'transient|volatile)\b', Keyword.Declaration), 

587 (r'(def|boolean|byte|char|double|float|int|long|short|void)\b', 

588 Keyword.Type), 

589 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace)), 

590 (r'(true|false|null)\b', Keyword.Constant), 

591 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Whitespace), 

592 'class'), 

593 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'), 

594 (r'""".*?"""', String.Double), 

595 (r"'''.*?'''", String.Single), 

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

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

598 (r'\$/((?!/\$).)*/\$', String), 

599 (r'/(\\\\|\\[^\\]|[^/\\])*/', String), 

600 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char), 

601 (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)), 

602 (r'[a-zA-Z_]\w*:', Name.Label), 

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

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

605 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

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

607 (r'[0-9]+L?', Number.Integer), 

608 (r'\n', Whitespace) 

609 ], 

610 'class': [ 

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

612 ], 

613 'import': [ 

614 (r'[\w.]+\*?', Name.Namespace, '#pop') 

615 ], 

616 } 

617 

618 def analyse_text(text): 

619 return shebang_matches(text, r'groovy') 

620 

621 

622class IokeLexer(RegexLexer): 

623 """ 

624 For Ioke (a strongly typed, dynamic, 

625 prototype based programming language) source. 

626 """ 

627 name = 'Ioke' 

628 url = 'https://ioke.org/' 

629 filenames = ['*.ik'] 

630 aliases = ['ioke', 'ik'] 

631 mimetypes = ['text/x-iokesrc'] 

632 version_added = '1.4' 

633 tokens = { 

634 'interpolatableText': [ 

635 (r'(\\b|\\e|\\t|\\n|\\f|\\r|\\"|\\\\|\\#|\\\Z|\\u[0-9a-fA-F]{1,4}' 

636 r'|\\[0-3]?[0-7]?[0-7])', String.Escape), 

637 (r'#\{', Punctuation, 'textInterpolationRoot') 

638 ], 

639 

640 'text': [ 

641 (r'(?<!\\)"', String, '#pop'), 

642 include('interpolatableText'), 

643 (r'[^"]', String) 

644 ], 

645 

646 'documentation': [ 

647 (r'(?<!\\)"', String.Doc, '#pop'), 

648 include('interpolatableText'), 

649 (r'[^"]', String.Doc) 

650 ], 

651 

652 'textInterpolationRoot': [ 

653 (r'\}', Punctuation, '#pop'), 

654 include('root') 

655 ], 

656 

657 'slashRegexp': [ 

658 (r'(?<!\\)/[im-psux]*', String.Regex, '#pop'), 

659 include('interpolatableText'), 

660 (r'\\/', String.Regex), 

661 (r'[^/]', String.Regex) 

662 ], 

663 

664 'squareRegexp': [ 

665 (r'(?<!\\)][im-psux]*', String.Regex, '#pop'), 

666 include('interpolatableText'), 

667 (r'\\]', String.Regex), 

668 (r'[^\]]', String.Regex) 

669 ], 

670 

671 'squareText': [ 

672 (r'(?<!\\)]', String, '#pop'), 

673 include('interpolatableText'), 

674 (r'[^\]]', String) 

675 ], 

676 

677 'root': [ 

678 (r'\n', Whitespace), 

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

680 

681 # Comments 

682 (r';(.*?)\n', Comment), 

683 (r'\A#!(.*?)\n', Comment), 

684 

685 # Regexps 

686 (r'#/', String.Regex, 'slashRegexp'), 

687 (r'#r\[', String.Regex, 'squareRegexp'), 

688 

689 # Symbols 

690 (r':[\w!:?]+', String.Symbol), 

691 (r'[\w!:?]+:(?![\w!?])', String.Other), 

692 (r':"(\\\\|\\[^\\]|[^"\\])*"', String.Symbol), 

693 

694 # Documentation 

695 (r'((?<=fn\()|(?<=fnx\()|(?<=method\()|(?<=macro\()|(?<=lecro\()' 

696 r'|(?<=syntax\()|(?<=dmacro\()|(?<=dlecro\()|(?<=dlecrox\()' 

697 r'|(?<=dsyntax\())(\s*)"', String.Doc, 'documentation'), 

698 

699 # Text 

700 (r'"', String, 'text'), 

701 (r'#\[', String, 'squareText'), 

702 

703 # Mimic 

704 (r'\w[\w!:?]+(?=\s*=.*mimic\s)', Name.Entity), 

705 

706 # Assignment 

707 (r'[a-zA-Z_][\w!:?]*(?=[\s]*[+*/-]?=[^=].*($|\.))', 

708 Name.Variable), 

709 

710 # keywords 

711 (r'(break|cond|continue|do|ensure|for|for:dict|for:set|if|let|' 

712 r'loop|p:for|p:for:dict|p:for:set|return|unless|until|while|' 

713 r'with)(?![\w!:?])', Keyword.Reserved), 

714 

715 # Origin 

716 (r'(eval|mimic|print|println)(?![\w!:?])', Keyword), 

717 

718 # Base 

719 (r'(cell\?|cellNames|cellOwner\?|cellOwner|cells|cell|' 

720 r'documentation|hash|identity|mimic|removeCell\!|undefineCell\!)' 

721 r'(?![\w!:?])', Keyword), 

722 

723 # Ground 

724 (r'(stackTraceAsText)(?![\w!:?])', Keyword), 

725 

726 # DefaultBehaviour Literals 

727 (r'(dict|list|message|set)(?![\w!:?])', Keyword.Reserved), 

728 

729 # DefaultBehaviour Case 

730 (r'(case|case:and|case:else|case:nand|case:nor|case:not|case:or|' 

731 r'case:otherwise|case:xor)(?![\w!:?])', Keyword.Reserved), 

732 

733 # DefaultBehaviour Reflection 

734 (r'(asText|become\!|derive|freeze\!|frozen\?|in\?|is\?|kind\?|' 

735 r'mimic\!|mimics|mimics\?|prependMimic\!|removeAllMimics\!|' 

736 r'removeMimic\!|same\?|send|thaw\!|uniqueHexId)' 

737 r'(?![\w!:?])', Keyword), 

738 

739 # DefaultBehaviour Aspects 

740 (r'(after|around|before)(?![\w!:?])', Keyword.Reserved), 

741 

742 # DefaultBehaviour 

743 (r'(kind|cellDescriptionDict|cellSummary|genSym|inspect|notice)' 

744 r'(?![\w!:?])', Keyword), 

745 (r'(use|destructuring)', Keyword.Reserved), 

746 

747 # DefaultBehavior BaseBehavior 

748 (r'(cell\?|cellOwner\?|cellOwner|cellNames|cells|cell|' 

749 r'documentation|identity|removeCell!|undefineCell)' 

750 r'(?![\w!:?])', Keyword), 

751 

752 # DefaultBehavior Internal 

753 (r'(internal:compositeRegexp|internal:concatenateText|' 

754 r'internal:createDecimal|internal:createNumber|' 

755 r'internal:createRegexp|internal:createText)' 

756 r'(?![\w!:?])', Keyword.Reserved), 

757 

758 # DefaultBehaviour Conditions 

759 (r'(availableRestarts|bind|error\!|findRestart|handle|' 

760 r'invokeRestart|rescue|restart|signal\!|warn\!)' 

761 r'(?![\w!:?])', Keyword.Reserved), 

762 

763 # constants 

764 (r'(nil|false|true)(?![\w!:?])', Name.Constant), 

765 

766 # names 

767 (r'(Arity|Base|Call|Condition|DateTime|Aspects|Pointcut|' 

768 r'Assignment|BaseBehavior|Boolean|Case|AndCombiner|Else|' 

769 r'NAndCombiner|NOrCombiner|NotCombiner|OrCombiner|XOrCombiner|' 

770 r'Conditions|Definitions|FlowControl|Internal|Literals|' 

771 r'Reflection|DefaultMacro|DefaultMethod|DefaultSyntax|Dict|' 

772 r'FileSystem|Ground|Handler|Hook|IO|IokeGround|Struct|' 

773 r'LexicalBlock|LexicalMacro|List|Message|Method|Mixins|' 

774 r'NativeMethod|Number|Origin|Pair|Range|Reflector|Regexp Match|' 

775 r'Regexp|Rescue|Restart|Runtime|Sequence|Set|Symbol|' 

776 r'System|Text|Tuple)(?![\w!:?])', Name.Builtin), 

777 

778 # functions 

779 ('(generateMatchMethod|aliasMethod|\u03bb|\u028E|fnx|fn|method|' 

780 'dmacro|dlecro|syntax|macro|dlecrox|lecrox|lecro|syntax)' 

781 '(?![\\w!:?])', Name.Function), 

782 

783 # Numbers 

784 (r'-?0[xX][0-9a-fA-F]+', Number.Hex), 

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

786 (r'-?\d+', Number.Integer), 

787 

788 (r'#\(', Punctuation), 

789 

790 # Operators 

791 (r'(&&>>|\|\|>>|\*\*>>|:::|::|\.\.\.|===|\*\*>|\*\*=|&&>|&&=|' 

792 r'\|\|>|\|\|=|\->>|\+>>|!>>|<>>>|<>>|&>>|%>>|#>>|@>>|/>>|\*>>|' 

793 r'\?>>|\|>>|\^>>|~>>|\$>>|=>>|<<=|>>=|<=>|<\->|=~|!~|=>|\+\+|' 

794 r'\-\-|<=|>=|==|!=|&&|\.\.|\+=|\-=|\*=|\/=|%=|&=|\^=|\|=|<\-|' 

795 r'\+>|!>|<>|&>|%>|#>|\@>|\/>|\*>|\?>|\|>|\^>|~>|\$>|<\->|\->|' 

796 r'<<|>>|\*\*|\?\||\?&|\|\||>|<|\*|\/|%|\+|\-|&|\^|\||=|\$|!|~|' 

797 r'\?|#|\u2260|\u2218|\u2208|\u2209)', Operator), 

798 (r'(and|nand|or|xor|nor|return|import)(?![\w!?])', 

799 Operator), 

800 

801 # Punctuation 

802 (r'(\`\`|\`|\'\'|\'|\.|\,|@@|@|\[|\]|\(|\)|\{|\})', Punctuation), 

803 

804 # kinds 

805 (r'[A-Z][\w!:?]*', Name.Class), 

806 

807 # default cellnames 

808 (r'[a-z_][\w!:?]*', Name) 

809 ] 

810 } 

811 

812 

813class ClojureLexer(RegexLexer): 

814 """ 

815 Lexer for Clojure source code. 

816 """ 

817 name = 'Clojure' 

818 url = 'http://clojure.org/' 

819 aliases = ['clojure', 'clj'] 

820 filenames = ['*.clj', '*.cljc'] 

821 mimetypes = ['text/x-clojure', 'application/x-clojure'] 

822 version_added = '0.11' 

823 

824 special_forms = ( 

825 '.', 'def', 'do', 'fn', 'if', 'let', 'new', 'quote', 'var', 'loop' 

826 ) 

827 

828 # It's safe to consider 'ns' a declaration thing because it defines a new 

829 # namespace. 

830 declarations = ( 

831 'def-', 'defn', 'defn-', 'defmacro', 'defmulti', 'defmethod', 

832 'defstruct', 'defonce', 'declare', 'definline', 'definterface', 

833 'defprotocol', 'defrecord', 'deftype', 'defproject', 'ns' 

834 ) 

835 

836 builtins = ( 

837 '*', '+', '-', '->', '/', '<', '<=', '=', '==', '>', '>=', '..', 

838 'accessor', 'agent', 'agent-errors', 'aget', 'alength', 'all-ns', 

839 'alter', 'and', 'append-child', 'apply', 'array-map', 'aset', 

840 'aset-boolean', 'aset-byte', 'aset-char', 'aset-double', 'aset-float', 

841 'aset-int', 'aset-long', 'aset-short', 'assert', 'assoc', 'await', 

842 'await-for', 'bean', 'binding', 'bit-and', 'bit-not', 'bit-or', 

843 'bit-shift-left', 'bit-shift-right', 'bit-xor', 'boolean', 'branch?', 

844 'butlast', 'byte', 'cast', 'char', 'children', 'class', 

845 'clear-agent-errors', 'comment', 'commute', 'comp', 'comparator', 

846 'complement', 'concat', 'conj', 'cons', 'constantly', 'cond', 'if-not', 

847 'construct-proxy', 'contains?', 'count', 'create-ns', 'create-struct', 

848 'cycle', 'dec', 'deref', 'difference', 'disj', 'dissoc', 'distinct', 

849 'doall', 'doc', 'dorun', 'doseq', 'dosync', 'dotimes', 'doto', 

850 'double', 'down', 'drop', 'drop-while', 'edit', 'end?', 'ensure', 

851 'eval', 'every?', 'false?', 'ffirst', 'file-seq', 'filter', 'find', 

852 'find-doc', 'find-ns', 'find-var', 'first', 'float', 'flush', 'for', 

853 'fnseq', 'frest', 'gensym', 'get-proxy-class', 'get', 

854 'hash-map', 'hash-set', 'identical?', 'identity', 'if-let', 'import', 

855 'in-ns', 'inc', 'index', 'insert-child', 'insert-left', 'insert-right', 

856 'inspect-table', 'inspect-tree', 'instance?', 'int', 'interleave', 

857 'intersection', 'into', 'into-array', 'iterate', 'join', 'key', 'keys', 

858 'keyword', 'keyword?', 'last', 'lazy-cat', 'lazy-cons', 'left', 

859 'lefts', 'line-seq', 'list*', 'list', 'load', 'load-file', 

860 'locking', 'long', 'loop', 'macroexpand', 'macroexpand-1', 

861 'make-array', 'make-node', 'map', 'map-invert', 'map?', 'mapcat', 

862 'max', 'max-key', 'memfn', 'merge', 'merge-with', 'meta', 'min', 

863 'min-key', 'name', 'namespace', 'neg?', 'new', 'newline', 'next', 

864 'nil?', 'node', 'not', 'not-any?', 'not-every?', 'not=', 'ns-imports', 

865 'ns-interns', 'ns-map', 'ns-name', 'ns-publics', 'ns-refers', 

866 'ns-resolve', 'ns-unmap', 'nth', 'nthrest', 'or', 'parse', 'partial', 

867 'path', 'peek', 'pop', 'pos?', 'pr', 'pr-str', 'print', 'print-str', 

868 'println', 'println-str', 'prn', 'prn-str', 'project', 'proxy', 

869 'proxy-mappings', 'quot', 'rand', 'rand-int', 'range', 're-find', 

870 're-groups', 're-matcher', 're-matches', 're-pattern', 're-seq', 

871 'read', 'read-line', 'reduce', 'ref', 'ref-set', 'refer', 'rem', 

872 'remove', 'remove-method', 'remove-ns', 'rename', 'rename-keys', 

873 'repeat', 'replace', 'replicate', 'resolve', 'rest', 'resultset-seq', 

874 'reverse', 'rfirst', 'right', 'rights', 'root', 'rrest', 'rseq', 

875 'second', 'select', 'select-keys', 'send', 'send-off', 'seq', 

876 'seq-zip', 'seq?', 'set', 'short', 'slurp', 'some', 'sort', 

877 'sort-by', 'sorted-map', 'sorted-map-by', 'sorted-set', 

878 'special-symbol?', 'split-at', 'split-with', 'str', 'string?', 

879 'struct', 'struct-map', 'subs', 'subvec', 'symbol', 'symbol?', 

880 'sync', 'take', 'take-nth', 'take-while', 'test', 'time', 'to-array', 

881 'to-array-2d', 'tree-seq', 'true?', 'union', 'up', 'update-proxy', 

882 'val', 'vals', 'var-get', 'var-set', 'var?', 'vector', 'vector-zip', 

883 'vector?', 'when', 'when-first', 'when-let', 'when-not', 

884 'with-local-vars', 'with-meta', 'with-open', 'with-out-str', 

885 'xml-seq', 'xml-zip', 'zero?', 'zipmap', 'zipper') 

886 

887 # valid names for identifiers 

888 # well, names can only not consist fully of numbers 

889 # but this should be good enough for now 

890 

891 # TODO / should divide keywords/symbols into namespace/rest 

892 # but that's hard, so just pretend / is part of the name 

893 valid_name = r'(?!#)[\w!$%*+<=>?/.#|-]+' 

894 

895 tokens = { 

896 'root': [ 

897 # the comments - always starting with semicolon 

898 # and going to the end of the line 

899 (r';.*$', Comment.Single), 

900 

901 # whitespaces - usually not relevant 

902 (r',+', Text), 

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

904 

905 # numbers 

906 (r'-?\d+\.\d+', Number.Float), 

907 (r'-?\d+/\d+', Number), 

908 (r'-?\d+', Number.Integer), 

909 (r'0x-?[abcdef\d]+', Number.Hex), 

910 

911 # strings, symbols and characters 

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

913 (r"'" + valid_name, String.Symbol), 

914 (r"\\(?:newline|space|tab|formfeed|backspace|return" 

915 r"|u[0-9a-fA-F]{4}|o[0-7]{1,3}|.)", String.Char), 

916 

917 # keywords 

918 (r'::?#?' + valid_name, String.Symbol), 

919 

920 # special operators 

921 (r'~@|[`\'#^~&@]', Operator), 

922 

923 # highlight the special forms 

924 (words(special_forms, suffix=' '), Keyword), 

925 

926 # Technically, only the special forms are 'keywords'. The problem 

927 # is that only treating them as keywords means that things like 

928 # 'defn' and 'ns' need to be highlighted as builtins. This is ugly 

929 # and weird for most styles. So, as a compromise we're going to 

930 # highlight them as Keyword.Declarations. 

931 (words(declarations, suffix=' '), Keyword.Declaration), 

932 

933 # highlight the builtins 

934 (words(builtins, suffix=' '), Name.Builtin), 

935 

936 # the remaining functions 

937 (r'(?<=\()' + valid_name, Name.Function), 

938 

939 # find the remaining variables 

940 (valid_name, Name.Variable), 

941 

942 # Clojure accepts vector notation 

943 (r'(\[|\])', Punctuation), 

944 

945 # Clojure accepts map notation 

946 (r'(\{|\})', Punctuation), 

947 

948 # the famous parentheses! 

949 (r'(\(|\))', Punctuation), 

950 ], 

951 } 

952 

953 

954class ClojureScriptLexer(ClojureLexer): 

955 """ 

956 Lexer for ClojureScript source code. 

957 """ 

958 name = 'ClojureScript' 

959 url = 'http://clojure.org/clojurescript' 

960 aliases = ['clojurescript', 'cljs'] 

961 filenames = ['*.cljs'] 

962 mimetypes = ['text/x-clojurescript', 'application/x-clojurescript'] 

963 version_added = '2.0' 

964 

965 

966class TeaLangLexer(RegexLexer): 

967 """ 

968 For Tea source code. Only used within a 

969 TeaTemplateLexer. 

970 

971 .. versionadded:: 1.5 

972 """ 

973 

974 flags = re.MULTILINE | re.DOTALL 

975 

976 tokens = { 

977 'root': [ 

978 # method names 

979 (r'^(\s*(?:[a-zA-Z_][\w\.\[\]]*\s+)+?)' # return arguments 

980 r'([a-zA-Z_]\w*)' # method name 

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

982 bygroups(using(this), Name.Function, Whitespace, Operator)), 

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

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

985 (r'/\*.*?\*/', Comment.Multiline), 

986 (r'@[a-zA-Z_][\w\.]*', Name.Decorator), 

987 (r'(and|break|else|foreach|if|in|not|or|reverse)\b', 

988 Keyword), 

989 (r'(as|call|define)\b', Keyword.Declaration), 

990 (r'(true|false|null)\b', Keyword.Constant), 

991 (r'(template)(\s+)', bygroups(Keyword.Declaration, Whitespace), 'template'), 

992 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'), 

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

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

995 (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)), 

996 (r'[a-zA-Z_]\w*:', Name.Label), 

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

998 (r'(isa|[.]{3}|[.]{2}|[=#!<>+-/%&;,.\*\\\(\)\[\]\{\}])', Operator), 

999 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

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

1001 (r'[0-9]+L?', Number.Integer), 

1002 (r'\n', Whitespace) 

1003 ], 

1004 'template': [ 

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

1006 ], 

1007 'import': [ 

1008 (r'[\w.]+\*?', Name.Namespace, '#pop') 

1009 ], 

1010 } 

1011 

1012 

1013class CeylonLexer(RegexLexer): 

1014 """ 

1015 For Ceylon source code. 

1016 """ 

1017 

1018 name = 'Ceylon' 

1019 url = 'http://ceylon-lang.org/' 

1020 aliases = ['ceylon'] 

1021 filenames = ['*.ceylon'] 

1022 mimetypes = ['text/x-ceylon'] 

1023 version_added = '1.6' 

1024 

1025 flags = re.MULTILINE | re.DOTALL 

1026 

1027 #: optional Comment or Whitespace 

1028 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+' 

1029 

1030 tokens = { 

1031 'root': [ 

1032 # method names 

1033 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments 

1034 r'([a-zA-Z_]\w*)' # method name 

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

1036 bygroups(using(this), Name.Function, Whitespace, Operator)), 

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

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

1039 (r'/\*', Comment.Multiline, 'comment'), 

1040 (r'(shared|abstract|formal|default|actual|variable|deprecated|small|' 

1041 r'late|literal|doc|by|see|throws|optional|license|tagged|final|native|' 

1042 r'annotation|sealed)\b', Name.Decorator), 

1043 (r'(break|case|catch|continue|else|finally|for|in|' 

1044 r'if|return|switch|this|throw|try|while|is|exists|dynamic|' 

1045 r'nonempty|then|outer|assert|let)\b', Keyword), 

1046 (r'(abstracts|extends|satisfies|' 

1047 r'super|given|of|out|assign)\b', Keyword.Declaration), 

1048 (r'(function|value|void|new)\b', 

1049 Keyword.Type), 

1050 (r'(assembly|module|package)(\s+)', bygroups(Keyword.Namespace, Whitespace)), 

1051 (r'(true|false|null)\b', Keyword.Constant), 

1052 (r'(class|interface|object|alias)(\s+)', 

1053 bygroups(Keyword.Declaration, Whitespace), 'class'), 

1054 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'), 

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

1056 (r"'\\.'|'[^\\]'|'\\\{#[0-9a-fA-F]{4}\}'", String.Char), 

1057 (r'(\.)([a-z_]\w*)', 

1058 bygroups(Operator, Name.Attribute)), 

1059 (r'[a-zA-Z_]\w*:', Name.Label), 

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

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

1062 (r'\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float), 

1063 (r'\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?', 

1064 Number.Float), 

1065 (r'[0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float), 

1066 (r'[0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?', 

1067 Number.Float), 

1068 (r'#([0-9a-fA-F]{4})(_[0-9a-fA-F]{4})+', Number.Hex), 

1069 (r'#[0-9a-fA-F]+', Number.Hex), 

1070 (r'\$([01]{4})(_[01]{4})+', Number.Bin), 

1071 (r'\$[01]+', Number.Bin), 

1072 (r'\d{1,3}(_\d{3})+[kMGTP]?', Number.Integer), 

1073 (r'[0-9]+[kMGTP]?', Number.Integer), 

1074 (r'\n', Whitespace) 

1075 ], 

1076 'class': [ 

1077 (r'[A-Za-z_]\w*', Name.Class, '#pop') 

1078 ], 

1079 'import': [ 

1080 (r'[a-z][\w.]*', 

1081 Name.Namespace, '#pop') 

1082 ], 

1083 'comment': [ 

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

1085 (r'/\*', Comment.Multiline, '#push'), 

1086 (r'\*/', Comment.Multiline, '#pop'), 

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

1088 ], 

1089 } 

1090 

1091 

1092class KotlinLexer(RegexLexer): 

1093 """ 

1094 For Kotlin source code. 

1095 """ 

1096 

1097 name = 'Kotlin' 

1098 url = 'http://kotlinlang.org/' 

1099 aliases = ['kotlin'] 

1100 filenames = ['*.kt', '*.kts'] 

1101 mimetypes = ['text/x-kotlin'] 

1102 version_added = '1.5' 

1103 

1104 flags = re.MULTILINE | re.DOTALL 

1105 

1106 kt_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' + 

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

1108 'Mn', 'Mc') + ']*') 

1109 

1110 kt_space_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' + 

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

1112 'Mn', 'Mc', 'Zs') 

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

1114 

1115 kt_id = '(' + kt_name + '|`' + kt_space_name + '`)' 

1116 

1117 modifiers = (r'actual|abstract|annotation|companion|const|crossinline|' 

1118 r'data|enum|expect|external|final|infix|inline|inner|' 

1119 r'internal|lateinit|noinline|open|operator|override|private|' 

1120 r'protected|public|sealed|suspend|tailrec|value') 

1121 

1122 tokens = { 

1123 'root': [ 

1124 # Whitespaces 

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

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

1127 (r'\\$', String.Escape), # line continuation 

1128 (r'\n', Whitespace), 

1129 # Comments 

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

1131 (r'^(#!/.+?)(\n)', bygroups(Comment.Single, Whitespace)), # shebang for kotlin scripts 

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

1133 # Keywords 

1134 (r'as\?', Keyword), 

1135 (r'(as|break|by|catch|constructor|continue|do|dynamic|else|finally|' 

1136 r'get|for|if|init|[!]*in|[!]*is|out|reified|return|set|super|this|' 

1137 r'throw|try|typealias|typeof|vararg|when|where|while)\b', Keyword), 

1138 (r'it\b', Name.Builtin), 

1139 # Built-in types 

1140 (words(('Boolean?', 'Byte?', 'Char?', 'Double?', 'Float?', 

1141 'Int?', 'Long?', 'Short?', 'String?', 'Any?', 'Unit?')), Keyword.Type), 

1142 (words(('Boolean', 'Byte', 'Char', 'Double', 'Float', 

1143 'Int', 'Long', 'Short', 'String', 'Any', 'Unit'), suffix=r'\b'), Keyword.Type), 

1144 # Constants 

1145 (r'(true|false|null)\b', Keyword.Constant), 

1146 # Imports 

1147 (r'(package|import)(\s+)(\S+)', bygroups(Keyword, Whitespace, Name.Namespace)), 

1148 # Dot access 

1149 (r'(\?\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Operator, Name.Attribute)), 

1150 (r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Punctuation, Name.Attribute)), 

1151 # Annotations 

1152 (r'@[^\W\d][\w.]*', Name.Decorator), 

1153 # Labels 

1154 (r'[^\W\d][\w.]+@', Name.Decorator), 

1155 # Object expression 

1156 (r'(object)(\s+)(:)(\s+)', bygroups(Keyword, Whitespace, Punctuation, Whitespace), 'class'), 

1157 # Types 

1158 (r'((?:(?:' + modifiers + r'|fun)\s+)*)(class|interface|object)(\s+)', 

1159 bygroups(using(this, state='modifiers'), Keyword.Declaration, Whitespace), 'class'), 

1160 # Variables 

1161 (r'(var|val)(\s+)(\()', bygroups(Keyword.Declaration, Whitespace, Punctuation), 

1162 'destructuring_assignment'), 

1163 (r'((?:(?:' + modifiers + r')\s+)*)(var|val)(\s+)', 

1164 bygroups(using(this, state='modifiers'), Keyword.Declaration, Whitespace), 'variable'), 

1165 # Functions 

1166 (r'((?:(?:' + modifiers + r')\s+)*)(fun)(\s+)', 

1167 bygroups(using(this, state='modifiers'), Keyword.Declaration, Whitespace), 'function'), 

1168 # Operators 

1169 (r'::|!!|\?[:.]', Operator), 

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

1171 # Punctuation 

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

1173 # Strings 

1174 (r'"""', String, 'multiline_string'), 

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

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

1177 # Numbers 

1178 (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFL]?|" 

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

1180 # Identifiers 

1181 # A trailing ``?`` marks a nullable type (e.g. ``Foo?``); use a 

1182 # negative lookahead so we don't consume the following character and 

1183 # so ``?.`` (safe call) and ``?:`` (elvis) stay separate operators. 

1184 (r'' + kt_id + r'(\?(?![.:]))?', Name) 

1185 ], 

1186 'class': [ 

1187 (r'\{', Punctuation, '#pop'), 

1188 (kt_id, Name.Class, '#pop') 

1189 ], 

1190 'variable': [ 

1191 (kt_id, Name.Variable, '#pop') 

1192 ], 

1193 'destructuring_assignment': [ 

1194 (r',', Punctuation), 

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

1196 (kt_id, Name.Variable), 

1197 (r'(:)(\s+)(' + kt_id + ')', bygroups(Punctuation, Whitespace, Name)), 

1198 (r'<', Operator, 'generic'), 

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

1200 ], 

1201 'function': [ 

1202 (r'<', Operator, 'generic'), 

1203 (r'' + kt_id + r'(\.)' + kt_id, bygroups(Name, Punctuation, Name.Function), '#pop'), 

1204 (kt_id, Name.Function, '#pop') 

1205 ], 

1206 'generic': [ 

1207 (r'(>)(\s*)', bygroups(Operator, Whitespace), '#pop'), 

1208 (r':', Punctuation), 

1209 (r'(reified|out|in)\b', Keyword), 

1210 (r',', Punctuation), 

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

1212 (kt_id, Name) 

1213 ], 

1214 'modifiers': [ 

1215 (r'\w+', Keyword.Declaration), 

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

1217 default('#pop') 

1218 ], 

1219 'string': [ 

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

1221 include('string_common') 

1222 ], 

1223 'multiline_string': [ 

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

1225 (r'"', String), 

1226 include('string_common') 

1227 ], 

1228 'string_common': [ 

1229 (r'\\\\', String), # escaped backslash 

1230 (r'\\"', String), # escaped quote 

1231 (r'\\', String), # bare backslash 

1232 (r'\$\{', String.Interpol, 'interpolation'), 

1233 (r'(\$)(\w+)', bygroups(String.Interpol, Name)), 

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

1235 ], 

1236 'interpolation': [ 

1237 (r'"', String), 

1238 (r'\$\{', String.Interpol, 'interpolation'), 

1239 (r'\{', Punctuation, 'scope'), 

1240 (r'\}', String.Interpol, '#pop'), 

1241 include('root') 

1242 ], 

1243 'scope': [ 

1244 (r'\{', Punctuation, 'scope'), 

1245 (r'\}', Punctuation, '#pop'), 

1246 include('root') 

1247 ] 

1248 } 

1249 

1250 

1251class XtendLexer(RegexLexer): 

1252 """ 

1253 For Xtend source code. 

1254 """ 

1255 

1256 name = 'Xtend' 

1257 url = 'https://www.eclipse.org/xtend/' 

1258 aliases = ['xtend'] 

1259 filenames = ['*.xtend'] 

1260 mimetypes = ['text/x-xtend'] 

1261 version_added = '1.6' 

1262 

1263 flags = re.MULTILINE | re.DOTALL 

1264 

1265 tokens = { 

1266 'root': [ 

1267 # method names 

1268 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments 

1269 r'([a-zA-Z_$][\w$]*)' # method name 

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

1271 bygroups(using(this), Name.Function, Whitespace, Operator)), 

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

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

1274 (r'/\*.*?\*/', Comment.Multiline), 

1275 (r'@[a-zA-Z_][\w.]*', Name.Decorator), 

1276 (r'(assert|break|case|catch|continue|default|do|else|finally|for|' 

1277 r'if|goto|instanceof|new|return|switch|this|throw|try|while|IF|' 

1278 r'ELSE|ELSEIF|ENDIF|FOR|ENDFOR|SEPARATOR|BEFORE|AFTER)\b', 

1279 Keyword), 

1280 (r'(def|abstract|const|enum|extends|final|implements|native|private|' 

1281 r'protected|public|static|strictfp|super|synchronized|throws|' 

1282 r'transient|volatile|val|var)\b', Keyword.Declaration), 

1283 (r'(boolean|byte|char|double|float|int|long|short|void)\b', 

1284 Keyword.Type), 

1285 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace)), 

1286 (r'(true|false|null)\b', Keyword.Constant), 

1287 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Whitespace), 

1288 'class'), 

1289 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'), 

1290 (r"(''')", String, 'template'), 

1291 (r'(\u00BB)', String, 'template'), 

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

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

1294 (r'[a-zA-Z_]\w*:', Name.Label), 

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

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

1297 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

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

1299 (r'[0-9]+L?', Number.Integer), 

1300 (r'\n', Whitespace) 

1301 ], 

1302 'class': [ 

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

1304 ], 

1305 'import': [ 

1306 (r'[\w.]+\*?', Name.Namespace, '#pop') 

1307 ], 

1308 'template': [ 

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

1310 (r'\u00AB', String, '#pop'), 

1311 (r'.', String) 

1312 ], 

1313 } 

1314 

1315 

1316class PigLexer(RegexLexer): 

1317 """ 

1318 For Pig Latin source code. 

1319 """ 

1320 

1321 name = 'Pig' 

1322 url = 'https://pig.apache.org/' 

1323 aliases = ['pig'] 

1324 filenames = ['*.pig'] 

1325 mimetypes = ['text/x-pig'] 

1326 version_added = '2.0' 

1327 

1328 flags = re.MULTILINE | re.IGNORECASE 

1329 

1330 tokens = { 

1331 'root': [ 

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

1333 (r'--.*', Comment), 

1334 (r'/\*[\w\W]*?\*/', Comment.Multiline), 

1335 (r'\\$', String.Escape), 

1336 (r'\\', Text), 

1337 (r'\'(?:\\[ntbrf\\\']|\\u[0-9a-f]{4}|[^\'\\\n\r])*\'', String), 

1338 include('keywords'), 

1339 include('types'), 

1340 include('builtins'), 

1341 include('punct'), 

1342 include('operators'), 

1343 (r'[0-9]*\.[0-9]+(e[0-9]+)?[fd]?', Number.Float), 

1344 (r'0x[0-9a-f]+', Number.Hex), 

1345 (r'[0-9]+L?', Number.Integer), 

1346 (r'\n', Whitespace), 

1347 (r'([a-z_]\w*)(\s*)(\()', 

1348 bygroups(Name.Function, Whitespace, Punctuation)), 

1349 (r'[()#:]', Text), 

1350 (r'[^(:#\'")\s]+', Text), 

1351 (r'\S+\s+', Text) # TODO: make tests pass without \s+ 

1352 ], 

1353 'keywords': [ 

1354 (r'(assert|and|any|all|arrange|as|asc|bag|by|cache|CASE|cat|cd|cp|' 

1355 r'%declare|%default|define|dense|desc|describe|distinct|du|dump|' 

1356 r'eval|exex|explain|filter|flatten|foreach|full|generate|group|' 

1357 r'help|if|illustrate|import|inner|input|into|is|join|kill|left|' 

1358 r'limit|load|ls|map|matches|mkdir|mv|not|null|onschema|or|order|' 

1359 r'outer|output|parallel|pig|pwd|quit|register|returns|right|rm|' 

1360 r'rmf|rollup|run|sample|set|ship|split|stderr|stdin|stdout|store|' 

1361 r'stream|through|union|using|void)\b', Keyword) 

1362 ], 

1363 'builtins': [ 

1364 (r'(AVG|BinStorage|cogroup|CONCAT|copyFromLocal|copyToLocal|COUNT|' 

1365 r'cross|DIFF|MAX|MIN|PigDump|PigStorage|SIZE|SUM|TextLoader|' 

1366 r'TOKENIZE)\b', Name.Builtin) 

1367 ], 

1368 'types': [ 

1369 (r'(bytearray|BIGINTEGER|BIGDECIMAL|chararray|datetime|double|float|' 

1370 r'int|long|tuple)\b', Keyword.Type) 

1371 ], 

1372 'punct': [ 

1373 (r'[;(){}\[\]]', Punctuation), 

1374 ], 

1375 'operators': [ 

1376 (r'[#=,./%+\-?]', Operator), 

1377 (r'(eq|gt|lt|gte|lte|neq|matches)\b', Operator), 

1378 (r'(==|<=|<|>=|>|!=)', Operator), 

1379 ], 

1380 } 

1381 

1382 

1383class GoloLexer(RegexLexer): 

1384 """ 

1385 For Golo source code. 

1386 """ 

1387 

1388 name = 'Golo' 

1389 url = 'http://golo-lang.org/' 

1390 filenames = ['*.golo'] 

1391 aliases = ['golo'] 

1392 version_added = '2.0' 

1393 

1394 tokens = { 

1395 'root': [ 

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

1397 

1398 (r'#.*$', Comment), 

1399 

1400 (r'(\^|\.\.\.|:|\?:|->|==|!=|=|\+|\*|%|/|<=|<|>=|>|=|\.)', 

1401 Operator), 

1402 (r'(?<=[^-])(-)(?=[^-])', Operator), 

1403 

1404 (r'(?<=[^`])(is|isnt|and|or|not|oftype|in|orIfNull)\b', Operator.Word), 

1405 (r'[]{}|(),[]', Punctuation), 

1406 

1407 (r'(module|import)(\s+)', 

1408 bygroups(Keyword.Namespace, Whitespace), 

1409 'modname'), 

1410 (r'\b([a-zA-Z_][\w$.]*)(::)', bygroups(Name.Namespace, Punctuation)), 

1411 (r'\b([a-zA-Z_][\w$]*(?:\.[a-zA-Z_][\w$]*)+)\b', Name.Namespace), 

1412 

1413 (r'(let|var)(\s+)', 

1414 bygroups(Keyword.Declaration, Whitespace), 

1415 'varname'), 

1416 (r'(struct)(\s+)', 

1417 bygroups(Keyword.Declaration, Whitespace), 

1418 'structname'), 

1419 (r'(function)(\s+)', 

1420 bygroups(Keyword.Declaration, Whitespace), 

1421 'funcname'), 

1422 

1423 (r'(null|true|false)\b', Keyword.Constant), 

1424 (r'(augment|pimp' 

1425 r'|if|else|case|match|return' 

1426 r'|case|when|then|otherwise' 

1427 r'|while|for|foreach' 

1428 r'|try|catch|finally|throw' 

1429 r'|local' 

1430 r'|continue|break)\b', Keyword), 

1431 

1432 (r'(map|array|list|set|vector|tuple)(\[)', 

1433 bygroups(Name.Builtin, Punctuation)), 

1434 (r'(print|println|readln|raise|fun' 

1435 r'|asInterfaceInstance)\b', Name.Builtin), 

1436 (r'(`?[a-zA-Z_][\w$]*)(\()', 

1437 bygroups(Name.Function, Punctuation)), 

1438 

1439 (r'-?[\d_]*\.[\d_]*([eE][+-]?\d[\d_]*)?F?', Number.Float), 

1440 (r'0[0-7]+j?', Number.Oct), 

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

1442 (r'-?\d[\d_]*L', Number.Integer.Long), 

1443 (r'-?\d[\d_]*', Number.Integer), 

1444 

1445 (r'`?[a-zA-Z_][\w$]*', Name), 

1446 (r'@[a-zA-Z_][\w$.]*', Name.Decorator), 

1447 

1448 (r'"""', String, combined('stringescape', 'triplestring')), 

1449 (r'"', String, combined('stringescape', 'doublestring')), 

1450 (r"'", String, combined('stringescape', 'singlestring')), 

1451 (r'----([\s\S]*?)----', String.Doc) 

1452 

1453 ], 

1454 

1455 'funcname': [ 

1456 (r'`?[a-zA-Z_][\w$]*', Name.Function, '#pop'), 

1457 ], 

1458 'modname': [ 

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

1460 ], 

1461 'structname': [ 

1462 (r'`?[\w.]+\*?', Name.Class, '#pop') 

1463 ], 

1464 'varname': [ 

1465 (r'`?[a-zA-Z_][\w$]*', Name.Variable, '#pop'), 

1466 ], 

1467 'string': [ 

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

1469 (r'[\'"\\]', String) 

1470 ], 

1471 'stringescape': [ 

1472 (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|' 

1473 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) 

1474 ], 

1475 'triplestring': [ 

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

1477 include('string'), 

1478 (r'\n', String), 

1479 ], 

1480 'doublestring': [ 

1481 (r'"', String.Double, '#pop'), 

1482 include('string'), 

1483 ], 

1484 'singlestring': [ 

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

1486 include('string'), 

1487 ], 

1488 'operators': [ 

1489 (r'[#=,./%+\-?]', Operator), 

1490 (r'(eq|gt|lt|gte|lte|neq|matches)\b', Operator), 

1491 (r'(==|<=|<|>=|>|!=)', Operator), 

1492 ], 

1493 } 

1494 

1495 

1496class JasminLexer(RegexLexer): 

1497 """ 

1498 For Jasmin assembly code. 

1499 """ 

1500 

1501 name = 'Jasmin' 

1502 url = 'http://jasmin.sourceforge.net/' 

1503 aliases = ['jasmin', 'jasminxt'] 

1504 filenames = ['*.j'] 

1505 version_added = '2.0' 

1506 

1507 _whitespace = r' \n\t\r' 

1508 _ws = rf'(?:[{_whitespace}]+)' 

1509 _separator = rf'{_whitespace}:=' 

1510 _break = rf'(?=[{_separator}]|$)' 

1511 _name = rf'[^{_separator}]+' 

1512 _unqualified_name = rf'(?:[^{_separator}.;\[/]+)' 

1513 

1514 tokens = { 

1515 'default': [ 

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

1517 (r"'", String.Single, ('#pop', 'quote')), 

1518 (r'"', String.Double, 'string'), 

1519 (r'=', Punctuation), 

1520 (r':', Punctuation, 'label'), 

1521 (_ws, Whitespace), 

1522 (r';.*', Comment.Single), 

1523 (rf'(\$[-+])?0x-?[\da-fA-F]+{_break}', Number.Hex), 

1524 (rf'(\$[-+]|\+)?-?\d+{_break}', Number.Integer), 

1525 (r'-?(\d+\.\d*|\.\d+)([eE][-+]?\d+)?[fFdD]?' 

1526 rf'[\x00-\x08\x0b\x0c\x0e-\x1f]*{_break}', Number.Float), 

1527 (rf'\${_name}', Name.Variable), 

1528 

1529 # Directives 

1530 (rf'\.annotation{_break}', Keyword.Reserved, 'annotation'), 

1531 (r'(\.attribute|\.bytecode|\.debug|\.deprecated|\.enclosing|' 

1532 r'\.interface|\.line|\.signature|\.source|\.stack|\.var|abstract|' 

1533 r'annotation|bridge|class|default|enum|field|final|fpstrict|' 

1534 r'interface|native|private|protected|public|signature|static|' 

1535 rf'synchronized|synthetic|transient|varargs|volatile){_break}', 

1536 Keyword.Reserved), 

1537 (rf'\.catch{_break}', Keyword.Reserved, 'caught-exception'), 

1538 (r'(\.class|\.implements|\.inner|\.super|inner|invisible|' 

1539 rf'invisibleparam|outer|visible|visibleparam){_break}', 

1540 Keyword.Reserved, 'class/convert-dots'), 

1541 (rf'\.field{_break}', Keyword.Reserved, 

1542 ('descriptor/convert-dots', 'field')), 

1543 (rf'(\.end|\.limit|use){_break}', Keyword.Reserved, 

1544 'no-verification'), 

1545 (rf'\.method{_break}', Keyword.Reserved, 'method'), 

1546 (rf'\.set{_break}', Keyword.Reserved, 'var'), 

1547 (rf'\.throws{_break}', Keyword.Reserved, 'exception'), 

1548 (rf'(from|offset|to|using){_break}', Keyword.Reserved, 'label'), 

1549 (rf'is{_break}', Keyword.Reserved, 

1550 ('descriptor/convert-dots', 'var')), 

1551 (rf'(locals|stack){_break}', Keyword.Reserved, 'verification'), 

1552 (rf'method{_break}', Keyword.Reserved, 'enclosing-method'), 

1553 

1554 # Instructions 

1555 (words(( 

1556 'aaload', 'aastore', 'aconst_null', 'aload', 'aload_0', 'aload_1', 'aload_2', 

1557 'aload_3', 'aload_w', 'areturn', 'arraylength', 'astore', 'astore_0', 'astore_1', 

1558 'astore_2', 'astore_3', 'astore_w', 'athrow', 'baload', 'bastore', 'bipush', 

1559 'breakpoint', 'caload', 'castore', 'd2f', 'd2i', 'd2l', 'dadd', 'daload', 'dastore', 

1560 'dcmpg', 'dcmpl', 'dconst_0', 'dconst_1', 'ddiv', 'dload', 'dload_0', 'dload_1', 

1561 'dload_2', 'dload_3', 'dload_w', 'dmul', 'dneg', 'drem', 'dreturn', 'dstore', 'dstore_0', 

1562 'dstore_1', 'dstore_2', 'dstore_3', 'dstore_w', 'dsub', 'dup', 'dup2', 'dup2_x1', 

1563 'dup2_x2', 'dup_x1', 'dup_x2', 'f2d', 'f2i', 'f2l', 'fadd', 'faload', 'fastore', 'fcmpg', 

1564 'fcmpl', 'fconst_0', 'fconst_1', 'fconst_2', 'fdiv', 'fload', 'fload_0', 'fload_1', 

1565 'fload_2', 'fload_3', 'fload_w', 'fmul', 'fneg', 'frem', 'freturn', 'fstore', 'fstore_0', 

1566 'fstore_1', 'fstore_2', 'fstore_3', 'fstore_w', 'fsub', 'i2b', 'i2c', 'i2d', 'i2f', 'i2l', 

1567 'i2s', 'iadd', 'iaload', 'iand', 'iastore', 'iconst_0', 'iconst_1', 'iconst_2', 

1568 'iconst_3', 'iconst_4', 'iconst_5', 'iconst_m1', 'idiv', 'iinc', 'iinc_w', 'iload', 

1569 'iload_0', 'iload_1', 'iload_2', 'iload_3', 'iload_w', 'imul', 'ineg', 'int2byte', 

1570 'int2char', 'int2short', 'ior', 'irem', 'ireturn', 'ishl', 'ishr', 'istore', 'istore_0', 

1571 'istore_1', 'istore_2', 'istore_3', 'istore_w', 'isub', 'iushr', 'ixor', 'l2d', 'l2f', 

1572 'l2i', 'ladd', 'laload', 'land', 'lastore', 'lcmp', 'lconst_0', 'lconst_1', 'ldc2_w', 

1573 'ldiv', 'lload', 'lload_0', 'lload_1', 'lload_2', 'lload_3', 'lload_w', 'lmul', 'lneg', 

1574 'lookupswitch', 'lor', 'lrem', 'lreturn', 'lshl', 'lshr', 'lstore', 'lstore_0', 

1575 'lstore_1', 'lstore_2', 'lstore_3', 'lstore_w', 'lsub', 'lushr', 'lxor', 

1576 'monitorenter', 'monitorexit', 'nop', 'pop', 'pop2', 'ret', 'ret_w', 'return', 'saload', 

1577 'sastore', 'sipush', 'swap'), suffix=_break), Keyword.Reserved), 

1578 (rf'(anewarray|checkcast|instanceof|ldc|ldc_w|new){_break}', 

1579 Keyword.Reserved, 'class/no-dots'), 

1580 (r'invoke(dynamic|interface|nonvirtual|special|' 

1581 rf'static|virtual){_break}', Keyword.Reserved, 

1582 'invocation'), 

1583 (rf'(getfield|putfield){_break}', Keyword.Reserved, 

1584 ('descriptor/no-dots', 'field')), 

1585 (rf'(getstatic|putstatic){_break}', Keyword.Reserved, 

1586 ('descriptor/no-dots', 'static')), 

1587 (words(( 

1588 'goto', 'goto_w', 'if_acmpeq', 'if_acmpne', 'if_icmpeq', 

1589 'if_icmpge', 'if_icmpgt', 'if_icmple', 'if_icmplt', 'if_icmpne', 

1590 'ifeq', 'ifge', 'ifgt', 'ifle', 'iflt', 'ifne', 'ifnonnull', 

1591 'ifnull', 'jsr', 'jsr_w'), suffix=_break), 

1592 Keyword.Reserved, 'label'), 

1593 (rf'(multianewarray|newarray){_break}', Keyword.Reserved, 

1594 'descriptor/convert-dots'), 

1595 (rf'tableswitch{_break}', Keyword.Reserved, 'table') 

1596 ], 

1597 'quote': [ 

1598 (r"'", String.Single, '#pop'), 

1599 (r'\\u[\da-fA-F]{4}', String.Escape), 

1600 (r"[^'\\]+", String.Single) 

1601 ], 

1602 'string': [ 

1603 (r'"', String.Double, '#pop'), 

1604 (r'\\([nrtfb"\'\\]|u[\da-fA-F]{4}|[0-3]?[0-7]{1,2})', 

1605 String.Escape), 

1606 (r'[^"\\]+', String.Double) 

1607 ], 

1608 'root': [ 

1609 (r'\n+', Whitespace), 

1610 (r"'", String.Single, 'quote'), 

1611 include('default'), 

1612 (rf'({_name})([ \t\r]*)(:)', 

1613 bygroups(Name.Label, Whitespace, Punctuation)), 

1614 (_name, String.Other) 

1615 ], 

1616 'annotation': [ 

1617 (r'\n', Whitespace, ('#pop', 'annotation-body')), 

1618 (rf'default{_break}', Keyword.Reserved, 

1619 ('#pop', 'annotation-default')), 

1620 include('default') 

1621 ], 

1622 'annotation-body': [ 

1623 (r'\n+', Whitespace), 

1624 (rf'\.end{_break}', Keyword.Reserved, '#pop'), 

1625 include('default'), 

1626 (_name, String.Other, ('annotation-items', 'descriptor/no-dots')) 

1627 ], 

1628 'annotation-default': [ 

1629 (r'\n+', Whitespace), 

1630 (rf'\.end{_break}', Keyword.Reserved, '#pop'), 

1631 include('default'), 

1632 default(('annotation-items', 'descriptor/no-dots')) 

1633 ], 

1634 'annotation-items': [ 

1635 (r"'", String.Single, 'quote'), 

1636 include('default'), 

1637 (_name, String.Other) 

1638 ], 

1639 'caught-exception': [ 

1640 (rf'all{_break}', Keyword, '#pop'), 

1641 include('exception') 

1642 ], 

1643 'class/convert-dots': [ 

1644 include('default'), 

1645 (rf'(L)((?:{_unqualified_name}[/.])*)({_name})(;)', 

1646 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1647 '#pop'), 

1648 (rf'((?:{_unqualified_name}[/.])*)({_name})', 

1649 bygroups(Name.Namespace, Name.Class), '#pop') 

1650 ], 

1651 'class/no-dots': [ 

1652 include('default'), 

1653 (r'\[+', Punctuation, ('#pop', 'descriptor/no-dots')), 

1654 (rf'(L)((?:{_unqualified_name}/)*)({_name})(;)', 

1655 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1656 '#pop'), 

1657 (rf'((?:{_unqualified_name}/)*)({_name})', 

1658 bygroups(Name.Namespace, Name.Class), '#pop') 

1659 ], 

1660 'descriptor/convert-dots': [ 

1661 include('default'), 

1662 (r'\[+', Punctuation), 

1663 (rf'(L)((?:{_unqualified_name}[/.])*)({_name}?)(;)', 

1664 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1665 '#pop'), 

1666 (rf'[^{_separator}\[)L]+', Keyword.Type, '#pop'), 

1667 default('#pop') 

1668 ], 

1669 'descriptor/no-dots': [ 

1670 include('default'), 

1671 (r'\[+', Punctuation), 

1672 (rf'(L)((?:{_unqualified_name}/)*)({_name})(;)', 

1673 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1674 '#pop'), 

1675 (rf'[^{_separator}\[)L]+', Keyword.Type, '#pop'), 

1676 default('#pop') 

1677 ], 

1678 'descriptors/convert-dots': [ 

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

1680 default('descriptor/convert-dots') 

1681 ], 

1682 'enclosing-method': [ 

1683 (_ws, Whitespace), 

1684 (rf'(?=[^{_separator}]*\()', Text, ('#pop', 'invocation')), 

1685 default(('#pop', 'class/convert-dots')) 

1686 ], 

1687 'exception': [ 

1688 include('default'), 

1689 (rf'((?:{_unqualified_name}[/.])*)({_name})', 

1690 bygroups(Name.Namespace, Name.Exception), '#pop') 

1691 ], 

1692 'field': [ 

1693 (rf'static{_break}', Keyword.Reserved, ('#pop', 'static')), 

1694 include('default'), 

1695 (rf'((?:{_unqualified_name}[/.](?=[^{_separator}]*[/.]))*)({_unqualified_name}[/.])?({_name})', 

1696 bygroups(Name.Namespace, Name.Class, Name.Variable.Instance), 

1697 '#pop') 

1698 ], 

1699 'invocation': [ 

1700 include('default'), 

1701 (rf'((?:{_unqualified_name}[/.](?=[^{_separator}(]*[/.]))*)({_unqualified_name}[/.])?({_name})(\()', 

1702 bygroups(Name.Namespace, Name.Class, Name.Function, Punctuation), 

1703 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots', 

1704 'descriptor/convert-dots')) 

1705 ], 

1706 'label': [ 

1707 include('default'), 

1708 (_name, Name.Label, '#pop') 

1709 ], 

1710 'method': [ 

1711 include('default'), 

1712 (rf'({_name})(\()', bygroups(Name.Function, Punctuation), 

1713 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots', 

1714 'descriptor/convert-dots')) 

1715 ], 

1716 'no-verification': [ 

1717 (rf'(locals|method|stack){_break}', Keyword.Reserved, '#pop'), 

1718 include('default') 

1719 ], 

1720 'static': [ 

1721 include('default'), 

1722 (rf'((?:{_unqualified_name}[/.](?=[^{_separator}]*[/.]))*)({_unqualified_name}[/.])?({_name})', 

1723 bygroups(Name.Namespace, Name.Class, Name.Variable.Class), '#pop') 

1724 ], 

1725 'table': [ 

1726 (r'\n+', Whitespace), 

1727 (rf'default{_break}', Keyword.Reserved, '#pop'), 

1728 include('default'), 

1729 (_name, Name.Label) 

1730 ], 

1731 'var': [ 

1732 include('default'), 

1733 (_name, Name.Variable, '#pop') 

1734 ], 

1735 'verification': [ 

1736 include('default'), 

1737 (rf'(Double|Float|Integer|Long|Null|Top|UninitializedThis){_break}', Keyword, '#pop'), 

1738 (rf'Object{_break}', Keyword, ('#pop', 'class/no-dots')), 

1739 (rf'Uninitialized{_break}', Keyword, ('#pop', 'label')) 

1740 ] 

1741 } 

1742 

1743 def analyse_text(text): 

1744 score = 0 

1745 if re.search(r'^\s*\.class\s', text, re.MULTILINE): 

1746 score += 0.5 

1747 if re.search(r'^\s*[a-z]+_[a-z]+\b', text, re.MULTILINE): 

1748 score += 0.3 

1749 if re.search(r'^\s*\.(attribute|bytecode|debug|deprecated|enclosing|' 

1750 r'inner|interface|limit|set|signature|stack)\b', text, 

1751 re.MULTILINE): 

1752 score += 0.6 

1753 return min(score, 1.0) 

1754 

1755 

1756class SarlLexer(RegexLexer): 

1757 """ 

1758 For SARL source code. 

1759 """ 

1760 

1761 name = 'SARL' 

1762 url = 'http://www.sarl.io' 

1763 aliases = ['sarl'] 

1764 filenames = ['*.sarl'] 

1765 mimetypes = ['text/x-sarl'] 

1766 version_added = '2.4' 

1767 

1768 flags = re.MULTILINE | re.DOTALL 

1769 

1770 tokens = { 

1771 'root': [ 

1772 # method names 

1773 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments 

1774 r'([a-zA-Z_$][\w$]*)' # method name 

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

1776 bygroups(using(this), Name.Function, Whitespace, Operator)), 

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

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

1779 (r'/\*.*?\*/', Comment.Multiline), 

1780 (r'@[a-zA-Z_][\w.]*', Name.Decorator), 

1781 (r'(as|break|case|catch|default|do|else|extends|extension|finally|' 

1782 r'fires|for|if|implements|instanceof|new|on|requires|return|super|' 

1783 r'switch|throw|throws|try|typeof|uses|while|with)\b', 

1784 Keyword), 

1785 (r'(abstract|def|dispatch|final|native|override|private|protected|' 

1786 r'public|static|strictfp|synchronized|transient|val|var|volatile)\b', 

1787 Keyword.Declaration), 

1788 (r'(boolean|byte|char|double|float|int|long|short|void)\b', 

1789 Keyword.Type), 

1790 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace)), 

1791 (r'(false|it|null|occurrence|this|true|void)\b', Keyword.Constant), 

1792 (r'(agent|annotation|artifact|behavior|capacity|class|enum|event|' 

1793 r'interface|skill|space)(\s+)', bygroups(Keyword.Declaration, Whitespace), 

1794 'class'), 

1795 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'), 

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

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

1798 (r'[a-zA-Z_]\w*:', Name.Label), 

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

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

1801 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

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

1803 (r'[0-9]+L?', Number.Integer), 

1804 (r'\n', Whitespace) 

1805 ], 

1806 'class': [ 

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

1808 ], 

1809 'import': [ 

1810 (r'[\w.]+\*?', Name.Namespace, '#pop') 

1811 ], 

1812 }