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

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"\\(.|[a-z]+)", String.Char), 

915 

916 # keywords 

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

918 

919 # special operators 

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

921 

922 # highlight the special forms 

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

924 

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

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

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

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

929 # highlight them as Keyword.Declarations. 

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

931 

932 # highlight the builtins 

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

934 

935 # the remaining functions 

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

937 

938 # find the remaining variables 

939 (valid_name, Name.Variable), 

940 

941 # Clojure accepts vector notation 

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

943 

944 # Clojure accepts map notation 

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

946 

947 # the famous parentheses! 

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

949 ], 

950 } 

951 

952 

953class ClojureScriptLexer(ClojureLexer): 

954 """ 

955 Lexer for ClojureScript source code. 

956 """ 

957 name = 'ClojureScript' 

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

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

960 filenames = ['*.cljs'] 

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

962 version_added = '2.0' 

963 

964 

965class TeaLangLexer(RegexLexer): 

966 """ 

967 For Tea source code. Only used within a 

968 TeaTemplateLexer. 

969 

970 .. versionadded:: 1.5 

971 """ 

972 

973 flags = re.MULTILINE | re.DOTALL 

974 

975 tokens = { 

976 'root': [ 

977 # method names 

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

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

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

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

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

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

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

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

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

987 Keyword), 

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

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

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

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

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

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

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

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

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

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

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

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

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

1001 (r'\n', Whitespace) 

1002 ], 

1003 'template': [ 

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

1005 ], 

1006 'import': [ 

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

1008 ], 

1009 } 

1010 

1011 

1012class CeylonLexer(RegexLexer): 

1013 """ 

1014 For Ceylon source code. 

1015 """ 

1016 

1017 name = 'Ceylon' 

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

1019 aliases = ['ceylon'] 

1020 filenames = ['*.ceylon'] 

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

1022 version_added = '1.6' 

1023 

1024 flags = re.MULTILINE | re.DOTALL 

1025 

1026 #: optional Comment or Whitespace 

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

1028 

1029 tokens = { 

1030 'root': [ 

1031 # method names 

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

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

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

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

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

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

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

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

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

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

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

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

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

1045 (r'(abstracts|extends|satisfies|' 

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

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

1048 Keyword.Type), 

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

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

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

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

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

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

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

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

1057 bygroups(Operator, Name.Attribute)), 

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

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

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

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

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

1063 Number.Float), 

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

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

1066 Number.Float), 

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

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

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

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

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

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

1073 (r'\n', Whitespace) 

1074 ], 

1075 'class': [ 

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

1077 ], 

1078 'import': [ 

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

1080 Name.Namespace, '#pop') 

1081 ], 

1082 'comment': [ 

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

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

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

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

1087 ], 

1088 } 

1089 

1090 

1091class KotlinLexer(RegexLexer): 

1092 """ 

1093 For Kotlin source code. 

1094 """ 

1095 

1096 name = 'Kotlin' 

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

1098 aliases = ['kotlin'] 

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

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

1101 version_added = '1.5' 

1102 

1103 flags = re.MULTILINE | re.DOTALL 

1104 

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

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

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

1108 

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

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

1111 'Mn', 'Mc', 'Zs') 

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

1113 

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

1115 

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

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

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

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

1120 

1121 tokens = { 

1122 'root': [ 

1123 # Whitespaces 

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

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

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

1127 (r'\n', Whitespace), 

1128 # Comments 

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

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

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

1132 # Keywords 

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

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

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

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

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

1138 # Built-in types 

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

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

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

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

1143 # Constants 

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

1145 # Imports 

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

1147 # Dot access 

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

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

1150 # Annotations 

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

1152 # Labels 

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

1154 # Object expression 

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

1156 # Types 

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

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

1159 # Variables 

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

1161 'destructuring_assignment'), 

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

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

1164 # Functions 

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

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

1167 # Operators 

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

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

1170 # Punctuation 

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

1172 # Strings 

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

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

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

1176 # Numbers 

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

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

1179 # Identifiers 

1180 (r'' + kt_id + r'((\?[^.])?)', Name) # additionally handle nullable types 

1181 ], 

1182 'class': [ 

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

1184 ], 

1185 'variable': [ 

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

1187 ], 

1188 'destructuring_assignment': [ 

1189 (r',', Punctuation), 

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

1191 (kt_id, Name.Variable), 

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

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

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

1195 ], 

1196 'function': [ 

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

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

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

1200 ], 

1201 'generic': [ 

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

1203 (r':', Punctuation), 

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

1205 (r',', Punctuation), 

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

1207 (kt_id, Name) 

1208 ], 

1209 'modifiers': [ 

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

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

1212 default('#pop') 

1213 ], 

1214 'string': [ 

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

1216 include('string_common') 

1217 ], 

1218 'multiline_string': [ 

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

1220 (r'"', String), 

1221 include('string_common') 

1222 ], 

1223 'string_common': [ 

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

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

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

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

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

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

1230 ], 

1231 'interpolation': [ 

1232 (r'"', String), 

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

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

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

1236 include('root') 

1237 ], 

1238 'scope': [ 

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

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

1241 include('root') 

1242 ] 

1243 } 

1244 

1245 

1246class XtendLexer(RegexLexer): 

1247 """ 

1248 For Xtend source code. 

1249 """ 

1250 

1251 name = 'Xtend' 

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

1253 aliases = ['xtend'] 

1254 filenames = ['*.xtend'] 

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

1256 version_added = '1.6' 

1257 

1258 flags = re.MULTILINE | re.DOTALL 

1259 

1260 tokens = { 

1261 'root': [ 

1262 # method names 

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

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

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

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

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

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

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

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

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

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

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

1274 Keyword), 

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

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

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

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

1279 Keyword.Type), 

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

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

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

1283 'class'), 

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

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

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

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

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

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

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

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

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

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

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

1295 (r'\n', Whitespace) 

1296 ], 

1297 'class': [ 

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

1299 ], 

1300 'import': [ 

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

1302 ], 

1303 'template': [ 

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

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

1306 (r'.', String) 

1307 ], 

1308 } 

1309 

1310 

1311class PigLexer(RegexLexer): 

1312 """ 

1313 For Pig Latin source code. 

1314 """ 

1315 

1316 name = 'Pig' 

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

1318 aliases = ['pig'] 

1319 filenames = ['*.pig'] 

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

1321 version_added = '2.0' 

1322 

1323 flags = re.MULTILINE | re.IGNORECASE 

1324 

1325 tokens = { 

1326 'root': [ 

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

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

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

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

1331 (r'\\', Text), 

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

1333 include('keywords'), 

1334 include('types'), 

1335 include('builtins'), 

1336 include('punct'), 

1337 include('operators'), 

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

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

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

1341 (r'\n', Whitespace), 

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

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

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

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

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

1347 ], 

1348 'keywords': [ 

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

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

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

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

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

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

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

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

1357 ], 

1358 'builtins': [ 

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

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

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

1362 ], 

1363 'types': [ 

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

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

1366 ], 

1367 'punct': [ 

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

1369 ], 

1370 'operators': [ 

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

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

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

1374 ], 

1375 } 

1376 

1377 

1378class GoloLexer(RegexLexer): 

1379 """ 

1380 For Golo source code. 

1381 """ 

1382 

1383 name = 'Golo' 

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

1385 filenames = ['*.golo'] 

1386 aliases = ['golo'] 

1387 version_added = '2.0' 

1388 

1389 tokens = { 

1390 'root': [ 

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

1392 

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

1394 

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

1396 Operator), 

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

1398 

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

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

1401 

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

1403 bygroups(Keyword.Namespace, Whitespace), 

1404 'modname'), 

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

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

1407 

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

1409 bygroups(Keyword.Declaration, Whitespace), 

1410 'varname'), 

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

1412 bygroups(Keyword.Declaration, Whitespace), 

1413 'structname'), 

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

1415 bygroups(Keyword.Declaration, Whitespace), 

1416 'funcname'), 

1417 

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

1419 (r'(augment|pimp' 

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

1421 r'|case|when|then|otherwise' 

1422 r'|while|for|foreach' 

1423 r'|try|catch|finally|throw' 

1424 r'|local' 

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

1426 

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

1428 bygroups(Name.Builtin, Punctuation)), 

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

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

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

1432 bygroups(Name.Function, Punctuation)), 

1433 

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

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

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

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

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

1439 

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

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

1442 

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

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

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

1446 (r'----((.|\n)*?)----', String.Doc) 

1447 

1448 ], 

1449 

1450 'funcname': [ 

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

1452 ], 

1453 'modname': [ 

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

1455 ], 

1456 'structname': [ 

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

1458 ], 

1459 'varname': [ 

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

1461 ], 

1462 'string': [ 

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

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

1465 ], 

1466 'stringescape': [ 

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

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

1469 ], 

1470 'triplestring': [ 

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

1472 include('string'), 

1473 (r'\n', String), 

1474 ], 

1475 'doublestring': [ 

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

1477 include('string'), 

1478 ], 

1479 'singlestring': [ 

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

1481 include('string'), 

1482 ], 

1483 'operators': [ 

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

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

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

1487 ], 

1488 } 

1489 

1490 

1491class JasminLexer(RegexLexer): 

1492 """ 

1493 For Jasmin assembly code. 

1494 """ 

1495 

1496 name = 'Jasmin' 

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

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

1499 filenames = ['*.j'] 

1500 version_added = '2.0' 

1501 

1502 _whitespace = r' \n\t\r' 

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

1504 _separator = rf'{_whitespace}:=' 

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

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

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

1508 

1509 tokens = { 

1510 'default': [ 

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

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

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

1514 (r'=', Punctuation), 

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

1516 (_ws, Whitespace), 

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

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

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

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

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

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

1523 

1524 # Directives 

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

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

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

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

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

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

1531 Keyword.Reserved), 

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

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

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

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

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

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

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

1539 'no-verification'), 

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

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

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

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

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

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

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

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

1548 

1549 # Instructions 

1550 (words(( 

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

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

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

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

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

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

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

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

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

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

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

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

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

1564 'iload_0', 'iload_1', 'iload_2', 'iload_3', 'iload_w', 'imul', 'ineg', 'int2byte', 

1565 'int2char', 'int2short', 'ior', 'irem', 'ireturn', 'ishl', 'ishr', 'istore', 'istore_0', 

1566 'istore_1', 'istore_2', 'istore_3', 'istore_w', 'isub', 'iushr', 'ixor', 'l2d', 'l2f', 

1567 'l2i', 'ladd', 'laload', 'land', 'lastore', 'lcmp', 'lconst_0', 'lconst_1', 'ldc2_w', 

1568 'ldiv', 'lload', 'lload_0', 'lload_1', 'lload_2', 'lload_3', 'lload_w', 'lmul', 'lneg', 

1569 'lookupswitch', 'lor', 'lrem', 'lreturn', 'lshl', 'lshr', 'lstore', 'lstore_0', 

1570 'lstore_1', 'lstore_2', 'lstore_3', 'lstore_w', 'lsub', 'lushr', 'lxor', 

1571 'monitorenter', 'monitorexit', 'nop', 'pop', 'pop2', 'ret', 'ret_w', 'return', 'saload', 

1572 'sastore', 'sipush', 'swap'), suffix=_break), Keyword.Reserved), 

1573 (rf'(anewarray|checkcast|instanceof|ldc|ldc_w|new){_break}', 

1574 Keyword.Reserved, 'class/no-dots'), 

1575 (r'invoke(dynamic|interface|nonvirtual|special|' 

1576 rf'static|virtual){_break}', Keyword.Reserved, 

1577 'invocation'), 

1578 (rf'(getfield|putfield){_break}', Keyword.Reserved, 

1579 ('descriptor/no-dots', 'field')), 

1580 (rf'(getstatic|putstatic){_break}', Keyword.Reserved, 

1581 ('descriptor/no-dots', 'static')), 

1582 (words(( 

1583 'goto', 'goto_w', 'if_acmpeq', 'if_acmpne', 'if_icmpeq', 

1584 'if_icmpge', 'if_icmpgt', 'if_icmple', 'if_icmplt', 'if_icmpne', 

1585 'ifeq', 'ifge', 'ifgt', 'ifle', 'iflt', 'ifne', 'ifnonnull', 

1586 'ifnull', 'jsr', 'jsr_w'), suffix=_break), 

1587 Keyword.Reserved, 'label'), 

1588 (rf'(multianewarray|newarray){_break}', Keyword.Reserved, 

1589 'descriptor/convert-dots'), 

1590 (rf'tableswitch{_break}', Keyword.Reserved, 'table') 

1591 ], 

1592 'quote': [ 

1593 (r"'", String.Single, '#pop'), 

1594 (r'\\u[\da-fA-F]{4}', String.Escape), 

1595 (r"[^'\\]+", String.Single) 

1596 ], 

1597 'string': [ 

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

1599 (r'\\([nrtfb"\'\\]|u[\da-fA-F]{4}|[0-3]?[0-7]{1,2})', 

1600 String.Escape), 

1601 (r'[^"\\]+', String.Double) 

1602 ], 

1603 'root': [ 

1604 (r'\n+', Whitespace), 

1605 (r"'", String.Single, 'quote'), 

1606 include('default'), 

1607 (rf'({_name})([ \t\r]*)(:)', 

1608 bygroups(Name.Label, Whitespace, Punctuation)), 

1609 (_name, String.Other) 

1610 ], 

1611 'annotation': [ 

1612 (r'\n', Whitespace, ('#pop', 'annotation-body')), 

1613 (rf'default{_break}', Keyword.Reserved, 

1614 ('#pop', 'annotation-default')), 

1615 include('default') 

1616 ], 

1617 'annotation-body': [ 

1618 (r'\n+', Whitespace), 

1619 (rf'\.end{_break}', Keyword.Reserved, '#pop'), 

1620 include('default'), 

1621 (_name, String.Other, ('annotation-items', 'descriptor/no-dots')) 

1622 ], 

1623 'annotation-default': [ 

1624 (r'\n+', Whitespace), 

1625 (rf'\.end{_break}', Keyword.Reserved, '#pop'), 

1626 include('default'), 

1627 default(('annotation-items', 'descriptor/no-dots')) 

1628 ], 

1629 'annotation-items': [ 

1630 (r"'", String.Single, 'quote'), 

1631 include('default'), 

1632 (_name, String.Other) 

1633 ], 

1634 'caught-exception': [ 

1635 (rf'all{_break}', Keyword, '#pop'), 

1636 include('exception') 

1637 ], 

1638 'class/convert-dots': [ 

1639 include('default'), 

1640 (rf'(L)((?:{_unqualified_name}[/.])*)({_name})(;)', 

1641 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1642 '#pop'), 

1643 (rf'((?:{_unqualified_name}[/.])*)({_name})', 

1644 bygroups(Name.Namespace, Name.Class), '#pop') 

1645 ], 

1646 'class/no-dots': [ 

1647 include('default'), 

1648 (r'\[+', Punctuation, ('#pop', 'descriptor/no-dots')), 

1649 (rf'(L)((?:{_unqualified_name}/)*)({_name})(;)', 

1650 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1651 '#pop'), 

1652 (rf'((?:{_unqualified_name}/)*)({_name})', 

1653 bygroups(Name.Namespace, Name.Class), '#pop') 

1654 ], 

1655 'descriptor/convert-dots': [ 

1656 include('default'), 

1657 (r'\[+', Punctuation), 

1658 (rf'(L)((?:{_unqualified_name}[/.])*)({_name}?)(;)', 

1659 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1660 '#pop'), 

1661 (rf'[^{_separator}\[)L]+', Keyword.Type, '#pop'), 

1662 default('#pop') 

1663 ], 

1664 'descriptor/no-dots': [ 

1665 include('default'), 

1666 (r'\[+', Punctuation), 

1667 (rf'(L)((?:{_unqualified_name}/)*)({_name})(;)', 

1668 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation), 

1669 '#pop'), 

1670 (rf'[^{_separator}\[)L]+', Keyword.Type, '#pop'), 

1671 default('#pop') 

1672 ], 

1673 'descriptors/convert-dots': [ 

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

1675 default('descriptor/convert-dots') 

1676 ], 

1677 'enclosing-method': [ 

1678 (_ws, Whitespace), 

1679 (rf'(?=[^{_separator}]*\()', Text, ('#pop', 'invocation')), 

1680 default(('#pop', 'class/convert-dots')) 

1681 ], 

1682 'exception': [ 

1683 include('default'), 

1684 (rf'((?:{_unqualified_name}[/.])*)({_name})', 

1685 bygroups(Name.Namespace, Name.Exception), '#pop') 

1686 ], 

1687 'field': [ 

1688 (rf'static{_break}', Keyword.Reserved, ('#pop', 'static')), 

1689 include('default'), 

1690 (rf'((?:{_unqualified_name}[/.](?=[^{_separator}]*[/.]))*)({_unqualified_name}[/.])?({_name})', 

1691 bygroups(Name.Namespace, Name.Class, Name.Variable.Instance), 

1692 '#pop') 

1693 ], 

1694 'invocation': [ 

1695 include('default'), 

1696 (rf'((?:{_unqualified_name}[/.](?=[^{_separator}(]*[/.]))*)({_unqualified_name}[/.])?({_name})(\()', 

1697 bygroups(Name.Namespace, Name.Class, Name.Function, Punctuation), 

1698 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots', 

1699 'descriptor/convert-dots')) 

1700 ], 

1701 'label': [ 

1702 include('default'), 

1703 (_name, Name.Label, '#pop') 

1704 ], 

1705 'method': [ 

1706 include('default'), 

1707 (rf'({_name})(\()', bygroups(Name.Function, Punctuation), 

1708 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots', 

1709 'descriptor/convert-dots')) 

1710 ], 

1711 'no-verification': [ 

1712 (rf'(locals|method|stack){_break}', Keyword.Reserved, '#pop'), 

1713 include('default') 

1714 ], 

1715 'static': [ 

1716 include('default'), 

1717 (rf'((?:{_unqualified_name}[/.](?=[^{_separator}]*[/.]))*)({_unqualified_name}[/.])?({_name})', 

1718 bygroups(Name.Namespace, Name.Class, Name.Variable.Class), '#pop') 

1719 ], 

1720 'table': [ 

1721 (r'\n+', Whitespace), 

1722 (rf'default{_break}', Keyword.Reserved, '#pop'), 

1723 include('default'), 

1724 (_name, Name.Label) 

1725 ], 

1726 'var': [ 

1727 include('default'), 

1728 (_name, Name.Variable, '#pop') 

1729 ], 

1730 'verification': [ 

1731 include('default'), 

1732 (rf'(Double|Float|Integer|Long|Null|Top|UninitializedThis){_break}', Keyword, '#pop'), 

1733 (rf'Object{_break}', Keyword, ('#pop', 'class/no-dots')), 

1734 (rf'Uninitialized{_break}', Keyword, ('#pop', 'label')) 

1735 ] 

1736 } 

1737 

1738 def analyse_text(text): 

1739 score = 0 

1740 if re.search(r'^\s*\.class\s', text, re.MULTILINE): 

1741 score += 0.5 

1742 if re.search(r'^\s*[a-z]+_[a-z]+\b', text, re.MULTILINE): 

1743 score += 0.3 

1744 if re.search(r'^\s*\.(attribute|bytecode|debug|deprecated|enclosing|' 

1745 r'inner|interface|limit|set|signature|stack)\b', text, 

1746 re.MULTILINE): 

1747 score += 0.6 

1748 return min(score, 1.0) 

1749 

1750 

1751class SarlLexer(RegexLexer): 

1752 """ 

1753 For SARL source code. 

1754 """ 

1755 

1756 name = 'SARL' 

1757 url = 'http://www.sarl.io' 

1758 aliases = ['sarl'] 

1759 filenames = ['*.sarl'] 

1760 mimetypes = ['text/x-sarl'] 

1761 version_added = '2.4' 

1762 

1763 flags = re.MULTILINE | re.DOTALL 

1764 

1765 tokens = { 

1766 'root': [ 

1767 # method names 

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

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

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

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

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

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

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

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

1776 (r'(as|break|case|catch|default|do|else|extends|extension|finally|' 

1777 r'fires|for|if|implements|instanceof|new|on|requires|return|super|' 

1778 r'switch|throw|throws|try|typeof|uses|while|with)\b', 

1779 Keyword), 

1780 (r'(abstract|def|dispatch|final|native|override|private|protected|' 

1781 r'public|static|strictfp|synchronized|transient|val|var|volatile)\b', 

1782 Keyword.Declaration), 

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

1784 Keyword.Type), 

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

1786 (r'(false|it|null|occurrence|this|true|void)\b', Keyword.Constant), 

1787 (r'(agent|annotation|artifact|behavior|capacity|class|enum|event|' 

1788 r'interface|skill|space)(\s+)', bygroups(Keyword.Declaration, Whitespace), 

1789 'class'), 

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

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

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

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

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

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

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

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

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

1799 (r'\n', Whitespace) 

1800 ], 

1801 'class': [ 

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

1803 ], 

1804 'import': [ 

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

1806 ], 

1807 }