Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/jvm.py: 89%
183 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.jvm
3 ~~~~~~~~~~~~~~~~~~~
5 Pygments lexers for JVM languages.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11import re
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
20__all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer',
21 'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'ClojureScriptLexer',
22 'KotlinLexer', 'XtendLexer', 'AspectJLexer', 'CeylonLexer',
23 'PigLexer', 'GoloLexer', 'JasminLexer', 'SarlLexer']
26class JavaLexer(RegexLexer):
27 """
28 For Java source code.
29 """
31 name = 'Java'
32 url = 'https://www.oracle.com/technetwork/java/'
33 aliases = ['java']
34 filenames = ['*.java']
35 mimetypes = ['text/x-java']
37 flags = re.MULTILINE | re.DOTALL
39 tokens = {
40 'root': [
41 (r'(^\s*)((?:(?:public|private|protected|static|strictfp)(?:\s+))*)(record)\b',
42 bygroups(Whitespace, using(this), Keyword.Declaration), 'class'),
43 (r'[^\S\n]+', Whitespace),
44 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
45 (r'/\*.*?\*/', Comment.Multiline),
46 # keywords: go before method names to avoid lexing "throw new XYZ"
47 # as a method signature
48 (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
49 r'if|goto|instanceof|new|return|switch|this|throw|try|while)\b',
50 Keyword),
51 # method names
52 (r'((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)' # return arguments
53 r'((?:[^\W\d]|\$)[\w$]*)' # method name
54 r'(\s*)(\()', # signature start
55 bygroups(using(this), Name.Function, Whitespace, Punctuation)),
56 (r'@[^\W\d][\w.]*', Name.Decorator),
57 (r'(abstract|const|enum|extends|final|implements|native|private|'
58 r'protected|public|sealed|static|strictfp|super|synchronized|throws|'
59 r'transient|volatile|yield)\b', Keyword.Declaration),
60 (r'(boolean|byte|char|double|float|int|long|short|void)\b',
61 Keyword.Type),
62 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'),
63 (r'(true|false|null)\b', Keyword.Constant),
64 (r'(class|interface)\b', Keyword.Declaration, 'class'),
65 (r'(var)(\s+)', bygroups(Keyword.Declaration, Whitespace), 'var'),
66 (r'(import(?:\s+static)?)(\s+)', bygroups(Keyword.Namespace, Whitespace),
67 'import'),
68 (r'"""\n', String, 'multiline_string'),
69 (r'"', String, 'string'),
70 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
71 (r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Punctuation,
72 Name.Attribute)),
73 (r'^(\s*)(default)(:)', bygroups(Whitespace, Keyword, Punctuation)),
74 (r'^(\s*)((?:[^\W\d]|\$)[\w$]*)(:)', bygroups(Whitespace, Name.Label,
75 Punctuation)),
76 (r'([^\W\d]|\$)[\w$]*', Name),
77 (r'([0-9][0-9_]*\.([0-9][0-9_]*)?|'
78 r'\.[0-9][0-9_]*)'
79 r'([eE][+\-]?[0-9][0-9_]*)?[fFdD]?|'
80 r'[0-9][eE][+\-]?[0-9][0-9_]*[fFdD]?|'
81 r'[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFdD]|'
82 r'0[xX]([0-9a-fA-F][0-9a-fA-F_]*\.?|'
83 r'([0-9a-fA-F][0-9a-fA-F_]*)?\.[0-9a-fA-F][0-9a-fA-F_]*)'
84 r'[pP][+\-]?[0-9][0-9_]*[fFdD]?', Number.Float),
85 (r'0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?', Number.Hex),
86 (r'0[bB][01][01_]*[lL]?', Number.Bin),
87 (r'0[0-7_]+[lL]?', Number.Oct),
88 (r'0|[1-9][0-9_]*[lL]?', Number.Integer),
89 (r'[~^*!%&\[\]<>|+=/?-]', Operator),
90 (r'[{}();:.,]', Punctuation),
91 (r'\n', Whitespace)
92 ],
93 'class': [
94 (r'\s+', Text),
95 (r'([^\W\d]|\$)[\w$]*', Name.Class, '#pop')
96 ],
97 'var': [
98 (r'([^\W\d]|\$)[\w$]*', Name, '#pop')
99 ],
100 'import': [
101 (r'[\w.]+\*?', Name.Namespace, '#pop')
102 ],
103 'multiline_string': [
104 (r'"""', String, '#pop'),
105 (r'"', String),
106 include('string')
107 ],
108 'string': [
109 (r'[^\\"]+', String),
110 (r'\\\\', String), # Escaped backslash
111 (r'\\"', String), # Escaped quote
112 (r'\\', String), # Bare backslash
113 (r'"', String, '#pop'), # Closing quote
114 ],
115 }
118class AspectJLexer(JavaLexer):
119 """
120 For AspectJ source code.
122 .. versionadded:: 1.6
123 """
125 name = 'AspectJ'
126 url = 'http://www.eclipse.org/aspectj/'
127 aliases = ['aspectj']
128 filenames = ['*.aj']
129 mimetypes = ['text/x-aspectj']
131 aj_keywords = {
132 'aspect', 'pointcut', 'privileged', 'call', 'execution',
133 'initialization', 'preinitialization', 'handler', 'get', 'set',
134 'staticinitialization', 'target', 'args', 'within', 'withincode',
135 'cflow', 'cflowbelow', 'annotation', 'before', 'after', 'around',
136 'proceed', 'throwing', 'returning', 'adviceexecution', 'declare',
137 'parents', 'warning', 'error', 'soft', 'precedence', 'thisJoinPoint',
138 'thisJoinPointStaticPart', 'thisEnclosingJoinPointStaticPart',
139 'issingleton', 'perthis', 'pertarget', 'percflow', 'percflowbelow',
140 'pertypewithin', 'lock', 'unlock', 'thisAspectInstance'
141 }
142 aj_inter_type = {'parents:', 'warning:', 'error:', 'soft:', 'precedence:'}
143 aj_inter_type_annotation = {'@type', '@method', '@constructor', '@field'}
145 def get_tokens_unprocessed(self, text):
146 for index, token, value in JavaLexer.get_tokens_unprocessed(self, text):
147 if token is Name and value in self.aj_keywords:
148 yield index, Keyword, value
149 elif token is Name.Label and value in self.aj_inter_type:
150 yield index, Keyword, value[:-1]
151 yield index, Operator, value[-1]
152 elif token is Name.Decorator and value in self.aj_inter_type_annotation:
153 yield index, Keyword, value
154 else:
155 yield index, token, value
158class ScalaLexer(RegexLexer):
159 """
160 For Scala source code.
161 """
163 name = 'Scala'
164 url = 'http://www.scala-lang.org'
165 aliases = ['scala']
166 filenames = ['*.scala']
167 mimetypes = ['text/x-scala']
169 flags = re.MULTILINE | re.DOTALL
171 opchar = '[!#%&*\\-\\/:?@^' + uni.combine('Sm', 'So') + ']'
172 letter = '[_\\$' + uni.combine('Ll', 'Lu', 'Lo', 'Nl', 'Lt') + ']'
173 upperLetter = '[' + uni.combine('Lu', 'Lt') + ']'
174 letterOrDigit = '(?:%s|[0-9])' % letter
175 letterOrDigitNoDollarSign = '(?:%s|[0-9])' % letter.replace('\\$', '')
176 alphaId = '%s+' % letter
177 simpleInterpolatedVariable = '%s%s*' % (letter, letterOrDigitNoDollarSign)
178 idrest = '%s%s*(?:(?<=_)%s+)?' % (letter, letterOrDigit, opchar)
179 idUpper = '%s%s*(?:(?<=_)%s+)?' % (upperLetter, letterOrDigit, opchar)
180 plainid = '(?:%s|%s+)' % (idrest, opchar)
181 backQuotedId = r'`[^`]+`'
182 anyId = r'(?:%s|%s)' % (plainid, backQuotedId)
183 notStartOfComment = r'(?!//|/\*)'
184 endOfLineMaybeWithComment = r'(?=\s*(//|$))'
186 keywords = (
187 'new', 'return', 'throw', 'classOf', 'isInstanceOf', 'asInstanceOf',
188 'else', 'if', 'then', 'do', 'while', 'for', 'yield', 'match', 'case',
189 'catch', 'finally', 'try'
190 )
192 operators = (
193 '<%', '=:=', '<:<', '<%<', '>:', '<:', '=', '==', '!=', '<=', '>=',
194 '<>', '<', '>', '<-', '←', '->', '→', '=>', '⇒', '?', '@', '|', '-',
195 '+', '*', '%', '~', '\\'
196 )
198 storage_modifiers = (
199 'private', 'protected', 'synchronized', '@volatile', 'abstract',
200 'final', 'lazy', 'sealed', 'implicit', 'override', '@transient',
201 '@native'
202 )
204 tokens = {
205 'root': [
206 include('whitespace'),
207 include('comments'),
208 include('script-header'),
209 include('imports'),
210 include('exports'),
211 include('storage-modifiers'),
212 include('annotations'),
213 include('using'),
214 include('declarations'),
215 include('inheritance'),
216 include('extension'),
217 include('end'),
218 include('constants'),
219 include('strings'),
220 include('symbols'),
221 include('singleton-type'),
222 include('inline'),
223 include('quoted'),
224 include('keywords'),
225 include('operators'),
226 include('punctuation'),
227 include('names'),
228 ],
230 # Includes:
231 'whitespace': [
232 (r'\s+', Whitespace),
233 ],
234 'comments': [
235 (r'//.*?\n', Comment.Single),
236 (r'/\*', Comment.Multiline, 'comment'),
237 ],
238 'script-header': [
239 (r'^#!([^\n]*)$', Comment.Hashbang),
240 ],
241 'imports': [
242 (r'\b(import)(\s+)', bygroups(Keyword, Whitespace), 'import-path'),
243 ],
244 'exports': [
245 (r'\b(export)(\s+)(given)(\s+)',
246 bygroups(Keyword, Whitespace, Keyword, Whitespace), 'export-path'),
247 (r'\b(export)(\s+)', bygroups(Keyword, Whitespace), 'export-path'),
248 ],
249 'storage-modifiers': [
250 (words(storage_modifiers, prefix=r'\b', suffix=r'\b'), Keyword),
251 # Only highlight soft modifiers if they are eventually followed by
252 # the correct keyword. Note that soft modifiers can be followed by a
253 # sequence of regular modifiers; [a-z\s]* skips those, and we just
254 # check that the soft modifier is applied to a supported statement.
255 (r'\b(transparent|opaque|infix|open|inline)\b(?=[a-z\s]*\b'
256 r'(def|val|var|given|type|class|trait|object|enum)\b)', Keyword),
257 ],
258 'annotations': [
259 (r'@%s' % idrest, Name.Decorator),
260 ],
261 'using': [
262 # using is a soft keyword, can only be used in the first position of
263 # a parameter or argument list.
264 (r'(\()(\s*)(using)(\s)', bygroups(Punctuation, Whitespace, Keyword, Whitespace)),
265 ],
266 'declarations': [
267 (r'\b(def)\b(\s*)%s(%s)?' % (notStartOfComment, anyId),
268 bygroups(Keyword, Whitespace, Name.Function)),
269 (r'\b(trait)\b(\s*)%s(%s)?' % (notStartOfComment, anyId),
270 bygroups(Keyword, Whitespace, Name.Class)),
271 (r'\b(?:(case)(\s+))?(class|object|enum)\b(\s*)%s(%s)?' %
272 (notStartOfComment, anyId),
273 bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Class)),
274 (r'(?<!\.)\b(type)\b(\s*)%s(%s)?' % (notStartOfComment, anyId),
275 bygroups(Keyword, Whitespace, Name.Class)),
276 (r'\b(val|var)\b', Keyword.Declaration),
277 (r'\b(package)(\s+)(object)\b(\s*)%s(%s)?' %
278 (notStartOfComment, anyId),
279 bygroups(Keyword, Whitespace, Keyword, Whitespace, Name.Namespace)),
280 (r'\b(package)(\s+)', bygroups(Keyword, Whitespace), 'package'),
281 (r'\b(given)\b(\s*)(%s)' % idUpper,
282 bygroups(Keyword, Whitespace, Name.Class)),
283 (r'\b(given)\b(\s*)(%s)?' % anyId,
284 bygroups(Keyword, Whitespace, Name)),
285 ],
286 'inheritance': [
287 (r'\b(extends|with|derives)\b(\s*)'
288 r'(%s|%s|(?=\([^\)]+=>)|(?=%s)|(?="))?' %
289 (idUpper, backQuotedId, plainid),
290 bygroups(Keyword, Whitespace, Name.Class)),
291 ],
292 'extension': [
293 (r'\b(extension)(\s+)(?=[\[\(])', bygroups(Keyword, Whitespace)),
294 ],
295 'end': [
296 # end is a soft keyword, should only be highlighted in certain cases
297 (r'\b(end)(\s+)(if|while|for|match|new|extension|val|var)\b',
298 bygroups(Keyword, Whitespace, Keyword)),
299 (r'\b(end)(\s+)(%s)%s' % (idUpper, endOfLineMaybeWithComment),
300 bygroups(Keyword, Whitespace, Name.Class)),
301 (r'\b(end)(\s+)(%s|%s)?%s' %
302 (backQuotedId, plainid, endOfLineMaybeWithComment),
303 bygroups(Keyword, Whitespace, Name.Namespace)),
304 ],
305 'punctuation': [
306 (r'[{}()\[\];,.]', Punctuation),
307 (r'(?<!:):(?!:)', Punctuation),
308 ],
309 'keywords': [
310 (words(keywords, prefix=r'\b', suffix=r'\b'), Keyword),
311 ],
312 'operators': [
313 (r'(%s{2,})(\s+)' % opchar, bygroups(Operator, Whitespace)),
314 (r'/(?![/*])', Operator),
315 (words(operators), Operator),
316 (r'(?<!%s)(!|&&|\|\|)(?!%s)' % (opchar, opchar), Operator),
317 ],
318 'constants': [
319 (r'\b(this|super)\b', Name.Builtin.Pseudo),
320 (r'(true|false|null)\b', Keyword.Constant),
321 (r'0[xX][0-9a-fA-F_]*', Number.Hex),
322 (r'([0-9][0-9_]*\.[0-9][0-9_]*|\.[0-9][0-9_]*)'
323 r'([eE][+-]?[0-9][0-9_]*)?[fFdD]?', Number.Float),
324 (r'[0-9]+([eE][+-]?[0-9]+)?[fFdD]', Number.Float),
325 (r'[0-9]+([eE][+-]?[0-9]+)[fFdD]?', Number.Float),
326 (r'[0-9]+[lL]', Number.Integer.Long),
327 (r'[0-9]+', Number.Integer),
328 (r'""".*?"""(?!")', String),
329 (r'"(\\\\|\\"|[^"])*"', String),
330 (r"(')(\\.)(')", bygroups(String.Char, String.Escape, String.Char)),
331 (r"'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
332 ],
333 "strings": [
334 (r'[fs]"""', String, 'interpolated-string-triple'),
335 (r'[fs]"', String, 'interpolated-string'),
336 (r'raw"(\\\\|\\"|[^"])*"', String),
337 ],
338 'symbols': [
339 (r"('%s)(?!')" % plainid, String.Symbol),
340 ],
341 'singleton-type': [
342 (r'(\.)(type)\b', bygroups(Punctuation, Keyword)),
343 ],
344 'inline': [
345 # inline is a soft modifier, only highlighted if followed by if,
346 # match or parameters.
347 (r'\b(inline)(?=\s+(%s|%s)\s*:)' % (plainid, backQuotedId),
348 Keyword),
349 (r'\b(inline)\b(?=(?:.(?!\b(?:val|def|given)\b))*\b(if|match)\b)',
350 Keyword),
351 ],
352 'quoted': [
353 # '{...} or ${...}
354 (r"['$]\{(?!')", Punctuation),
355 # '[...]
356 (r"'\[(?!')", Punctuation),
357 ],
358 'names': [
359 (idUpper, Name.Class),
360 (anyId, Name),
361 ],
363 # States
364 'comment': [
365 (r'[^/*]+', Comment.Multiline),
366 (r'/\*', Comment.Multiline, '#push'),
367 (r'\*/', Comment.Multiline, '#pop'),
368 (r'[*/]', Comment.Multiline),
369 ],
370 'import-path': [
371 (r'(?<=[\n;:])', Text, '#pop'),
372 include('comments'),
373 (r'\b(given)\b', Keyword),
374 include('qualified-name'),
375 (r'\{', Punctuation, 'import-path-curly-brace'),
376 ],
377 'import-path-curly-brace': [
378 include('whitespace'),
379 include('comments'),
380 (r'\b(given)\b', Keyword),
381 (r'=>', Operator),
382 (r'\}', Punctuation, '#pop'),
383 (r',', Punctuation),
384 (r'[\[\]]', Punctuation),
385 include('qualified-name'),
386 ],
387 'export-path': [
388 (r'(?<=[\n;:])', Text, '#pop'),
389 include('comments'),
390 include('qualified-name'),
391 (r'\{', Punctuation, 'export-path-curly-brace'),
392 ],
393 'export-path-curly-brace': [
394 include('whitespace'),
395 include('comments'),
396 (r'=>', Operator),
397 (r'\}', Punctuation, '#pop'),
398 (r',', Punctuation),
399 include('qualified-name'),
400 ],
401 'package': [
402 (r'(?<=[\n;])', Text, '#pop'),
403 (r':', Punctuation, '#pop'),
404 include('comments'),
405 include('qualified-name'),
406 ],
407 'interpolated-string-triple': [
408 (r'"""(?!")', String, '#pop'),
409 (r'"', String),
410 include('interpolated-string-common'),
411 ],
412 'interpolated-string': [
413 (r'"', String, '#pop'),
414 include('interpolated-string-common'),
415 ],
416 'interpolated-string-brace': [
417 (r'\}', String.Interpol, '#pop'),
418 (r'\{', Punctuation, 'interpolated-string-nested-brace'),
419 include('root'),
420 ],
421 'interpolated-string-nested-brace': [
422 (r'\{', Punctuation, '#push'),
423 (r'\}', Punctuation, '#pop'),
424 include('root'),
425 ],
427 # Helpers
428 'qualified-name': [
429 (idUpper, Name.Class),
430 (r'(%s)(\.)' % anyId, bygroups(Name.Namespace, Punctuation)),
431 (r'\.', Punctuation),
432 (anyId, Name),
433 (r'[^\S\n]+', Whitespace),
434 ],
435 'interpolated-string-common': [
436 (r'[^"$\\]+', String),
437 (r'\$\$', String.Escape),
438 (r'(\$)(%s)' % simpleInterpolatedVariable,
439 bygroups(String.Interpol, Name)),
440 (r'\$\{', String.Interpol, 'interpolated-string-brace'),
441 (r'\\.', String),
442 ],
443 }
446class GosuLexer(RegexLexer):
447 """
448 For Gosu source code.
450 .. versionadded:: 1.5
451 """
453 name = 'Gosu'
454 aliases = ['gosu']
455 filenames = ['*.gs', '*.gsx', '*.gsp', '*.vark']
456 mimetypes = ['text/x-gosu']
458 flags = re.MULTILINE | re.DOTALL
460 tokens = {
461 'root': [
462 # method names
463 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # modifiers etc.
464 r'([a-zA-Z_]\w*)' # method name
465 r'(\s*)(\()', # signature start
466 bygroups(using(this), Name.Function, Whitespace, Operator)),
467 (r'[^\S\n]+', Whitespace),
468 (r'//.*?\n', Comment.Single),
469 (r'/\*.*?\*/', Comment.Multiline),
470 (r'@[a-zA-Z_][\w.]*', Name.Decorator),
471 (r'(in|as|typeof|statictypeof|typeis|typeas|if|else|foreach|for|'
472 r'index|while|do|continue|break|return|try|catch|finally|this|'
473 r'throw|new|switch|case|default|eval|super|outer|classpath|'
474 r'using)\b', Keyword),
475 (r'(var|delegate|construct|function|private|internal|protected|'
476 r'public|abstract|override|final|static|extends|transient|'
477 r'implements|represents|readonly)\b', Keyword.Declaration),
478 (r'(property)(\s+)(get|set)?', bygroups(Keyword.Declaration, Whitespace, Keyword.Declaration)),
479 (r'(boolean|byte|char|double|float|int|long|short|void|block)\b',
480 Keyword.Type),
481 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace)),
482 (r'(true|false|null|NaN|Infinity)\b', Keyword.Constant),
483 (r'(class|interface|enhancement|enum)(\s+)([a-zA-Z_]\w*)',
484 bygroups(Keyword.Declaration, Whitespace, Name.Class)),
485 (r'(uses)(\s+)([\w.]+\*?)',
486 bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
487 (r'"', String, 'string'),
488 (r'(\??[.#])([a-zA-Z_]\w*)',
489 bygroups(Operator, Name.Attribute)),
490 (r'(:)([a-zA-Z_]\w*)',
491 bygroups(Operator, Name.Attribute)),
492 (r'[a-zA-Z_$]\w*', Name),
493 (r'and|or|not|[\\~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
494 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
495 (r'[0-9]+', Number.Integer),
496 (r'\n', Whitespace)
497 ],
498 'templateText': [
499 (r'(\\<)|(\\\$)', String),
500 (r'(<%@\s+)(extends|params)',
501 bygroups(Operator, Name.Decorator), 'stringTemplate'),
502 (r'<%!--.*?--%>', Comment.Multiline),
503 (r'(<%)|(<%=)', Operator, 'stringTemplate'),
504 (r'\$\{', Operator, 'stringTemplateShorthand'),
505 (r'.', String)
506 ],
507 'string': [
508 (r'"', String, '#pop'),
509 include('templateText')
510 ],
511 'stringTemplate': [
512 (r'"', String, 'string'),
513 (r'%>', Operator, '#pop'),
514 include('root')
515 ],
516 'stringTemplateShorthand': [
517 (r'"', String, 'string'),
518 (r'\{', Operator, 'stringTemplateShorthand'),
519 (r'\}', Operator, '#pop'),
520 include('root')
521 ],
522 }
525class GosuTemplateLexer(Lexer):
526 """
527 For Gosu templates.
529 .. versionadded:: 1.5
530 """
532 name = 'Gosu Template'
533 aliases = ['gst']
534 filenames = ['*.gst']
535 mimetypes = ['text/x-gosu-template']
537 def get_tokens_unprocessed(self, text):
538 lexer = GosuLexer()
539 stack = ['templateText']
540 yield from lexer.get_tokens_unprocessed(text, stack)
543class GroovyLexer(RegexLexer):
544 """
545 For Groovy source code.
547 .. versionadded:: 1.5
548 """
550 name = 'Groovy'
551 url = 'https://groovy-lang.org/'
552 aliases = ['groovy']
553 filenames = ['*.groovy','*.gradle']
554 mimetypes = ['text/x-groovy']
556 flags = re.MULTILINE | re.DOTALL
558 tokens = {
559 'root': [
560 # Groovy allows a file to start with a shebang
561 (r'#!(.*?)$', Comment.Preproc, 'base'),
562 default('base'),
563 ],
564 'base': [
565 (r'[^\S\n]+', Whitespace),
566 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
567 (r'/\*.*?\*/', Comment.Multiline),
568 # keywords: go before method names to avoid lexing "throw new XYZ"
569 # as a method signature
570 (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
571 r'if|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b',
572 Keyword),
573 # method names
574 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments
575 r'('
576 r'[a-zA-Z_]\w*' # method name
577 r'|"(?:\\\\|\\[^\\]|[^"\\])*"' # or double-quoted method name
578 r"|'(?:\\\\|\\[^\\]|[^'\\])*'" # or single-quoted method name
579 r')'
580 r'(\s*)(\()', # signature start
581 bygroups(using(this), Name.Function, Whitespace, Operator)),
582 (r'@[a-zA-Z_][\w.]*', Name.Decorator),
583 (r'(abstract|const|enum|extends|final|implements|native|private|'
584 r'protected|public|static|strictfp|super|synchronized|throws|'
585 r'transient|volatile)\b', Keyword.Declaration),
586 (r'(def|boolean|byte|char|double|float|int|long|short|void)\b',
587 Keyword.Type),
588 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace)),
589 (r'(true|false|null)\b', Keyword.Constant),
590 (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Whitespace),
591 'class'),
592 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'),
593 (r'""".*?"""', String.Double),
594 (r"'''.*?'''", String.Single),
595 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
596 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
597 (r'\$/((?!/\$).)*/\$', String),
598 (r'/(\\\\|\\[^\\]|[^/\\])*/', String),
599 (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char),
600 (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)),
601 (r'[a-zA-Z_]\w*:', Name.Label),
602 (r'[a-zA-Z_$]\w*', Name),
603 (r'[~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
604 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
605 (r'0x[0-9a-fA-F]+', Number.Hex),
606 (r'[0-9]+L?', Number.Integer),
607 (r'\n', Whitespace)
608 ],
609 'class': [
610 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
611 ],
612 'import': [
613 (r'[\w.]+\*?', Name.Namespace, '#pop')
614 ],
615 }
617 def analyse_text(text):
618 return shebang_matches(text, r'groovy')
621class IokeLexer(RegexLexer):
622 """
623 For Ioke (a strongly typed, dynamic,
624 prototype based programming language) source.
626 .. versionadded:: 1.4
627 """
628 name = 'Ioke'
629 url = 'https://ioke.org/'
630 filenames = ['*.ik']
631 aliases = ['ioke', 'ik']
632 mimetypes = ['text/x-iokesrc']
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 ],
640 'text': [
641 (r'(?<!\\)"', String, '#pop'),
642 include('interpolatableText'),
643 (r'[^"]', String)
644 ],
646 'documentation': [
647 (r'(?<!\\)"', String.Doc, '#pop'),
648 include('interpolatableText'),
649 (r'[^"]', String.Doc)
650 ],
652 'textInterpolationRoot': [
653 (r'\}', Punctuation, '#pop'),
654 include('root')
655 ],
657 'slashRegexp': [
658 (r'(?<!\\)/[im-psux]*', String.Regex, '#pop'),
659 include('interpolatableText'),
660 (r'\\/', String.Regex),
661 (r'[^/]', String.Regex)
662 ],
664 'squareRegexp': [
665 (r'(?<!\\)][im-psux]*', String.Regex, '#pop'),
666 include('interpolatableText'),
667 (r'\\]', String.Regex),
668 (r'[^\]]', String.Regex)
669 ],
671 'squareText': [
672 (r'(?<!\\)]', String, '#pop'),
673 include('interpolatableText'),
674 (r'[^\]]', String)
675 ],
677 'root': [
678 (r'\n', Whitespace),
679 (r'\s+', Whitespace),
681 # Comments
682 (r';(.*?)\n', Comment),
683 (r'\A#!(.*?)\n', Comment),
685 # Regexps
686 (r'#/', String.Regex, 'slashRegexp'),
687 (r'#r\[', String.Regex, 'squareRegexp'),
689 # Symbols
690 (r':[\w!:?]+', String.Symbol),
691 (r'[\w!:?]+:(?![\w!?])', String.Other),
692 (r':"(\\\\|\\[^\\]|[^"\\])*"', String.Symbol),
694 # Documentation
695 (r'((?<=fn\()|(?<=fnx\()|(?<=method\()|(?<=macro\()|(?<=lecro\()'
696 r'|(?<=syntax\()|(?<=dmacro\()|(?<=dlecro\()|(?<=dlecrox\()'
697 r'|(?<=dsyntax\())(\s*)"', String.Doc, 'documentation'),
699 # Text
700 (r'"', String, 'text'),
701 (r'#\[', String, 'squareText'),
703 # Mimic
704 (r'\w[\w!:?]+(?=\s*=.*mimic\s)', Name.Entity),
706 # Assignment
707 (r'[a-zA-Z_][\w!:?]*(?=[\s]*[+*/-]?=[^=].*($|\.))',
708 Name.Variable),
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),
715 # Origin
716 (r'(eval|mimic|print|println)(?![\w!:?])', Keyword),
718 # Base
719 (r'(cell\?|cellNames|cellOwner\?|cellOwner|cells|cell|'
720 r'documentation|hash|identity|mimic|removeCell\!|undefineCell\!)'
721 r'(?![\w!:?])', Keyword),
723 # Ground
724 (r'(stackTraceAsText)(?![\w!:?])', Keyword),
726 # DefaultBehaviour Literals
727 (r'(dict|list|message|set)(?![\w!:?])', Keyword.Reserved),
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),
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),
739 # DefaultBehaviour Aspects
740 (r'(after|around|before)(?![\w!:?])', Keyword.Reserved),
742 # DefaultBehaviour
743 (r'(kind|cellDescriptionDict|cellSummary|genSym|inspect|notice)'
744 r'(?![\w!:?])', Keyword),
745 (r'(use|destructuring)', Keyword.Reserved),
747 # DefaultBehavior BaseBehavior
748 (r'(cell\?|cellOwner\?|cellOwner|cellNames|cells|cell|'
749 r'documentation|identity|removeCell!|undefineCell)'
750 r'(?![\w!:?])', Keyword),
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),
758 # DefaultBehaviour Conditions
759 (r'(availableRestarts|bind|error\!|findRestart|handle|'
760 r'invokeRestart|rescue|restart|signal\!|warn\!)'
761 r'(?![\w!:?])', Keyword.Reserved),
763 # constants
764 (r'(nil|false|true)(?![\w!:?])', Name.Constant),
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),
778 # functions
779 ('(generateMatchMethod|aliasMethod|\u03bb|\u028E|fnx|fn|method|'
780 'dmacro|dlecro|syntax|macro|dlecrox|lecrox|lecro|syntax)'
781 '(?![\\w!:?])', Name.Function),
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),
788 (r'#\(', Punctuation),
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),
801 # Punctuation
802 (r'(\`\`|\`|\'\'|\'|\.|\,|@@|@|\[|\]|\(|\)|\{|\})', Punctuation),
804 # kinds
805 (r'[A-Z][\w!:?]*', Name.Class),
807 # default cellnames
808 (r'[a-z_][\w!:?]*', Name)
809 ]
810 }
813class ClojureLexer(RegexLexer):
814 """
815 Lexer for Clojure source code.
817 .. versionadded:: 0.11
818 """
819 name = 'Clojure'
820 url = 'http://clojure.org/'
821 aliases = ['clojure', 'clj']
822 filenames = ['*.clj', '*.cljc']
823 mimetypes = ['text/x-clojure', 'application/x-clojure']
825 special_forms = (
826 '.', 'def', 'do', 'fn', 'if', 'let', 'new', 'quote', 'var', 'loop'
827 )
829 # It's safe to consider 'ns' a declaration thing because it defines a new
830 # namespace.
831 declarations = (
832 'def-', 'defn', 'defn-', 'defmacro', 'defmulti', 'defmethod',
833 'defstruct', 'defonce', 'declare', 'definline', 'definterface',
834 'defprotocol', 'defrecord', 'deftype', 'defproject', 'ns'
835 )
837 builtins = (
838 '*', '+', '-', '->', '/', '<', '<=', '=', '==', '>', '>=', '..',
839 'accessor', 'agent', 'agent-errors', 'aget', 'alength', 'all-ns',
840 'alter', 'and', 'append-child', 'apply', 'array-map', 'aset',
841 'aset-boolean', 'aset-byte', 'aset-char', 'aset-double', 'aset-float',
842 'aset-int', 'aset-long', 'aset-short', 'assert', 'assoc', 'await',
843 'await-for', 'bean', 'binding', 'bit-and', 'bit-not', 'bit-or',
844 'bit-shift-left', 'bit-shift-right', 'bit-xor', 'boolean', 'branch?',
845 'butlast', 'byte', 'cast', 'char', 'children', 'class',
846 'clear-agent-errors', 'comment', 'commute', 'comp', 'comparator',
847 'complement', 'concat', 'conj', 'cons', 'constantly', 'cond', 'if-not',
848 'construct-proxy', 'contains?', 'count', 'create-ns', 'create-struct',
849 'cycle', 'dec', 'deref', 'difference', 'disj', 'dissoc', 'distinct',
850 'doall', 'doc', 'dorun', 'doseq', 'dosync', 'dotimes', 'doto',
851 'double', 'down', 'drop', 'drop-while', 'edit', 'end?', 'ensure',
852 'eval', 'every?', 'false?', 'ffirst', 'file-seq', 'filter', 'find',
853 'find-doc', 'find-ns', 'find-var', 'first', 'float', 'flush', 'for',
854 'fnseq', 'frest', 'gensym', 'get-proxy-class', 'get',
855 'hash-map', 'hash-set', 'identical?', 'identity', 'if-let', 'import',
856 'in-ns', 'inc', 'index', 'insert-child', 'insert-left', 'insert-right',
857 'inspect-table', 'inspect-tree', 'instance?', 'int', 'interleave',
858 'intersection', 'into', 'into-array', 'iterate', 'join', 'key', 'keys',
859 'keyword', 'keyword?', 'last', 'lazy-cat', 'lazy-cons', 'left',
860 'lefts', 'line-seq', 'list*', 'list', 'load', 'load-file',
861 'locking', 'long', 'loop', 'macroexpand', 'macroexpand-1',
862 'make-array', 'make-node', 'map', 'map-invert', 'map?', 'mapcat',
863 'max', 'max-key', 'memfn', 'merge', 'merge-with', 'meta', 'min',
864 'min-key', 'name', 'namespace', 'neg?', 'new', 'newline', 'next',
865 'nil?', 'node', 'not', 'not-any?', 'not-every?', 'not=', 'ns-imports',
866 'ns-interns', 'ns-map', 'ns-name', 'ns-publics', 'ns-refers',
867 'ns-resolve', 'ns-unmap', 'nth', 'nthrest', 'or', 'parse', 'partial',
868 'path', 'peek', 'pop', 'pos?', 'pr', 'pr-str', 'print', 'print-str',
869 'println', 'println-str', 'prn', 'prn-str', 'project', 'proxy',
870 'proxy-mappings', 'quot', 'rand', 'rand-int', 'range', 're-find',
871 're-groups', 're-matcher', 're-matches', 're-pattern', 're-seq',
872 'read', 'read-line', 'reduce', 'ref', 'ref-set', 'refer', 'rem',
873 'remove', 'remove-method', 'remove-ns', 'rename', 'rename-keys',
874 'repeat', 'replace', 'replicate', 'resolve', 'rest', 'resultset-seq',
875 'reverse', 'rfirst', 'right', 'rights', 'root', 'rrest', 'rseq',
876 'second', 'select', 'select-keys', 'send', 'send-off', 'seq',
877 'seq-zip', 'seq?', 'set', 'short', 'slurp', 'some', 'sort',
878 'sort-by', 'sorted-map', 'sorted-map-by', 'sorted-set',
879 'special-symbol?', 'split-at', 'split-with', 'str', 'string?',
880 'struct', 'struct-map', 'subs', 'subvec', 'symbol', 'symbol?',
881 'sync', 'take', 'take-nth', 'take-while', 'test', 'time', 'to-array',
882 'to-array-2d', 'tree-seq', 'true?', 'union', 'up', 'update-proxy',
883 'val', 'vals', 'var-get', 'var-set', 'var?', 'vector', 'vector-zip',
884 'vector?', 'when', 'when-first', 'when-let', 'when-not',
885 'with-local-vars', 'with-meta', 'with-open', 'with-out-str',
886 'xml-seq', 'xml-zip', 'zero?', 'zipmap', 'zipper')
888 # valid names for identifiers
889 # well, names can only not consist fully of numbers
890 # but this should be good enough for now
892 # TODO / should divide keywords/symbols into namespace/rest
893 # but that's hard, so just pretend / is part of the name
894 valid_name = r'(?!#)[\w!$%*+<=>?/.#|-]+'
896 tokens = {
897 'root': [
898 # the comments - always starting with semicolon
899 # and going to the end of the line
900 (r';.*$', Comment.Single),
902 # whitespaces - usually not relevant
903 (r',+', Text),
904 (r'\s+', Whitespace),
906 # numbers
907 (r'-?\d+\.\d+', Number.Float),
908 (r'-?\d+/\d+', Number),
909 (r'-?\d+', Number.Integer),
910 (r'0x-?[abcdef\d]+', Number.Hex),
912 # strings, symbols and characters
913 (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
914 (r"'" + valid_name, String.Symbol),
915 (r"\\(.|[a-z]+)", String.Char),
917 # keywords
918 (r'::?#?' + valid_name, String.Symbol),
920 # special operators
921 (r'~@|[`\'#^~&@]', Operator),
923 # highlight the special forms
924 (words(special_forms, suffix=' '), Keyword),
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),
933 # highlight the builtins
934 (words(builtins, suffix=' '), Name.Builtin),
936 # the remaining functions
937 (r'(?<=\()' + valid_name, Name.Function),
939 # find the remaining variables
940 (valid_name, Name.Variable),
942 # Clojure accepts vector notation
943 (r'(\[|\])', Punctuation),
945 # Clojure accepts map notation
946 (r'(\{|\})', Punctuation),
948 # the famous parentheses!
949 (r'(\(|\))', Punctuation),
950 ],
951 }
954class ClojureScriptLexer(ClojureLexer):
955 """
956 Lexer for ClojureScript source code.
958 .. versionadded:: 2.0
959 """
960 name = 'ClojureScript'
961 url = 'http://clojure.org/clojurescript'
962 aliases = ['clojurescript', 'cljs']
963 filenames = ['*.cljs']
964 mimetypes = ['text/x-clojurescript', 'application/x-clojurescript']
967class TeaLangLexer(RegexLexer):
968 """
969 For Tea source code. Only used within a
970 TeaTemplateLexer.
972 .. versionadded:: 1.5
973 """
975 flags = re.MULTILINE | re.DOTALL
977 tokens = {
978 'root': [
979 # method names
980 (r'^(\s*(?:[a-zA-Z_][\w\.\[\]]*\s+)+?)' # return arguments
981 r'([a-zA-Z_]\w*)' # method name
982 r'(\s*)(\()', # signature start
983 bygroups(using(this), Name.Function, Whitespace, Operator)),
984 (r'[^\S\n]+', Whitespace),
985 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
986 (r'/\*.*?\*/', Comment.Multiline),
987 (r'@[a-zA-Z_][\w\.]*', Name.Decorator),
988 (r'(and|break|else|foreach|if|in|not|or|reverse)\b',
989 Keyword),
990 (r'(as|call|define)\b', Keyword.Declaration),
991 (r'(true|false|null)\b', Keyword.Constant),
992 (r'(template)(\s+)', bygroups(Keyword.Declaration, Whitespace), 'template'),
993 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'),
994 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
995 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
996 (r'(\.)([a-zA-Z_]\w*)', bygroups(Operator, Name.Attribute)),
997 (r'[a-zA-Z_]\w*:', Name.Label),
998 (r'[a-zA-Z_\$]\w*', Name),
999 (r'(isa|[.]{3}|[.]{2}|[=#!<>+-/%&;,.\*\\\(\)\[\]\{\}])', Operator),
1000 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1001 (r'0x[0-9a-fA-F]+', Number.Hex),
1002 (r'[0-9]+L?', Number.Integer),
1003 (r'\n', Whitespace)
1004 ],
1005 'template': [
1006 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
1007 ],
1008 'import': [
1009 (r'[\w.]+\*?', Name.Namespace, '#pop')
1010 ],
1011 }
1014class CeylonLexer(RegexLexer):
1015 """
1016 For Ceylon source code.
1018 .. versionadded:: 1.6
1019 """
1021 name = 'Ceylon'
1022 url = 'http://ceylon-lang.org/'
1023 aliases = ['ceylon']
1024 filenames = ['*.ceylon']
1025 mimetypes = ['text/x-ceylon']
1027 flags = re.MULTILINE | re.DOTALL
1029 #: optional Comment or Whitespace
1030 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
1032 tokens = {
1033 'root': [
1034 # method names
1035 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments
1036 r'([a-zA-Z_]\w*)' # method name
1037 r'(\s*)(\()', # signature start
1038 bygroups(using(this), Name.Function, Whitespace, Operator)),
1039 (r'[^\S\n]+', Whitespace),
1040 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
1041 (r'/\*', Comment.Multiline, 'comment'),
1042 (r'(shared|abstract|formal|default|actual|variable|deprecated|small|'
1043 r'late|literal|doc|by|see|throws|optional|license|tagged|final|native|'
1044 r'annotation|sealed)\b', Name.Decorator),
1045 (r'(break|case|catch|continue|else|finally|for|in|'
1046 r'if|return|switch|this|throw|try|while|is|exists|dynamic|'
1047 r'nonempty|then|outer|assert|let)\b', Keyword),
1048 (r'(abstracts|extends|satisfies|'
1049 r'super|given|of|out|assign)\b', Keyword.Declaration),
1050 (r'(function|value|void|new)\b',
1051 Keyword.Type),
1052 (r'(assembly|module|package)(\s+)', bygroups(Keyword.Namespace, Whitespace)),
1053 (r'(true|false|null)\b', Keyword.Constant),
1054 (r'(class|interface|object|alias)(\s+)',
1055 bygroups(Keyword.Declaration, Whitespace), 'class'),
1056 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'),
1057 (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
1058 (r"'\\.'|'[^\\]'|'\\\{#[0-9a-fA-F]{4}\}'", String.Char),
1059 (r'(\.)([a-z_]\w*)',
1060 bygroups(Operator, Name.Attribute)),
1061 (r'[a-zA-Z_]\w*:', Name.Label),
1062 (r'[a-zA-Z_]\w*', Name),
1063 (r'[~^*!%&\[\](){}<>|+=:;,./?-]', Operator),
1064 (r'\d{1,3}(_\d{3})+\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float),
1065 (r'\d{1,3}(_\d{3})+\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?',
1066 Number.Float),
1067 (r'[0-9][0-9]*\.\d{1,3}(_\d{3})+[kMGTPmunpf]?', Number.Float),
1068 (r'[0-9][0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[kMGTPmunpf]?',
1069 Number.Float),
1070 (r'#([0-9a-fA-F]{4})(_[0-9a-fA-F]{4})+', Number.Hex),
1071 (r'#[0-9a-fA-F]+', Number.Hex),
1072 (r'\$([01]{4})(_[01]{4})+', Number.Bin),
1073 (r'\$[01]+', Number.Bin),
1074 (r'\d{1,3}(_\d{3})+[kMGTP]?', Number.Integer),
1075 (r'[0-9]+[kMGTP]?', Number.Integer),
1076 (r'\n', Whitespace)
1077 ],
1078 'class': [
1079 (r'[A-Za-z_]\w*', Name.Class, '#pop')
1080 ],
1081 'import': [
1082 (r'[a-z][\w.]*',
1083 Name.Namespace, '#pop')
1084 ],
1085 'comment': [
1086 (r'[^*/]', Comment.Multiline),
1087 (r'/\*', Comment.Multiline, '#push'),
1088 (r'\*/', Comment.Multiline, '#pop'),
1089 (r'[*/]', Comment.Multiline)
1090 ],
1091 }
1094class KotlinLexer(RegexLexer):
1095 """
1096 For Kotlin source code.
1098 .. versionadded:: 1.5
1099 """
1101 name = 'Kotlin'
1102 url = 'http://kotlinlang.org/'
1103 aliases = ['kotlin']
1104 filenames = ['*.kt', '*.kts']
1105 mimetypes = ['text/x-kotlin']
1107 flags = re.MULTILINE | re.DOTALL
1109 kt_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +
1110 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 'Cf',
1111 'Mn', 'Mc') + ']*')
1113 kt_space_name = ('@?[_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl') + ']' +
1114 '[' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Nl', 'Nd', 'Pc', 'Cf',
1115 'Mn', 'Mc', 'Zs')
1116 + r'\'~!%^&*()+=|\[\]:;,.<>/\?-]*')
1118 kt_id = '(' + kt_name + '|`' + kt_space_name + '`)'
1120 modifiers = (r'actual|abstract|annotation|companion|const|crossinline|'
1121 r'data|enum|expect|external|final|infix|inline|inner|'
1122 r'internal|lateinit|noinline|open|operator|override|private|'
1123 r'protected|public|sealed|suspend|tailrec|value')
1125 tokens = {
1126 'root': [
1127 # Whitespaces
1128 (r'[^\S\n]+', Whitespace),
1129 (r'\s+', Whitespace),
1130 (r'\\$', String.Escape), # line continuation
1131 (r'\n', Whitespace),
1132 # Comments
1133 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
1134 (r'^(#!/.+?)(\n)', bygroups(Comment.Single, Whitespace)), # shebang for kotlin scripts
1135 (r'/[*].*?[*]/', Comment.Multiline),
1136 # Keywords
1137 (r'as\?', Keyword),
1138 (r'(as|break|by|catch|constructor|continue|do|dynamic|else|finally|'
1139 r'get|for|if|init|[!]*in|[!]*is|out|reified|return|set|super|this|'
1140 r'throw|try|typealias|typeof|vararg|when|where|while)\b', Keyword),
1141 (r'it\b', Name.Builtin),
1142 # Built-in types
1143 (words(('Boolean?', 'Byte?', 'Char?', 'Double?', 'Float?',
1144 'Int?', 'Long?', 'Short?', 'String?', 'Any?', 'Unit?')), Keyword.Type),
1145 (words(('Boolean', 'Byte', 'Char', 'Double', 'Float',
1146 'Int', 'Long', 'Short', 'String', 'Any', 'Unit'), suffix=r'\b'), Keyword.Type),
1147 # Constants
1148 (r'(true|false|null)\b', Keyword.Constant),
1149 # Imports
1150 (r'(package|import)(\s+)(\S+)', bygroups(Keyword, Whitespace, Name.Namespace)),
1151 # Dot access
1152 (r'(\?\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Operator, Name.Attribute)),
1153 (r'(\.)((?:[^\W\d]|\$)[\w$]*)', bygroups(Punctuation, Name.Attribute)),
1154 # Annotations
1155 (r'@[^\W\d][\w.]*', Name.Decorator),
1156 # Labels
1157 (r'[^\W\d][\w.]+@', Name.Decorator),
1158 # Object expression
1159 (r'(object)(\s+)(:)(\s+)', bygroups(Keyword, Whitespace, Punctuation, Whitespace), 'class'),
1160 # Types
1161 (r'((?:(?:' + modifiers + r'|fun)\s+)*)(class|interface|object)(\s+)',
1162 bygroups(using(this, state='modifiers'), Keyword.Declaration, Whitespace), 'class'),
1163 # Variables
1164 (r'(var|val)(\s+)(\()', bygroups(Keyword.Declaration, Whitespace, Punctuation),
1165 'destructuring_assignment'),
1166 (r'((?:(?:' + modifiers + r')\s+)*)(var|val)(\s+)',
1167 bygroups(using(this, state='modifiers'), Keyword.Declaration, Whitespace), 'variable'),
1168 # Functions
1169 (r'((?:(?:' + modifiers + r')\s+)*)(fun)(\s+)',
1170 bygroups(using(this, state='modifiers'), Keyword.Declaration, Whitespace), 'function'),
1171 # Operators
1172 (r'::|!!|\?[:.]', Operator),
1173 (r'[~^*!%&\[\]<>|+=/?-]', Operator),
1174 # Punctuation
1175 (r'[{}();:.,]', Punctuation),
1176 # Strings
1177 (r'"""', String, 'multiline_string'),
1178 (r'"', String, 'string'),
1179 (r"'\\.'|'[^\\]'", String.Char),
1180 # Numbers
1181 (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFL]?|"
1182 r"0[xX][0-9a-fA-F]+[Ll]?", Number),
1183 # Identifiers
1184 (r'' + kt_id + r'((\?[^.])?)', Name) # additionally handle nullable types
1185 ],
1186 'class': [
1187 (kt_id, Name.Class, '#pop')
1188 ],
1189 'variable': [
1190 (kt_id, Name.Variable, '#pop')
1191 ],
1192 'destructuring_assignment': [
1193 (r',', Punctuation),
1194 (r'\s+', Whitespace),
1195 (kt_id, Name.Variable),
1196 (r'(:)(\s+)(' + kt_id + ')', bygroups(Punctuation, Whitespace, Name)),
1197 (r'<', Operator, 'generic'),
1198 (r'\)', Punctuation, '#pop')
1199 ],
1200 'function': [
1201 (r'<', Operator, 'generic'),
1202 (r'' + kt_id + r'(\.)' + kt_id, bygroups(Name, Punctuation, Name.Function), '#pop'),
1203 (kt_id, Name.Function, '#pop')
1204 ],
1205 'generic': [
1206 (r'(>)(\s*)', bygroups(Operator, Whitespace), '#pop'),
1207 (r':', Punctuation),
1208 (r'(reified|out|in)\b', Keyword),
1209 (r',', Punctuation),
1210 (r'\s+', Whitespace),
1211 (kt_id, Name)
1212 ],
1213 'modifiers': [
1214 (r'\w+', Keyword.Declaration),
1215 (r'\s+', Whitespace),
1216 default('#pop')
1217 ],
1218 'string': [
1219 (r'"', String, '#pop'),
1220 include('string_common')
1221 ],
1222 'multiline_string': [
1223 (r'"""', String, '#pop'),
1224 (r'"', String),
1225 include('string_common')
1226 ],
1227 'string_common': [
1228 (r'\\\\', String), # escaped backslash
1229 (r'\\"', String), # escaped quote
1230 (r'\\', String), # bare backslash
1231 (r'\$\{', String.Interpol, 'interpolation'),
1232 (r'(\$)(\w+)', bygroups(String.Interpol, Name)),
1233 (r'[^\\"$]+', String)
1234 ],
1235 'interpolation': [
1236 (r'"', String),
1237 (r'\$\{', String.Interpol, 'interpolation'),
1238 (r'\{', Punctuation, 'scope'),
1239 (r'\}', String.Interpol, '#pop'),
1240 include('root')
1241 ],
1242 'scope': [
1243 (r'\{', Punctuation, 'scope'),
1244 (r'\}', Punctuation, '#pop'),
1245 include('root')
1246 ]
1247 }
1250class XtendLexer(RegexLexer):
1251 """
1252 For Xtend source code.
1254 .. versionadded:: 1.6
1255 """
1257 name = 'Xtend'
1258 url = 'https://www.eclipse.org/xtend/'
1259 aliases = ['xtend']
1260 filenames = ['*.xtend']
1261 mimetypes = ['text/x-xtend']
1263 flags = re.MULTILINE | re.DOTALL
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)\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 }
1316class PigLexer(RegexLexer):
1317 """
1318 For Pig Latin source code.
1320 .. versionadded:: 2.0
1321 """
1323 name = 'Pig'
1324 url = 'https://pig.apache.org/'
1325 aliases = ['pig']
1326 filenames = ['*.pig']
1327 mimetypes = ['text/x-pig']
1329 flags = re.MULTILINE | re.IGNORECASE
1331 tokens = {
1332 'root': [
1333 (r'\s+', Whitespace),
1334 (r'--.*', Comment),
1335 (r'/\*[\w\W]*?\*/', Comment.Multiline),
1336 (r'\\$', String.Escape),
1337 (r'\\', Text),
1338 (r'\'(?:\\[ntbrf\\\']|\\u[0-9a-f]{4}|[^\'\\\n\r])*\'', String),
1339 include('keywords'),
1340 include('types'),
1341 include('builtins'),
1342 include('punct'),
1343 include('operators'),
1344 (r'[0-9]*\.[0-9]+(e[0-9]+)?[fd]?', Number.Float),
1345 (r'0x[0-9a-f]+', Number.Hex),
1346 (r'[0-9]+L?', Number.Integer),
1347 (r'\n', Whitespace),
1348 (r'([a-z_]\w*)(\s*)(\()',
1349 bygroups(Name.Function, Whitespace, Punctuation)),
1350 (r'[()#:]', Text),
1351 (r'[^(:#\'")\s]+', Text),
1352 (r'\S+\s+', Text) # TODO: make tests pass without \s+
1353 ],
1354 'keywords': [
1355 (r'(assert|and|any|all|arrange|as|asc|bag|by|cache|CASE|cat|cd|cp|'
1356 r'%declare|%default|define|dense|desc|describe|distinct|du|dump|'
1357 r'eval|exex|explain|filter|flatten|foreach|full|generate|group|'
1358 r'help|if|illustrate|import|inner|input|into|is|join|kill|left|'
1359 r'limit|load|ls|map|matches|mkdir|mv|not|null|onschema|or|order|'
1360 r'outer|output|parallel|pig|pwd|quit|register|returns|right|rm|'
1361 r'rmf|rollup|run|sample|set|ship|split|stderr|stdin|stdout|store|'
1362 r'stream|through|union|using|void)\b', Keyword)
1363 ],
1364 'builtins': [
1365 (r'(AVG|BinStorage|cogroup|CONCAT|copyFromLocal|copyToLocal|COUNT|'
1366 r'cross|DIFF|MAX|MIN|PigDump|PigStorage|SIZE|SUM|TextLoader|'
1367 r'TOKENIZE)\b', Name.Builtin)
1368 ],
1369 'types': [
1370 (r'(bytearray|BIGINTEGER|BIGDECIMAL|chararray|datetime|double|float|'
1371 r'int|long|tuple)\b', Keyword.Type)
1372 ],
1373 'punct': [
1374 (r'[;(){}\[\]]', Punctuation),
1375 ],
1376 'operators': [
1377 (r'[#=,./%+\-?]', Operator),
1378 (r'(eq|gt|lt|gte|lte|neq|matches)\b', Operator),
1379 (r'(==|<=|<|>=|>|!=)', Operator),
1380 ],
1381 }
1384class GoloLexer(RegexLexer):
1385 """
1386 For Golo source code.
1388 .. versionadded:: 2.0
1389 """
1391 name = 'Golo'
1392 url = 'http://golo-lang.org/'
1393 filenames = ['*.golo']
1394 aliases = ['golo']
1396 tokens = {
1397 'root': [
1398 (r'[^\S\n]+', Whitespace),
1400 (r'#.*$', Comment),
1402 (r'(\^|\.\.\.|:|\?:|->|==|!=|=|\+|\*|%|/|<=|<|>=|>|=|\.)',
1403 Operator),
1404 (r'(?<=[^-])(-)(?=[^-])', Operator),
1406 (r'(?<=[^`])(is|isnt|and|or|not|oftype|in|orIfNull)\b', Operator.Word),
1407 (r'[]{}|(),[]', Punctuation),
1409 (r'(module|import)(\s+)',
1410 bygroups(Keyword.Namespace, Whitespace),
1411 'modname'),
1412 (r'\b([a-zA-Z_][\w$.]*)(::)', bygroups(Name.Namespace, Punctuation)),
1413 (r'\b([a-zA-Z_][\w$]*(?:\.[a-zA-Z_][\w$]*)+)\b', Name.Namespace),
1415 (r'(let|var)(\s+)',
1416 bygroups(Keyword.Declaration, Whitespace),
1417 'varname'),
1418 (r'(struct)(\s+)',
1419 bygroups(Keyword.Declaration, Whitespace),
1420 'structname'),
1421 (r'(function)(\s+)',
1422 bygroups(Keyword.Declaration, Whitespace),
1423 'funcname'),
1425 (r'(null|true|false)\b', Keyword.Constant),
1426 (r'(augment|pimp'
1427 r'|if|else|case|match|return'
1428 r'|case|when|then|otherwise'
1429 r'|while|for|foreach'
1430 r'|try|catch|finally|throw'
1431 r'|local'
1432 r'|continue|break)\b', Keyword),
1434 (r'(map|array|list|set|vector|tuple)(\[)',
1435 bygroups(Name.Builtin, Punctuation)),
1436 (r'(print|println|readln|raise|fun'
1437 r'|asInterfaceInstance)\b', Name.Builtin),
1438 (r'(`?[a-zA-Z_][\w$]*)(\()',
1439 bygroups(Name.Function, Punctuation)),
1441 (r'-?[\d_]*\.[\d_]*([eE][+-]?\d[\d_]*)?F?', Number.Float),
1442 (r'0[0-7]+j?', Number.Oct),
1443 (r'0[xX][a-fA-F0-9]+', Number.Hex),
1444 (r'-?\d[\d_]*L', Number.Integer.Long),
1445 (r'-?\d[\d_]*', Number.Integer),
1447 (r'`?[a-zA-Z_][\w$]*', Name),
1448 (r'@[a-zA-Z_][\w$.]*', Name.Decorator),
1450 (r'"""', String, combined('stringescape', 'triplestring')),
1451 (r'"', String, combined('stringescape', 'doublestring')),
1452 (r"'", String, combined('stringescape', 'singlestring')),
1453 (r'----((.|\n)*?)----', String.Doc)
1455 ],
1457 'funcname': [
1458 (r'`?[a-zA-Z_][\w$]*', Name.Function, '#pop'),
1459 ],
1460 'modname': [
1461 (r'[a-zA-Z_][\w$.]*\*?', Name.Namespace, '#pop')
1462 ],
1463 'structname': [
1464 (r'`?[\w.]+\*?', Name.Class, '#pop')
1465 ],
1466 'varname': [
1467 (r'`?[a-zA-Z_][\w$]*', Name.Variable, '#pop'),
1468 ],
1469 'string': [
1470 (r'[^\\\'"\n]+', String),
1471 (r'[\'"\\]', String)
1472 ],
1473 'stringescape': [
1474 (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|'
1475 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
1476 ],
1477 'triplestring': [
1478 (r'"""', String, '#pop'),
1479 include('string'),
1480 (r'\n', String),
1481 ],
1482 'doublestring': [
1483 (r'"', String.Double, '#pop'),
1484 include('string'),
1485 ],
1486 'singlestring': [
1487 (r"'", String, '#pop'),
1488 include('string'),
1489 ],
1490 'operators': [
1491 (r'[#=,./%+\-?]', Operator),
1492 (r'(eq|gt|lt|gte|lte|neq|matches)\b', Operator),
1493 (r'(==|<=|<|>=|>|!=)', Operator),
1494 ],
1495 }
1498class JasminLexer(RegexLexer):
1499 """
1500 For Jasmin assembly code.
1502 .. versionadded:: 2.0
1503 """
1505 name = 'Jasmin'
1506 url = 'http://jasmin.sourceforge.net/'
1507 aliases = ['jasmin', 'jasminxt']
1508 filenames = ['*.j']
1510 _whitespace = r' \n\t\r'
1511 _ws = r'(?:[%s]+)' % _whitespace
1512 _separator = r'%s:=' % _whitespace
1513 _break = r'(?=[%s]|$)' % _separator
1514 _name = r'[^%s]+' % _separator
1515 _unqualified_name = r'(?:[^%s.;\[/]+)' % _separator
1517 tokens = {
1518 'default': [
1519 (r'\n', Whitespace, '#pop'),
1520 (r"'", String.Single, ('#pop', 'quote')),
1521 (r'"', String.Double, 'string'),
1522 (r'=', Punctuation),
1523 (r':', Punctuation, 'label'),
1524 (_ws, Whitespace),
1525 (r';.*', Comment.Single),
1526 (r'(\$[-+])?0x-?[\da-fA-F]+%s' % _break, Number.Hex),
1527 (r'(\$[-+]|\+)?-?\d+%s' % _break, Number.Integer),
1528 (r'-?(\d+\.\d*|\.\d+)([eE][-+]?\d+)?[fFdD]?'
1529 r'[\x00-\x08\x0b\x0c\x0e-\x1f]*%s' % _break, Number.Float),
1530 (r'\$%s' % _name, Name.Variable),
1532 # Directives
1533 (r'\.annotation%s' % _break, Keyword.Reserved, 'annotation'),
1534 (r'(\.attribute|\.bytecode|\.debug|\.deprecated|\.enclosing|'
1535 r'\.interface|\.line|\.signature|\.source|\.stack|\.var|abstract|'
1536 r'annotation|bridge|class|default|enum|field|final|fpstrict|'
1537 r'interface|native|private|protected|public|signature|static|'
1538 r'synchronized|synthetic|transient|varargs|volatile)%s' % _break,
1539 Keyword.Reserved),
1540 (r'\.catch%s' % _break, Keyword.Reserved, 'caught-exception'),
1541 (r'(\.class|\.implements|\.inner|\.super|inner|invisible|'
1542 r'invisibleparam|outer|visible|visibleparam)%s' % _break,
1543 Keyword.Reserved, 'class/convert-dots'),
1544 (r'\.field%s' % _break, Keyword.Reserved,
1545 ('descriptor/convert-dots', 'field')),
1546 (r'(\.end|\.limit|use)%s' % _break, Keyword.Reserved,
1547 'no-verification'),
1548 (r'\.method%s' % _break, Keyword.Reserved, 'method'),
1549 (r'\.set%s' % _break, Keyword.Reserved, 'var'),
1550 (r'\.throws%s' % _break, Keyword.Reserved, 'exception'),
1551 (r'(from|offset|to|using)%s' % _break, Keyword.Reserved, 'label'),
1552 (r'is%s' % _break, Keyword.Reserved,
1553 ('descriptor/convert-dots', 'var')),
1554 (r'(locals|stack)%s' % _break, Keyword.Reserved, 'verification'),
1555 (r'method%s' % _break, Keyword.Reserved, 'enclosing-method'),
1557 # Instructions
1558 (words((
1559 'aaload', 'aastore', 'aconst_null', 'aload', 'aload_0', 'aload_1', 'aload_2',
1560 'aload_3', 'aload_w', 'areturn', 'arraylength', 'astore', 'astore_0', 'astore_1',
1561 'astore_2', 'astore_3', 'astore_w', 'athrow', 'baload', 'bastore', 'bipush',
1562 'breakpoint', 'caload', 'castore', 'd2f', 'd2i', 'd2l', 'dadd', 'daload', 'dastore',
1563 'dcmpg', 'dcmpl', 'dconst_0', 'dconst_1', 'ddiv', 'dload', 'dload_0', 'dload_1',
1564 'dload_2', 'dload_3', 'dload_w', 'dmul', 'dneg', 'drem', 'dreturn', 'dstore', 'dstore_0',
1565 'dstore_1', 'dstore_2', 'dstore_3', 'dstore_w', 'dsub', 'dup', 'dup2', 'dup2_x1',
1566 'dup2_x2', 'dup_x1', 'dup_x2', 'f2d', 'f2i', 'f2l', 'fadd', 'faload', 'fastore', 'fcmpg',
1567 'fcmpl', 'fconst_0', 'fconst_1', 'fconst_2', 'fdiv', 'fload', 'fload_0', 'fload_1',
1568 'fload_2', 'fload_3', 'fload_w', 'fmul', 'fneg', 'frem', 'freturn', 'fstore', 'fstore_0',
1569 'fstore_1', 'fstore_2', 'fstore_3', 'fstore_w', 'fsub', 'i2b', 'i2c', 'i2d', 'i2f', 'i2l',
1570 'i2s', 'iadd', 'iaload', 'iand', 'iastore', 'iconst_0', 'iconst_1', 'iconst_2',
1571 'iconst_3', 'iconst_4', 'iconst_5', 'iconst_m1', 'idiv', 'iinc', 'iinc_w', 'iload',
1572 'iload_0', 'iload_1', 'iload_2', 'iload_3', 'iload_w', 'imul', 'ineg', 'int2byte',
1573 'int2char', 'int2short', 'ior', 'irem', 'ireturn', 'ishl', 'ishr', 'istore', 'istore_0',
1574 'istore_1', 'istore_2', 'istore_3', 'istore_w', 'isub', 'iushr', 'ixor', 'l2d', 'l2f',
1575 'l2i', 'ladd', 'laload', 'land', 'lastore', 'lcmp', 'lconst_0', 'lconst_1', 'ldc2_w',
1576 'ldiv', 'lload', 'lload_0', 'lload_1', 'lload_2', 'lload_3', 'lload_w', 'lmul', 'lneg',
1577 'lookupswitch', 'lor', 'lrem', 'lreturn', 'lshl', 'lshr', 'lstore', 'lstore_0',
1578 'lstore_1', 'lstore_2', 'lstore_3', 'lstore_w', 'lsub', 'lushr', 'lxor',
1579 'monitorenter', 'monitorexit', 'nop', 'pop', 'pop2', 'ret', 'ret_w', 'return', 'saload',
1580 'sastore', 'sipush', 'swap'), suffix=_break), Keyword.Reserved),
1581 (r'(anewarray|checkcast|instanceof|ldc|ldc_w|new)%s' % _break,
1582 Keyword.Reserved, 'class/no-dots'),
1583 (r'invoke(dynamic|interface|nonvirtual|special|'
1584 r'static|virtual)%s' % _break, Keyword.Reserved,
1585 'invocation'),
1586 (r'(getfield|putfield)%s' % _break, Keyword.Reserved,
1587 ('descriptor/no-dots', 'field')),
1588 (r'(getstatic|putstatic)%s' % _break, Keyword.Reserved,
1589 ('descriptor/no-dots', 'static')),
1590 (words((
1591 'goto', 'goto_w', 'if_acmpeq', 'if_acmpne', 'if_icmpeq',
1592 'if_icmpge', 'if_icmpgt', 'if_icmple', 'if_icmplt', 'if_icmpne',
1593 'ifeq', 'ifge', 'ifgt', 'ifle', 'iflt', 'ifne', 'ifnonnull',
1594 'ifnull', 'jsr', 'jsr_w'), suffix=_break),
1595 Keyword.Reserved, 'label'),
1596 (r'(multianewarray|newarray)%s' % _break, Keyword.Reserved,
1597 'descriptor/convert-dots'),
1598 (r'tableswitch%s' % _break, Keyword.Reserved, 'table')
1599 ],
1600 'quote': [
1601 (r"'", String.Single, '#pop'),
1602 (r'\\u[\da-fA-F]{4}', String.Escape),
1603 (r"[^'\\]+", String.Single)
1604 ],
1605 'string': [
1606 (r'"', String.Double, '#pop'),
1607 (r'\\([nrtfb"\'\\]|u[\da-fA-F]{4}|[0-3]?[0-7]{1,2})',
1608 String.Escape),
1609 (r'[^"\\]+', String.Double)
1610 ],
1611 'root': [
1612 (r'\n+', Whitespace),
1613 (r"'", String.Single, 'quote'),
1614 include('default'),
1615 (r'(%s)([ \t\r]*)(:)' % _name,
1616 bygroups(Name.Label, Whitespace, Punctuation)),
1617 (_name, String.Other)
1618 ],
1619 'annotation': [
1620 (r'\n', Whitespace, ('#pop', 'annotation-body')),
1621 (r'default%s' % _break, Keyword.Reserved,
1622 ('#pop', 'annotation-default')),
1623 include('default')
1624 ],
1625 'annotation-body': [
1626 (r'\n+', Whitespace),
1627 (r'\.end%s' % _break, Keyword.Reserved, '#pop'),
1628 include('default'),
1629 (_name, String.Other, ('annotation-items', 'descriptor/no-dots'))
1630 ],
1631 'annotation-default': [
1632 (r'\n+', Whitespace),
1633 (r'\.end%s' % _break, Keyword.Reserved, '#pop'),
1634 include('default'),
1635 default(('annotation-items', 'descriptor/no-dots'))
1636 ],
1637 'annotation-items': [
1638 (r"'", String.Single, 'quote'),
1639 include('default'),
1640 (_name, String.Other)
1641 ],
1642 'caught-exception': [
1643 (r'all%s' % _break, Keyword, '#pop'),
1644 include('exception')
1645 ],
1646 'class/convert-dots': [
1647 include('default'),
1648 (r'(L)((?:%s[/.])*)(%s)(;)' % (_unqualified_name, _name),
1649 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1650 '#pop'),
1651 (r'((?:%s[/.])*)(%s)' % (_unqualified_name, _name),
1652 bygroups(Name.Namespace, Name.Class), '#pop')
1653 ],
1654 'class/no-dots': [
1655 include('default'),
1656 (r'\[+', Punctuation, ('#pop', 'descriptor/no-dots')),
1657 (r'(L)((?:%s/)*)(%s)(;)' % (_unqualified_name, _name),
1658 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1659 '#pop'),
1660 (r'((?:%s/)*)(%s)' % (_unqualified_name, _name),
1661 bygroups(Name.Namespace, Name.Class), '#pop')
1662 ],
1663 'descriptor/convert-dots': [
1664 include('default'),
1665 (r'\[+', Punctuation),
1666 (r'(L)((?:%s[/.])*)(%s?)(;)' % (_unqualified_name, _name),
1667 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1668 '#pop'),
1669 (r'[^%s\[)L]+' % _separator, Keyword.Type, '#pop'),
1670 default('#pop')
1671 ],
1672 'descriptor/no-dots': [
1673 include('default'),
1674 (r'\[+', Punctuation),
1675 (r'(L)((?:%s/)*)(%s)(;)' % (_unqualified_name, _name),
1676 bygroups(Keyword.Type, Name.Namespace, Name.Class, Punctuation),
1677 '#pop'),
1678 (r'[^%s\[)L]+' % _separator, Keyword.Type, '#pop'),
1679 default('#pop')
1680 ],
1681 'descriptors/convert-dots': [
1682 (r'\)', Punctuation, '#pop'),
1683 default('descriptor/convert-dots')
1684 ],
1685 'enclosing-method': [
1686 (_ws, Whitespace),
1687 (r'(?=[^%s]*\()' % _separator, Text, ('#pop', 'invocation')),
1688 default(('#pop', 'class/convert-dots'))
1689 ],
1690 'exception': [
1691 include('default'),
1692 (r'((?:%s[/.])*)(%s)' % (_unqualified_name, _name),
1693 bygroups(Name.Namespace, Name.Exception), '#pop')
1694 ],
1695 'field': [
1696 (r'static%s' % _break, Keyword.Reserved, ('#pop', 'static')),
1697 include('default'),
1698 (r'((?:%s[/.](?=[^%s]*[/.]))*)(%s[/.])?(%s)' %
1699 (_unqualified_name, _separator, _unqualified_name, _name),
1700 bygroups(Name.Namespace, Name.Class, Name.Variable.Instance),
1701 '#pop')
1702 ],
1703 'invocation': [
1704 include('default'),
1705 (r'((?:%s[/.](?=[^%s(]*[/.]))*)(%s[/.])?(%s)(\()' %
1706 (_unqualified_name, _separator, _unqualified_name, _name),
1707 bygroups(Name.Namespace, Name.Class, Name.Function, Punctuation),
1708 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots',
1709 'descriptor/convert-dots'))
1710 ],
1711 'label': [
1712 include('default'),
1713 (_name, Name.Label, '#pop')
1714 ],
1715 'method': [
1716 include('default'),
1717 (r'(%s)(\()' % _name, bygroups(Name.Function, Punctuation),
1718 ('#pop', 'descriptor/convert-dots', 'descriptors/convert-dots',
1719 'descriptor/convert-dots'))
1720 ],
1721 'no-verification': [
1722 (r'(locals|method|stack)%s' % _break, Keyword.Reserved, '#pop'),
1723 include('default')
1724 ],
1725 'static': [
1726 include('default'),
1727 (r'((?:%s[/.](?=[^%s]*[/.]))*)(%s[/.])?(%s)' %
1728 (_unqualified_name, _separator, _unqualified_name, _name),
1729 bygroups(Name.Namespace, Name.Class, Name.Variable.Class), '#pop')
1730 ],
1731 'table': [
1732 (r'\n+', Whitespace),
1733 (r'default%s' % _break, Keyword.Reserved, '#pop'),
1734 include('default'),
1735 (_name, Name.Label)
1736 ],
1737 'var': [
1738 include('default'),
1739 (_name, Name.Variable, '#pop')
1740 ],
1741 'verification': [
1742 include('default'),
1743 (r'(Double|Float|Integer|Long|Null|Top|UninitializedThis)%s' %
1744 _break, Keyword, '#pop'),
1745 (r'Object%s' % _break, Keyword, ('#pop', 'class/no-dots')),
1746 (r'Uninitialized%s' % _break, Keyword, ('#pop', 'label'))
1747 ]
1748 }
1750 def analyse_text(text):
1751 score = 0
1752 if re.search(r'^\s*\.class\s', text, re.MULTILINE):
1753 score += 0.5
1754 if re.search(r'^\s*[a-z]+_[a-z]+\b', text, re.MULTILINE):
1755 score += 0.3
1756 if re.search(r'^\s*\.(attribute|bytecode|debug|deprecated|enclosing|'
1757 r'inner|interface|limit|set|signature|stack)\b', text,
1758 re.MULTILINE):
1759 score += 0.6
1760 return min(score, 1.0)
1763class SarlLexer(RegexLexer):
1764 """
1765 For SARL source code.
1767 .. versionadded:: 2.4
1768 """
1770 name = 'SARL'
1771 url = 'http://www.sarl.io'
1772 aliases = ['sarl']
1773 filenames = ['*.sarl']
1774 mimetypes = ['text/x-sarl']
1776 flags = re.MULTILINE | re.DOTALL
1778 tokens = {
1779 'root': [
1780 # method names
1781 (r'^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)' # return arguments
1782 r'([a-zA-Z_$][\w$]*)' # method name
1783 r'(\s*)(\()', # signature start
1784 bygroups(using(this), Name.Function, Whitespace, Operator)),
1785 (r'[^\S\n]+', Whitespace),
1786 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)),
1787 (r'/\*.*?\*/', Comment.Multiline),
1788 (r'@[a-zA-Z_][\w.]*', Name.Decorator),
1789 (r'(as|break|case|catch|default|do|else|extends|extension|finally|'
1790 r'fires|for|if|implements|instanceof|new|on|requires|return|super|'
1791 r'switch|throw|throws|try|typeof|uses|while|with)\b',
1792 Keyword),
1793 (r'(abstract|def|dispatch|final|native|override|private|protected|'
1794 r'public|static|strictfp|synchronized|transient|val|var|volatile)\b',
1795 Keyword.Declaration),
1796 (r'(boolean|byte|char|double|float|int|long|short|void)\b',
1797 Keyword.Type),
1798 (r'(package)(\s+)', bygroups(Keyword.Namespace, Whitespace)),
1799 (r'(false|it|null|occurrence|this|true|void)\b', Keyword.Constant),
1800 (r'(agent|annotation|artifact|behavior|capacity|class|enum|event|'
1801 r'interface|skill|space)(\s+)', bygroups(Keyword.Declaration, Whitespace),
1802 'class'),
1803 (r'(import)(\s+)', bygroups(Keyword.Namespace, Whitespace), 'import'),
1804 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
1805 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
1806 (r'[a-zA-Z_]\w*:', Name.Label),
1807 (r'[a-zA-Z_$]\w*', Name),
1808 (r'[~^*!%&\[\](){}<>\|+=:;,./?-]', Operator),
1809 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1810 (r'0x[0-9a-fA-F]+', Number.Hex),
1811 (r'[0-9]+L?', Number.Integer),
1812 (r'\n', Whitespace)
1813 ],
1814 'class': [
1815 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
1816 ],
1817 'import': [
1818 (r'[\w.]+\*?', Name.Namespace, '#pop')
1819 ],
1820 }