1"""
2 pygments.lexers.scripting
3 ~~~~~~~~~~~~~~~~~~~~~~~~~
4
5 Lexer for scripting and embedded 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 RegexLexer, include, bygroups, default, combined, \
14 words
15from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 Number, Punctuation, Error, Whitespace, Other
17from pygments.util import get_bool_opt, get_list_opt
18
19__all__ = ['LuaLexer', 'LuauLexer', 'MoonScriptLexer', 'ChaiscriptLexer', 'LSLLexer',
20 'AppleScriptLexer', 'RexxLexer', 'MOOCodeLexer', 'HybrisLexer',
21 'EasytrieveLexer', 'JclLexer', 'MiniScriptLexer']
22
23
24def all_lua_builtins():
25 from pygments.lexers._lua_builtins import MODULES
26 return [w for values in MODULES.values() for w in values]
27
28class LuaLexer(RegexLexer):
29 """
30 For Lua source code.
31
32 Additional options accepted:
33
34 `func_name_highlighting`
35 If given and ``True``, highlight builtin function names
36 (default: ``True``).
37 `disabled_modules`
38 If given, must be a list of module names whose function names
39 should not be highlighted. By default, all modules are highlighted.
40
41 To get a list of allowed modules have a look into the
42 `_lua_builtins` module:
43
44 .. sourcecode:: pycon
45
46 >>> from pygments.lexers._lua_builtins import MODULES
47 >>> MODULES.keys()
48 ['string', 'coroutine', 'modules', 'io', 'basic', ...]
49 """
50
51 name = 'Lua'
52 url = 'https://www.lua.org/'
53 aliases = ['lua']
54 filenames = ['*.lua', '*.wlua']
55 mimetypes = ['text/x-lua', 'application/x-lua']
56 version_added = ''
57
58 _comment_multiline = r'(?:--\[(?P<level>=*)\[[\w\W]*?\](?P=level)\])'
59 _comment_single = r'(?:--.*$)'
60 _space = r'(?:\s+(?!\s))'
61 _s = rf'(?:{_comment_multiline}|{_comment_single}|{_space})'
62 # A lookahead-safe version of _s that avoids catastrophic backtracking.
63 # The _comment_multiline pattern contains [\w\W]*? which, when used
64 # inside a lookahead with a * quantifier, causes exponential blowup.
65 # This version skips only whitespace; comments between an identifier
66 # and a following [.:] or ( are rare enough to sacrifice.
67 _s_la = r'\s'
68 _name = r'(?:[^\W\d]\w*)'
69
70 tokens = {
71 'root': [
72 # Lua allows a file to start with a shebang.
73 (r'#!.*', Comment.Preproc),
74 default('base'),
75 ],
76 'ws': [
77 (_comment_multiline, Comment.Multiline),
78 (_comment_single, Comment.Single),
79 (_space, Whitespace),
80 ],
81 'base': [
82 include('ws'),
83
84 (r'(?i)0x[\da-f]*(\.[\da-f]*)?(p[+-]?\d+)?', Number.Hex),
85 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
86 (r'(?i)\d+e[+-]?\d+', Number.Float),
87 (r'\d+', Number.Integer),
88
89 # multiline strings
90 (r'(?s)\[(=*)\[.*?\]\1\]', String),
91
92 (r'::', Punctuation, 'label'),
93 (r'\.{3}', Punctuation),
94 (r'[+\-*%^&|#]|//?|>>|<<|\.\.|[=~<>]=?', Operator),
95 (r'[\[\]{}().,:;]+', Punctuation),
96 (r'(and|or|not)\b', Operator.Word),
97
98 (words([
99 'break', 'do', 'else', 'elseif', 'end', 'for', 'if', 'in',
100 'repeat', 'return', 'then', 'until', 'while'
101 ], suffix=r'\b'), Keyword.Reserved),
102 (r'goto\b', Keyword.Reserved, 'goto'),
103 (r'local\b', Keyword.Declaration),
104 (r'(true|false|nil)\b', Keyword.Constant),
105
106 (r'function\b', Keyword.Reserved, 'funcname'),
107
108 (words(all_lua_builtins(), suffix=r'\b'), Name.Builtin),
109 (fr'[A-Za-z_]\w*(?={_s_la}*\()', Name.Function),
110 (fr'[A-Za-z_]\w*(?={_s_la}*[.:])', Name.Variable, 'varname'),
111 (fr'[A-Za-z_]\w*(?={_s_la}*<.+?>)', Name.Variable, 'varname'),
112 (r'[A-Za-z_]\w*', Name.Variable),
113
114 ("'", String.Single, combined('stringescape', 'sqs')),
115 ('"', String.Double, combined('stringescape', 'dqs'))
116 ],
117
118 'varname': [
119 include('ws'),
120 (r'\.\.', Operator, '#pop'),
121 (r'[.:]', Punctuation),
122 (r'<', Punctuation, 'attribute'),
123 (rf'{_name}(?={_s_la}*[.:])', Name.Property),
124 (rf'{_name}(?={_s_la}*\()', Name.Function, '#pop'),
125 (_name, Name.Property, '#pop'),
126 ],
127
128 'funcname': [
129 include('ws'),
130 (r'[.:]', Punctuation),
131 (rf'{_name}(?={_s_la}*[.:])', Name.Class),
132 (_name, Name.Function, '#pop'),
133 # inline function
134 (r'\(', Punctuation, '#pop'),
135 ],
136
137 'goto': [
138 include('ws'),
139 (_name, Name.Label, '#pop'),
140 ],
141
142 'label': [
143 include('ws'),
144 (r'::', Punctuation, '#pop'),
145 (_name, Name.Label),
146 ],
147
148 'attribute': [
149 include('ws'),
150 (r'>', Punctuation, '#pop:2'),
151 (_name, Name.Attribute),
152 ],
153
154 'stringescape': [
155 (r'\\([abfnrtv\\"\']|[\r\n]{1,2}|z\s*|x[0-9a-fA-F]{2}|\d{1,3}|'
156 r'u\{[0-9a-fA-F]+\})', String.Escape),
157 ],
158
159 'sqs': [
160 (r"'", String.Single, '#pop'),
161 (r"[^\\']+", String.Single),
162 ],
163
164 'dqs': [
165 (r'"', String.Double, '#pop'),
166 (r'[^\\"]+', String.Double),
167 ]
168 }
169
170 def __init__(self, **options):
171 self.func_name_highlighting = get_bool_opt(
172 options, 'func_name_highlighting', True)
173 self.disabled_modules = get_list_opt(options, 'disabled_modules', [])
174
175 self._functions = set()
176 if self.func_name_highlighting:
177 from pygments.lexers._lua_builtins import MODULES
178 for mod, func in MODULES.items():
179 if mod not in self.disabled_modules:
180 self._functions.update(func)
181 RegexLexer.__init__(self, **options)
182
183 def get_tokens_unprocessed(self, text):
184 for index, token, value in \
185 RegexLexer.get_tokens_unprocessed(self, text):
186 if token is Name.Builtin and value not in self._functions:
187 if '.' in value:
188 a, b = value.split('.')
189 yield index, Name, a
190 yield index + len(a), Punctuation, '.'
191 yield index + len(a) + 1, Name, b
192 else:
193 yield index, Name, value
194 continue
195 yield index, token, value
196
197def _luau_make_expression(should_pop, _s, _s_la):
198 temp_list = [
199 (r'0[xX][\da-fA-F_]*', Number.Hex, '#pop'),
200 (r'0[bB][\d_]*', Number.Bin, '#pop'),
201 (r'\.?\d[\d_]*(?:\.[\d_]*)?(?:[eE][+-]?[\d_]+)?', Number.Float, '#pop'),
202
203 (words((
204 'true', 'false', 'nil'
205 ), suffix=r'\b'), Keyword.Constant, '#pop'),
206
207 (r'\[(=*)\[[.\n]*?\]\1\]', String, '#pop'),
208
209 (r'(\.)([a-zA-Z_]\w*)(?=%s*[({"\'])', bygroups(Punctuation, Name.Function), '#pop'),
210 (r'(\.)([a-zA-Z_]\w*)', bygroups(Punctuation, Name.Variable), '#pop'),
211
212 (rf'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?={_s_la}*[({{"\'])', Name.Other, '#pop'),
213 (r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*', Name, '#pop'),
214 ]
215 if should_pop:
216 return temp_list
217 return [entry[:2] for entry in temp_list]
218
219def _luau_make_expression_special(should_pop):
220 temp_list = [
221 (r'\{', Punctuation, ('#pop', 'closing_brace_base', 'expression')),
222 (r'\(', Punctuation, ('#pop', 'closing_parenthesis_base', 'expression')),
223
224 (r'::?', Punctuation, ('#pop', 'type_end', 'type_start')),
225
226 (r"'", String.Single, ('#pop', 'string_single')),
227 (r'"', String.Double, ('#pop', 'string_double')),
228 (r'`', String.Backtick, ('#pop', 'string_interpolated')),
229 ]
230 if should_pop:
231 return temp_list
232 return [(entry[0], entry[1], entry[2][1:]) for entry in temp_list]
233
234class LuauLexer(RegexLexer):
235 """
236 For Luau source code.
237
238 Additional options accepted:
239
240 `include_luau_builtins`
241 If given and ``True``, automatically highlight Luau builtins
242 (default: ``True``).
243 `include_roblox_builtins`
244 If given and ``True``, automatically highlight Roblox-specific builtins
245 (default: ``False``).
246 `additional_builtins`
247 If given, must be a list of additional builtins to highlight.
248 `disabled_builtins`
249 If given, must be a list of builtins that will not be highlighted.
250 """
251
252 name = 'Luau'
253 url = 'https://luau-lang.org/'
254 aliases = ['luau']
255 filenames = ['*.luau']
256 version_added = '2.18'
257
258 _comment_multiline = r'(?:--\[(?P<level>=*)\[[\w\W]*?\](?P=level)\])'
259 _comment_single = r'(?:--.*$)'
260 _s = r'(?:{}|{}|{})'.format(_comment_multiline, _comment_single, r'\s+')
261 # Lookahead-safe version — avoids catastrophic backtracking from
262 # [\w\W]*? inside _comment_multiline when combined with * quantifier.
263 _s_la = r'\s'
264
265 tokens = {
266 'root': [
267 (r'#!.*', Comment.Hashbang, 'base'),
268 default('base'),
269 ],
270
271 'ws': [
272 (_comment_multiline, Comment.Multiline),
273 (_comment_single, Comment.Single),
274 (r'\s+', Whitespace),
275 ],
276
277 'base': [
278 include('ws'),
279
280 *_luau_make_expression_special(False),
281 (r'\.\.\.', Punctuation),
282
283 (rf'type\b(?={_s}+[a-zA-Z_])', Keyword.Reserved, 'type_declaration'),
284 (rf'export\b(?={_s}+[a-zA-Z_])', Keyword.Reserved),
285
286 (r'(?:\.\.|//|[+\-*\/%^<>=])=?', Operator, 'expression'),
287 (r'~=', Operator, 'expression'),
288
289 (words((
290 'and', 'or', 'not'
291 ), suffix=r'\b'), Operator.Word, 'expression'),
292
293 (words((
294 'elseif', 'for', 'if', 'in', 'repeat', 'return', 'until',
295 'while'), suffix=r'\b'), Keyword.Reserved, 'expression'),
296 (r'local\b', Keyword.Declaration, 'expression'),
297
298 (r'function\b', Keyword.Reserved, ('expression', 'func_name')),
299
300 (r'[\])};]+', Punctuation),
301
302 include('expression_static'),
303 *_luau_make_expression(False, _s, _s_la),
304
305 (r'[\[.,]', Punctuation, 'expression'),
306 ],
307 'expression_static': [
308 (words((
309 'break', 'continue', 'do', 'else', 'elseif', 'end', 'for',
310 'if', 'in', 'repeat', 'return', 'then', 'until', 'while'),
311 suffix=r'\b'), Keyword.Reserved),
312 ],
313 'expression': [
314 include('ws'),
315
316 (r'if\b', Keyword.Reserved, ('ternary', 'expression')),
317
318 (r'local\b', Keyword.Declaration),
319 *_luau_make_expression_special(True),
320 (r'\.\.\.', Punctuation, '#pop'),
321
322 (r'function\b', Keyword.Reserved, 'func_name'),
323
324 include('expression_static'),
325 *_luau_make_expression(True, _s, _s_la),
326
327 default('#pop'),
328 ],
329 'ternary': [
330 include('ws'),
331
332 (r'else\b', Keyword.Reserved, '#pop'),
333 (words((
334 'then', 'elseif',
335 ), suffix=r'\b'), Operator.Reserved, 'expression'),
336
337 default('#pop'),
338 ],
339
340 'closing_brace_pop': [
341 (r'\}', Punctuation, '#pop'),
342 ],
343 'closing_parenthesis_pop': [
344 (r'\)', Punctuation, '#pop'),
345 ],
346 'closing_gt_pop': [
347 (r'>', Punctuation, '#pop'),
348 ],
349
350 'closing_parenthesis_base': [
351 include('closing_parenthesis_pop'),
352 include('base'),
353 ],
354 'closing_parenthesis_type': [
355 include('closing_parenthesis_pop'),
356 include('type'),
357 ],
358 'closing_brace_base': [
359 include('closing_brace_pop'),
360 include('base'),
361 ],
362 'closing_brace_type': [
363 include('closing_brace_pop'),
364 include('type'),
365 ],
366 'closing_gt_type': [
367 include('closing_gt_pop'),
368 include('type'),
369 ],
370
371 'string_escape': [
372 (r'\\z\s*', String.Escape),
373 (r'\\(?:[abfnrtvz\\"\'`\{\n])|[\r\n]{1,2}|x[\da-fA-F]{2}|\d{1,3}|'
374 r'u\{\}[\da-fA-F]*\}', String.Escape),
375 ],
376 'string_single': [
377 include('string_escape'),
378
379 (r"'", String.Single, "#pop"),
380 (r"[^\\']+", String.Single),
381 ],
382 'string_double': [
383 include('string_escape'),
384
385 (r'"', String.Double, "#pop"),
386 (r'[^\\"]+', String.Double),
387 ],
388 'string_interpolated': [
389 include('string_escape'),
390
391 (r'\{', Punctuation, ('closing_brace_base', 'expression')),
392
393 (r'`', String.Backtick, "#pop"),
394 (r'[^\\`\{]+', String.Backtick),
395 ],
396
397 'func_name': [
398 include('ws'),
399
400 (r'[.:]', Punctuation),
401 (rf'[a-zA-Z_]\w*(?={_s_la}*[.:])', Name.Class),
402 (r'[a-zA-Z_]\w*', Name.Function),
403
404 (r'<', Punctuation, 'closing_gt_type'),
405
406 (r'\(', Punctuation, '#pop'),
407 ],
408
409 'type': [
410 include('ws'),
411
412 (r'\(', Punctuation, 'closing_parenthesis_type'),
413 (r'\{', Punctuation, 'closing_brace_type'),
414 (r'<', Punctuation, 'closing_gt_type'),
415
416 (r"'", String.Single, 'string_single'),
417 (r'"', String.Double, 'string_double'),
418
419 (r'[|&\.,\[\]:=]+', Punctuation),
420 (r'->', Punctuation),
421
422 (r'typeof\(', Name.Builtin, ('closing_parenthesis_base',
423 'expression')),
424 (r'[a-zA-Z_]\w*', Name.Class),
425 ],
426 'type_start': [
427 include('ws'),
428
429 (r'\(', Punctuation, ('#pop', 'closing_parenthesis_type')),
430 (r'\{', Punctuation, ('#pop', 'closing_brace_type')),
431 (r'<', Punctuation, ('#pop', 'closing_gt_type')),
432
433 (r"'", String.Single, ('#pop', 'string_single')),
434 (r'"', String.Double, ('#pop', 'string_double')),
435
436 (r'typeof\(', Name.Builtin, ('#pop', 'closing_parenthesis_base',
437 'expression')),
438 (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
439 ],
440 'type_end': [
441 include('ws'),
442
443 (r'[|&\.]', Punctuation, 'type_start'),
444 (r'->', Punctuation, 'type_start'),
445
446 (r'<', Punctuation, 'closing_gt_type'),
447
448 default('#pop'),
449 ],
450 'type_declaration': [
451 include('ws'),
452
453 (r'[a-zA-Z_]\w*', Name.Class),
454 (r'<', Punctuation, 'closing_gt_type'),
455
456 (r'=', Punctuation, ('#pop', 'type_end', 'type_start')),
457 ],
458 }
459
460 def __init__(self, **options):
461 self.include_luau_builtins = get_bool_opt(
462 options, 'include_luau_builtins', True)
463 self.include_roblox_builtins = get_bool_opt(
464 options, 'include_roblox_builtins', False)
465 self.additional_builtins = get_list_opt(options, 'additional_builtins', [])
466 self.disabled_builtins = get_list_opt(options, 'disabled_builtins', [])
467
468 self._builtins = set(self.additional_builtins)
469 if self.include_luau_builtins:
470 from pygments.lexers._luau_builtins import LUAU_BUILTINS
471 self._builtins.update(LUAU_BUILTINS)
472 if self.include_roblox_builtins:
473 from pygments.lexers._luau_builtins import ROBLOX_BUILTINS
474 self._builtins.update(ROBLOX_BUILTINS)
475 if self.additional_builtins:
476 self._builtins.update(self.additional_builtins)
477 self._builtins.difference_update(self.disabled_builtins)
478
479 RegexLexer.__init__(self, **options)
480
481 def get_tokens_unprocessed(self, text):
482 for index, token, value in \
483 RegexLexer.get_tokens_unprocessed(self, text):
484 if token is Name or token is Name.Other:
485 split_value = value.split('.')
486 complete_value = []
487 new_index = index
488 for position in range(len(split_value), 0, -1):
489 potential_string = '.'.join(split_value[:position])
490 if potential_string in self._builtins:
491 yield index, Name.Builtin, potential_string
492 new_index += len(potential_string)
493
494 if complete_value:
495 yield new_index, Punctuation, '.'
496 new_index += 1
497 break
498 complete_value.insert(0, split_value[position - 1])
499
500 for position, substring in enumerate(complete_value):
501 if position + 1 == len(complete_value):
502 if token is Name:
503 yield new_index, Name.Variable, substring
504 continue
505 yield new_index, Name.Function, substring
506 continue
507 yield new_index, Name.Variable, substring
508 new_index += len(substring)
509 yield new_index, Punctuation, '.'
510 new_index += 1
511
512 continue
513 yield index, token, value
514
515class MoonScriptLexer(LuaLexer):
516 """
517 For MoonScript source code.
518 """
519
520 name = 'MoonScript'
521 url = 'http://moonscript.org'
522 aliases = ['moonscript', 'moon']
523 filenames = ['*.moon']
524 mimetypes = ['text/x-moonscript', 'application/x-moonscript']
525 version_added = '1.5'
526
527 tokens = {
528 'root': [
529 (r'#!(.*?)$', Comment.Preproc),
530 default('base'),
531 ],
532 'base': [
533 ('--.*$', Comment.Single),
534 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
535 (r'(?i)\d+e[+-]?\d+', Number.Float),
536 (r'(?i)0x[0-9a-f]*', Number.Hex),
537 (r'\d+', Number.Integer),
538 (r'\n', Whitespace),
539 (r'[^\S\n]+', Text),
540 (r'(?s)\[(=*)\[.*?\]\1\]', String),
541 (r'(->|=>)', Name.Function),
542 (r':[a-zA-Z_]\w*', Name.Variable),
543 (r'(==|!=|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#!.\\:])', Operator),
544 (r'[;,]', Punctuation),
545 (r'[\[\]{}()]', Keyword.Type),
546 (r'[a-zA-Z_]\w*:', Name.Variable),
547 (words((
548 'class', 'extends', 'if', 'then', 'super', 'do', 'with',
549 'import', 'export', 'while', 'elseif', 'return', 'for', 'in',
550 'from', 'when', 'using', 'else', 'and', 'or', 'not', 'switch',
551 'break'), suffix=r'\b'),
552 Keyword),
553 (r'(true|false|nil)\b', Keyword.Constant),
554 (r'(and|or|not)\b', Operator.Word),
555 (r'(self)\b', Name.Builtin.Pseudo),
556 (r'@@?([a-zA-Z_]\w*)?', Name.Variable.Class),
557 (r'[A-Z]\w*', Name.Class), # proper name
558 (words(all_lua_builtins(), suffix=r"\b"), Name.Builtin),
559 (r'[A-Za-z_]\w*', Name),
560 ("'", String.Single, combined('stringescape', 'sqs')),
561 ('"', String.Double, combined('stringescape', 'dqs'))
562 ],
563 'stringescape': [
564 (r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape)
565 ],
566 'strings': [
567 (r'[^#\\\'"]+', String),
568 # note that strings are multi-line.
569 # hashmarks, quotes and backslashes must be parsed one at a time
570 ],
571 'interpoling_string': [
572 (r'\}', String.Interpol, "#pop"),
573 include('base')
574 ],
575 'dqs': [
576 (r'"', String.Double, '#pop'),
577 (r'\\.|\'', String), # double-quoted string don't need ' escapes
578 (r'#\{', String.Interpol, "interpoling_string"),
579 (r'#', String),
580 include('strings')
581 ],
582 'sqs': [
583 (r"'", String.Single, '#pop'),
584 (r'#|\\.|"', String), # single quoted strings don't need " escapses
585 include('strings')
586 ]
587 }
588
589 def get_tokens_unprocessed(self, text):
590 # set . as Operator instead of Punctuation
591 for index, token, value in LuaLexer.get_tokens_unprocessed(self, text):
592 if token == Punctuation and value == ".":
593 token = Operator
594 yield index, token, value
595
596
597class ChaiscriptLexer(RegexLexer):
598 """
599 For ChaiScript source code.
600 """
601
602 name = 'ChaiScript'
603 url = 'http://chaiscript.com/'
604 aliases = ['chaiscript', 'chai']
605 filenames = ['*.chai']
606 mimetypes = ['text/x-chaiscript', 'application/x-chaiscript']
607 version_added = '2.0'
608
609 flags = re.DOTALL | re.MULTILINE
610
611 tokens = {
612 'commentsandwhitespace': [
613 (r'\s+', Text),
614 (r'//.*?\n', Comment.Single),
615 (r'/\*.*?\*/', Comment.Multiline),
616 (r'^\#.*?\n', Comment.Single)
617 ],
618 'slashstartsregex': [
619 include('commentsandwhitespace'),
620 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
621 r'([gim]+\b|\B)', String.Regex, '#pop'),
622 (r'(?=/)', Text, ('#pop', 'badregex')),
623 default('#pop')
624 ],
625 'badregex': [
626 (r'\n', Text, '#pop')
627 ],
628 'root': [
629 include('commentsandwhitespace'),
630 (r'\n', Text),
631 (r'[^\S\n]+', Text),
632 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|\.\.'
633 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
634 (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
635 (r'[})\].]', Punctuation),
636 (r'[=+\-*/]', Operator),
637 (r'(for|in|while|do|break|return|continue|if|else|'
638 r'throw|try|catch'
639 r')\b', Keyword, 'slashstartsregex'),
640 (r'(var)\b', Keyword.Declaration, 'slashstartsregex'),
641 (r'(attr|def|fun)\b', Keyword.Reserved),
642 (r'(true|false)\b', Keyword.Constant),
643 (r'(eval|throw)\b', Name.Builtin),
644 (r'`\S+`', Name.Builtin),
645 (r'[$a-zA-Z_]\w*', Name.Other),
646 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
647 (r'0x[0-9a-fA-F]+', Number.Hex),
648 (r'[0-9]+', Number.Integer),
649 (r'"', String.Double, 'dqstring'),
650 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
651 ],
652 'dqstring': [
653 (r'\$\{[^"}]+?\}', String.Interpol),
654 (r'\$', String.Double),
655 (r'\\\\', String.Double),
656 (r'\\"', String.Double),
657 (r'[^\\"$]+', String.Double),
658 (r'"', String.Double, '#pop'),
659 ],
660 }
661
662
663class LSLLexer(RegexLexer):
664 """
665 For Second Life's Linden Scripting Language source code.
666 """
667
668 name = 'LSL'
669 aliases = ['lsl']
670 filenames = ['*.lsl']
671 mimetypes = ['text/x-lsl']
672 url = 'https://wiki.secondlife.com/wiki/Linden_Scripting_Language'
673 version_added = '2.0'
674
675 flags = re.MULTILINE
676
677 lsl_keywords = r'\b(?:do|else|for|if|jump|return|while)\b'
678 lsl_types = r'\b(?:float|integer|key|list|quaternion|rotation|string|vector)\b'
679 lsl_states = r'\b(?:(?:state)\s+\w+|default)\b'
680 lsl_events = r'\b(?:state_(?:entry|exit)|touch(?:_(?:start|end))?|(?:land_)?collision(?:_(?:start|end))?|timer|listen|(?:no_)?sensor|control|(?:not_)?at_(?:rot_)?target|money|email|run_time_permissions|changed|attach|dataserver|moving_(?:start|end)|link_message|(?:on|object)_rez|remote_data|http_re(?:sponse|quest)|path_update|transaction_result)\b'
681 lsl_functions_builtin = r'\b(?:ll(?:ReturnObjectsBy(?:ID|Owner)|Json(?:2List|[GS]etValue|ValueType)|Sin|Cos|Tan|Atan2|Sqrt|Pow|Abs|Fabs|Frand|Floor|Ceil|Round|Vec(?:Mag|Norm|Dist)|Rot(?:Between|2(?:Euler|Fwd|Left|Up))|(?:Euler|Axes)2Rot|Whisper|(?:Region|Owner)?Say|Shout|Listen(?:Control|Remove)?|Sensor(?:Repeat|Remove)?|Detected(?:Name|Key|Owner|Type|Pos|Vel|Grab|Rot|Group|LinkNumber)|Die|Ground|Wind|(?:[GS]et)(?:AnimationOverride|MemoryLimit|PrimMediaParams|ParcelMusicURL|Object(?:Desc|Name)|PhysicsMaterial|Status|Scale|Color|Alpha|Texture|Pos|Rot|Force|Torque)|ResetAnimationOverride|(?:Scale|Offset|Rotate)Texture|(?:Rot)?Target(?:Remove)?|(?:Stop)?MoveToTarget|Apply(?:Rotational)?Impulse|Set(?:KeyframedMotion|ContentType|RegionPos|(?:Angular)?Velocity|Buoyancy|HoverHeight|ForceAndTorque|TimerEvent|ScriptState|Damage|TextureAnim|Sound(?:Queueing|Radius)|Vehicle(?:Type|(?:Float|Vector|Rotation)Param)|(?:Touch|Sit)?Text|Camera(?:Eye|At)Offset|PrimitiveParams|ClickAction|Link(?:Alpha|Color|PrimitiveParams(?:Fast)?|Texture(?:Anim)?|Camera|Media)|RemoteScriptAccessPin|PayPrice|LocalRot)|ScaleByFactor|Get(?:(?:Max|Min)ScaleFactor|ClosestNavPoint|StaticPath|SimStats|Env|PrimitiveParams|Link(?:PrimitiveParams|Number(?:OfSides)?|Key|Name|Media)|HTTPHeader|FreeURLs|Object(?:Details|PermMask|PrimCount)|Parcel(?:MaxPrims|Details|Prim(?:Count|Owners))|Attached|(?:SPMax|Free|Used)Memory|Region(?:Name|TimeDilation|FPS|Corner|AgentCount)|Root(?:Position|Rotation)|UnixTime|(?:Parcel|Region)Flags|(?:Wall|GMT)clock|SimulatorHostname|BoundingBox|GeometricCenter|Creator|NumberOf(?:Prims|NotecardLines|Sides)|Animation(?:List)?|(?:Camera|Local)(?:Pos|Rot)|Vel|Accel|Omega|Time(?:stamp|OfDay)|(?:Object|CenterOf)?Mass|MassMKS|Energy|Owner|(?:Owner)?Key|SunDirection|Texture(?:Offset|Scale|Rot)|Inventory(?:Number|Name|Key|Type|Creator|PermMask)|Permissions(?:Key)?|StartParameter|List(?:Length|EntryType)|Date|Agent(?:Size|Info|Language|List)|LandOwnerAt|NotecardLine|Script(?:Name|State))|(?:Get|Reset|GetAndReset)Time|PlaySound(?:Slave)?|LoopSound(?:Master|Slave)?|(?:Trigger|Stop|Preload)Sound|(?:(?:Get|Delete)Sub|Insert)String|To(?:Upper|Lower)|Give(?:InventoryList|Money)|RezObject|(?:Stop)?LookAt|Sleep|CollisionFilter|(?:Take|Release)Controls|DetachFromAvatar|AttachToAvatar(?:Temp)?|InstantMessage|(?:GetNext)?Email|StopHover|MinEventDelay|RotLookAt|String(?:Length|Trim)|(?:Start|Stop)Animation|TargetOmega|RequestPermissions|(?:Create|Break)Link|BreakAllLinks|(?:Give|Remove)Inventory|Water|PassTouches|Request(?:Agent|Inventory)Data|TeleportAgent(?:Home|GlobalCoords)?|ModifyLand|CollisionSound|ResetScript|MessageLinked|PushObject|PassCollisions|AxisAngle2Rot|Rot2(?:Axis|Angle)|A(?:cos|sin)|AngleBetween|AllowInventoryDrop|SubStringIndex|List2(?:CSV|Integer|Json|Float|String|Key|Vector|Rot|List(?:Strided)?)|DeleteSubList|List(?:Statistics|Sort|Randomize|(?:Insert|Find|Replace)List)|EdgeOfWorld|AdjustSoundVolume|Key2Name|TriggerSoundLimited|EjectFromLand|(?:CSV|ParseString)2List|OverMyLand|SameGroup|UnSit|Ground(?:Slope|Normal|Contour)|GroundRepel|(?:Set|Remove)VehicleFlags|(?:AvatarOn)?(?:Link)?SitTarget|Script(?:Danger|Profiler)|Dialog|VolumeDetect|ResetOtherScript|RemoteLoadScriptPin|(?:Open|Close)RemoteDataChannel|SendRemoteData|RemoteDataReply|(?:Integer|String)ToBase64|XorBase64|Log(?:10)?|Base64To(?:String|Integer)|ParseStringKeepNulls|RezAtRoot|RequestSimulatorData|ForceMouselook|(?:Load|Release|(?:E|Une)scape)URL|ParcelMedia(?:CommandList|Query)|ModPow|MapDestination|(?:RemoveFrom|AddTo|Reset)Land(?:Pass|Ban)List|(?:Set|Clear)CameraParams|HTTP(?:Request|Response)|TextBox|DetectedTouch(?:UV|Face|Pos|(?:N|Bin)ormal|ST)|(?:MD5|SHA1|DumpList2)String|Request(?:Secure)?URL|Clear(?:Prim|Link)Media|(?:Link)?ParticleSystem|(?:Get|Request)(?:Username|DisplayName)|RegionSayTo|CastRay|GenerateKey|TransferLindenDollars|ManageEstateAccess|(?:Create|Delete)Character|ExecCharacterCmd|Evade|FleeFrom|NavigateTo|PatrolPoints|Pursue|UpdateCharacter|WanderWithin))\b'
682 lsl_constants_float = r'\b(?:DEG_TO_RAD|PI(?:_BY_TWO)?|RAD_TO_DEG|SQRT2|TWO_PI)\b'
683 lsl_constants_integer = r'\b(?:JSON_APPEND|STATUS_(?:PHYSICS|ROTATE_[XYZ]|PHANTOM|SANDBOX|BLOCK_GRAB(?:_OBJECT)?|(?:DIE|RETURN)_AT_EDGE|CAST_SHADOWS|OK|MALFORMED_PARAMS|TYPE_MISMATCH|BOUNDS_ERROR|NOT_(?:FOUND|SUPPORTED)|INTERNAL_ERROR|WHITELIST_FAILED)|AGENT(?:_(?:BY_(?:LEGACY_|USER)NAME|FLYING|ATTACHMENTS|SCRIPTED|MOUSELOOK|SITTING|ON_OBJECT|AWAY|WALKING|IN_AIR|TYPING|CROUCHING|BUSY|ALWAYS_RUN|AUTOPILOT|LIST_(?:PARCEL(?:_OWNER)?|REGION)))?|CAMERA_(?:PITCH|DISTANCE|BEHINDNESS_(?:ANGLE|LAG)|(?:FOCUS|POSITION)(?:_(?:THRESHOLD|LOCKED|LAG))?|FOCUS_OFFSET|ACTIVE)|ANIM_ON|LOOP|REVERSE|PING_PONG|SMOOTH|ROTATE|SCALE|ALL_SIDES|LINK_(?:ROOT|SET|ALL_(?:OTHERS|CHILDREN)|THIS)|ACTIVE|PASSIVE|SCRIPTED|CONTROL_(?:FWD|BACK|(?:ROT_)?(?:LEFT|RIGHT)|UP|DOWN|(?:ML_)?LBUTTON)|PERMISSION_(?:RETURN_OBJECTS|DEBIT|OVERRIDE_ANIMATIONS|SILENT_ESTATE_MANAGEMENT|TAKE_CONTROLS|TRIGGER_ANIMATION|ATTACH|CHANGE_LINKS|(?:CONTROL|TRACK)_CAMERA|TELEPORT)|INVENTORY_(?:TEXTURE|SOUND|OBJECT|SCRIPT|LANDMARK|CLOTHING|NOTECARD|BODYPART|ANIMATION|GESTURE|ALL|NONE)|CHANGED_(?:INVENTORY|COLOR|SHAPE|SCALE|TEXTURE|LINK|ALLOWED_DROP|OWNER|REGION(?:_START)?|TELEPORT|MEDIA)|OBJECT_(?:(?:PHYSICS|SERVER|STREAMING)_COST|UNKNOWN_DETAIL|CHARACTER_TIME|PHANTOM|PHYSICS|TEMP_ON_REZ|NAME|DESC|POS|PRIM_EQUIVALENCE|RETURN_(?:PARCEL(?:_OWNER)?|REGION)|ROO?T|VELOCITY|OWNER|GROUP|CREATOR|ATTACHED_POINT|RENDER_WEIGHT|PATHFINDING_TYPE|(?:RUNNING|TOTAL)_SCRIPT_COUNT|SCRIPT_(?:MEMORY|TIME))|TYPE_(?:INTEGER|FLOAT|STRING|KEY|VECTOR|ROTATION|INVALID)|(?:DEBUG|PUBLIC)_CHANNEL|ATTACH_(?:AVATAR_CENTER|CHEST|HEAD|BACK|PELVIS|MOUTH|CHIN|NECK|NOSE|BELLY|[LR](?:SHOULDER|HAND|FOOT|EAR|EYE|[UL](?:ARM|LEG)|HIP)|(?:LEFT|RIGHT)_PEC|HUD_(?:CENTER_[12]|TOP_(?:RIGHT|CENTER|LEFT)|BOTTOM(?:_(?:RIGHT|LEFT))?))|LAND_(?:LEVEL|RAISE|LOWER|SMOOTH|NOISE|REVERT)|DATA_(?:ONLINE|NAME|BORN|SIM_(?:POS|STATUS|RATING)|PAYINFO)|PAYMENT_INFO_(?:ON_FILE|USED)|REMOTE_DATA_(?:CHANNEL|REQUEST|REPLY)|PSYS_(?:PART_(?:BF_(?:ZERO|ONE(?:_MINUS_(?:DEST_COLOR|SOURCE_(ALPHA|COLOR)))?|DEST_COLOR|SOURCE_(ALPHA|COLOR))|BLEND_FUNC_(DEST|SOURCE)|FLAGS|(?:START|END)_(?:COLOR|ALPHA|SCALE|GLOW)|MAX_AGE|(?:RIBBON|WIND|INTERP_(?:COLOR|SCALE)|BOUNCE|FOLLOW_(?:SRC|VELOCITY)|TARGET_(?:POS|LINEAR)|EMISSIVE)_MASK)|SRC_(?:MAX_AGE|PATTERN|ANGLE_(?:BEGIN|END)|BURST_(?:RATE|PART_COUNT|RADIUS|SPEED_(?:MIN|MAX))|ACCEL|TEXTURE|TARGET_KEY|OMEGA|PATTERN_(?:DROP|EXPLODE|ANGLE(?:_CONE(?:_EMPTY)?)?)))|VEHICLE_(?:REFERENCE_FRAME|TYPE_(?:NONE|SLED|CAR|BOAT|AIRPLANE|BALLOON)|(?:LINEAR|ANGULAR)_(?:FRICTION_TIMESCALE|MOTOR_DIRECTION)|LINEAR_MOTOR_OFFSET|HOVER_(?:HEIGHT|EFFICIENCY|TIMESCALE)|BUOYANCY|(?:LINEAR|ANGULAR)_(?:DEFLECTION_(?:EFFICIENCY|TIMESCALE)|MOTOR_(?:DECAY_)?TIMESCALE)|VERTICAL_ATTRACTION_(?:EFFICIENCY|TIMESCALE)|BANKING_(?:EFFICIENCY|MIX|TIMESCALE)|FLAG_(?:NO_DEFLECTION_UP|LIMIT_(?:ROLL_ONLY|MOTOR_UP)|HOVER_(?:(?:WATER|TERRAIN|UP)_ONLY|GLOBAL_HEIGHT)|MOUSELOOK_(?:STEER|BANK)|CAMERA_DECOUPLED))|PRIM_(?:TYPE(?:_(?:BOX|CYLINDER|PRISM|SPHERE|TORUS|TUBE|RING|SCULPT))?|HOLE_(?:DEFAULT|CIRCLE|SQUARE|TRIANGLE)|MATERIAL(?:_(?:STONE|METAL|GLASS|WOOD|FLESH|PLASTIC|RUBBER))?|SHINY_(?:NONE|LOW|MEDIUM|HIGH)|BUMP_(?:NONE|BRIGHT|DARK|WOOD|BARK|BRICKS|CHECKER|CONCRETE|TILE|STONE|DISKS|GRAVEL|BLOBS|SIDING|LARGETILE|STUCCO|SUCTION|WEAVE)|TEXGEN_(?:DEFAULT|PLANAR)|SCULPT_(?:TYPE_(?:SPHERE|TORUS|PLANE|CYLINDER|MASK)|FLAG_(?:MIRROR|INVERT))|PHYSICS(?:_(?:SHAPE_(?:CONVEX|NONE|PRIM|TYPE)))?|(?:POS|ROT)_LOCAL|SLICE|TEXT|FLEXIBLE|POINT_LIGHT|TEMP_ON_REZ|PHANTOM|POSITION|SIZE|ROTATION|TEXTURE|NAME|OMEGA|DESC|LINK_TARGET|COLOR|BUMP_SHINY|FULLBRIGHT|TEXGEN|GLOW|MEDIA_(?:ALT_IMAGE_ENABLE|CONTROLS|(?:CURRENT|HOME)_URL|AUTO_(?:LOOP|PLAY|SCALE|ZOOM)|FIRST_CLICK_INTERACT|(?:WIDTH|HEIGHT)_PIXELS|WHITELIST(?:_ENABLE)?|PERMS_(?:INTERACT|CONTROL)|PARAM_MAX|CONTROLS_(?:STANDARD|MINI)|PERM_(?:NONE|OWNER|GROUP|ANYONE)|MAX_(?:URL_LENGTH|WHITELIST_(?:SIZE|COUNT)|(?:WIDTH|HEIGHT)_PIXELS)))|MASK_(?:BASE|OWNER|GROUP|EVERYONE|NEXT)|PERM_(?:TRANSFER|MODIFY|COPY|MOVE|ALL)|PARCEL_(?:MEDIA_COMMAND_(?:STOP|PAUSE|PLAY|LOOP|TEXTURE|URL|TIME|AGENT|UNLOAD|AUTO_ALIGN|TYPE|SIZE|DESC|LOOP_SET)|FLAG_(?:ALLOW_(?:FLY|(?:GROUP_)?SCRIPTS|LANDMARK|TERRAFORM|DAMAGE|CREATE_(?:GROUP_)?OBJECTS)|USE_(?:ACCESS_(?:GROUP|LIST)|BAN_LIST|LAND_PASS_LIST)|LOCAL_SOUND_ONLY|RESTRICT_PUSHOBJECT|ALLOW_(?:GROUP|ALL)_OBJECT_ENTRY)|COUNT_(?:TOTAL|OWNER|GROUP|OTHER|SELECTED|TEMP)|DETAILS_(?:NAME|DESC|OWNER|GROUP|AREA|ID|SEE_AVATARS))|LIST_STAT_(?:MAX|MIN|MEAN|MEDIAN|STD_DEV|SUM(?:_SQUARES)?|NUM_COUNT|GEOMETRIC_MEAN|RANGE)|PAY_(?:HIDE|DEFAULT)|REGION_FLAG_(?:ALLOW_DAMAGE|FIXED_SUN|BLOCK_TERRAFORM|SANDBOX|DISABLE_(?:COLLISIONS|PHYSICS)|BLOCK_FLY|ALLOW_DIRECT_TELEPORT|RESTRICT_PUSHOBJECT)|HTTP_(?:METHOD|MIMETYPE|BODY_(?:MAXLENGTH|TRUNCATED)|CUSTOM_HEADER|PRAGMA_NO_CACHE|VERBOSE_THROTTLE|VERIFY_CERT)|STRING_(?:TRIM(?:_(?:HEAD|TAIL))?)|CLICK_ACTION_(?:NONE|TOUCH|SIT|BUY|PAY|OPEN(?:_MEDIA)?|PLAY|ZOOM)|TOUCH_INVALID_FACE|PROFILE_(?:NONE|SCRIPT_MEMORY)|RC_(?:DATA_FLAGS|DETECT_PHANTOM|GET_(?:LINK_NUM|NORMAL|ROOT_KEY)|MAX_HITS|REJECT_(?:TYPES|AGENTS|(?:NON)?PHYSICAL|LAND))|RCERR_(?:CAST_TIME_EXCEEDED|SIM_PERF_LOW|UNKNOWN)|ESTATE_ACCESS_(?:ALLOWED_(?:AGENT|GROUP)_(?:ADD|REMOVE)|BANNED_AGENT_(?:ADD|REMOVE))|DENSITY|FRICTION|RESTITUTION|GRAVITY_MULTIPLIER|KFM_(?:COMMAND|CMD_(?:PLAY|STOP|PAUSE|SET_MODE)|MODE|FORWARD|LOOP|PING_PONG|REVERSE|DATA|ROTATION|TRANSLATION)|ERR_(?:GENERIC|PARCEL_PERMISSIONS|MALFORMED_PARAMS|RUNTIME_PERMISSIONS|THROTTLED)|CHARACTER_(?:CMD_(?:(?:SMOOTH_)?STOP|JUMP)|DESIRED_(?:TURN_)?SPEED|RADIUS|STAY_WITHIN_PARCEL|LENGTH|ORIENTATION|ACCOUNT_FOR_SKIPPED_FRAMES|AVOIDANCE_MODE|TYPE(?:_(?:[A-D]|NONE))?|MAX_(?:DECEL|TURN_RADIUS|(?:ACCEL|SPEED)))|PURSUIT_(?:OFFSET|FUZZ_FACTOR|GOAL_TOLERANCE|INTERCEPT)|REQUIRE_LINE_OF_SIGHT|FORCE_DIRECT_PATH|VERTICAL|HORIZONTAL|AVOID_(?:CHARACTERS|DYNAMIC_OBSTACLES|NONE)|PU_(?:EVADE_(?:HIDDEN|SPOTTED)|FAILURE_(?:DYNAMIC_PATHFINDING_DISABLED|INVALID_(?:GOAL|START)|NO_(?:NAVMESH|VALID_DESTINATION)|OTHER|TARGET_GONE|(?:PARCEL_)?UNREACHABLE)|(?:GOAL|SLOWDOWN_DISTANCE)_REACHED)|TRAVERSAL_TYPE(?:_(?:FAST|NONE|SLOW))?|CONTENT_TYPE_(?:ATOM|FORM|HTML|JSON|LLSD|RSS|TEXT|XHTML|XML)|GCNP_(?:RADIUS|STATIC)|(?:PATROL|WANDER)_PAUSE_AT_WAYPOINTS|OPT_(?:AVATAR|CHARACTER|EXCLUSION_VOLUME|LEGACY_LINKSET|MATERIAL_VOLUME|OTHER|STATIC_OBSTACLE|WALKABLE)|SIM_STAT_PCT_CHARS_STEPPED)\b'
684 lsl_constants_integer_boolean = r'\b(?:FALSE|TRUE)\b'
685 lsl_constants_rotation = r'\b(?:ZERO_ROTATION)\b'
686 lsl_constants_string = r'\b(?:EOF|JSON_(?:ARRAY|DELETE|FALSE|INVALID|NULL|NUMBER|OBJECT|STRING|TRUE)|NULL_KEY|TEXTURE_(?:BLANK|DEFAULT|MEDIA|PLYWOOD|TRANSPARENT)|URL_REQUEST_(?:GRANTED|DENIED))\b'
687 lsl_constants_vector = r'\b(?:TOUCH_INVALID_(?:TEXCOORD|VECTOR)|ZERO_VECTOR)\b'
688 lsl_invalid_broken = r'\b(?:LAND_(?:LARGE|MEDIUM|SMALL)_BRUSH)\b'
689 lsl_invalid_deprecated = r'\b(?:ATTACH_[LR]PEC|DATA_RATING|OBJECT_ATTACHMENT_(?:GEOMETRY_BYTES|SURFACE_AREA)|PRIM_(?:CAST_SHADOWS|MATERIAL_LIGHT|TYPE_LEGACY)|PSYS_SRC_(?:INNER|OUTER)ANGLE|VEHICLE_FLAG_NO_FLY_UP|ll(?:Cloud|Make(?:Explosion|Fountain|Smoke|Fire)|RemoteDataSetRegion|Sound(?:Preload)?|XorBase64Strings(?:Correct)?))\b'
690 lsl_invalid_illegal = r'\b(?:event)\b'
691 lsl_invalid_unimplemented = r'\b(?:CHARACTER_(?:MAX_ANGULAR_(?:ACCEL|SPEED)|TURN_SPEED_MULTIPLIER)|PERMISSION_(?:CHANGE_(?:JOINTS|PERMISSIONS)|RELEASE_OWNERSHIP|REMAP_CONTROLS)|PRIM_PHYSICS_MATERIAL|PSYS_SRC_OBJ_REL_MASK|ll(?:CollisionSprite|(?:Stop)?PointAt|(?:(?:Refresh|Set)Prim)URL|(?:Take|Release)Camera|RemoteLoadScript))\b'
692 lsl_reserved_godmode = r'\b(?:ll(?:GodLikeRezObject|Set(?:Inventory|Object)PermMask))\b'
693 lsl_reserved_log = r'\b(?:print)\b'
694 lsl_operators = r'\+\+|\-\-|<<|>>|&&?|\|\|?|\^|~|[!%<>=*+\-/]=?'
695
696 tokens = {
697 'root':
698 [
699 (r'//.*?\n', Comment.Single),
700 (r'/\*', Comment.Multiline, 'comment'),
701 (r'"', String.Double, 'string'),
702 (lsl_keywords, Keyword),
703 (lsl_types, Keyword.Type),
704 (lsl_states, Name.Class),
705 (lsl_events, Name.Builtin),
706 (lsl_functions_builtin, Name.Function),
707 (lsl_constants_float, Keyword.Constant),
708 (lsl_constants_integer, Keyword.Constant),
709 (lsl_constants_integer_boolean, Keyword.Constant),
710 (lsl_constants_rotation, Keyword.Constant),
711 (lsl_constants_string, Keyword.Constant),
712 (lsl_constants_vector, Keyword.Constant),
713 (lsl_invalid_broken, Error),
714 (lsl_invalid_deprecated, Error),
715 (lsl_invalid_illegal, Error),
716 (lsl_invalid_unimplemented, Error),
717 (lsl_reserved_godmode, Keyword.Reserved),
718 (lsl_reserved_log, Keyword.Reserved),
719 (r'\b([a-zA-Z_]\w*)\b', Name.Variable),
720 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d*', Number.Float),
721 (r'(\d+\.\d*|\.\d+)', Number.Float),
722 (r'0[xX][0-9a-fA-F]+', Number.Hex),
723 (r'\d+', Number.Integer),
724 (lsl_operators, Operator),
725 (r':=?', Error),
726 (r'[,;{}()\[\]]', Punctuation),
727 (r'\n+', Whitespace),
728 (r'\s+', Whitespace)
729 ],
730 'comment':
731 [
732 (r'[^*/]+', Comment.Multiline),
733 (r'/\*', Comment.Multiline, '#push'),
734 (r'\*/', Comment.Multiline, '#pop'),
735 (r'[*/]', Comment.Multiline)
736 ],
737 'string':
738 [
739 (r'\\([nt"\\])', String.Escape),
740 (r'"', String.Double, '#pop'),
741 (r'\\.', Error),
742 (r'[^"\\]+', String.Double),
743 ]
744 }
745
746
747class AppleScriptLexer(RegexLexer):
748 """
749 For AppleScript source code,
750 including `AppleScript Studio
751 <http://developer.apple.com/documentation/AppleScript/
752 Reference/StudioReference>`_.
753 Contributed by Andreas Amann <aamann@mac.com>.
754 """
755
756 name = 'AppleScript'
757 url = 'https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html'
758 aliases = ['applescript']
759 filenames = ['*.applescript']
760 version_added = '1.0'
761
762 flags = re.MULTILINE | re.DOTALL
763
764 Identifiers = r'[a-zA-Z]\w*'
765
766 # XXX: use words() for all of these
767 Literals = ('AppleScript', 'current application', 'false', 'linefeed',
768 'missing value', 'pi', 'quote', 'result', 'return', 'space',
769 'tab', 'text item delimiters', 'true', 'version')
770 Classes = ('alias ', 'application ', 'boolean ', 'class ', 'constant ',
771 'date ', 'file ', 'integer ', 'list ', 'number ', 'POSIX file ',
772 'real ', 'record ', 'reference ', 'RGB color ', 'script ',
773 'text ', 'unit types', '(?:Unicode )?text', 'string')
774 BuiltIn = ('attachment', 'attribute run', 'character', 'day', 'month',
775 'paragraph', 'word', 'year')
776 HandlerParams = ('about', 'above', 'against', 'apart from', 'around',
777 'aside from', 'at', 'below', 'beneath', 'beside',
778 'between', 'for', 'given', 'instead of', 'on', 'onto',
779 'out of', 'over', 'since')
780 Commands = ('ASCII (character|number)', 'activate', 'beep', 'choose URL',
781 'choose application', 'choose color', 'choose file( name)?',
782 'choose folder', 'choose from list',
783 'choose remote application', 'clipboard info',
784 'close( access)?', 'copy', 'count', 'current date', 'delay',
785 'delete', 'display (alert|dialog)', 'do shell script',
786 'duplicate', 'exists', 'get eof', 'get volume settings',
787 'info for', 'launch', 'list (disks|folder)', 'load script',
788 'log', 'make', 'mount volume', 'new', 'offset',
789 'open( (for access|location))?', 'path to', 'print', 'quit',
790 'random number', 'read', 'round', 'run( script)?',
791 'say', 'scripting components',
792 'set (eof|the clipboard to|volume)', 'store script',
793 'summarize', 'system attribute', 'system info',
794 'the clipboard', 'time to GMT', 'write', 'quoted form')
795 References = ('(in )?back of', '(in )?front of', '[0-9]+(st|nd|rd|th)',
796 'first', 'second', 'third', 'fourth', 'fifth', 'sixth',
797 'seventh', 'eighth', 'ninth', 'tenth', 'after', 'back',
798 'before', 'behind', 'every', 'front', 'index', 'last',
799 'middle', 'some', 'that', 'through', 'thru', 'where', 'whose')
800 Operators = ("and", "or", "is equal", "equals", "(is )?equal to", "is not",
801 "isn't", "isn't equal( to)?", "is not equal( to)?",
802 "doesn't equal", "does not equal", "(is )?greater than",
803 "comes after", "is not less than or equal( to)?",
804 "isn't less than or equal( to)?", "(is )?less than",
805 "comes before", "is not greater than or equal( to)?",
806 "isn't greater than or equal( to)?",
807 "(is )?greater than or equal( to)?", "is not less than",
808 "isn't less than", "does not come before",
809 "doesn't come before", "(is )?less than or equal( to)?",
810 "is not greater than", "isn't greater than",
811 "does not come after", "doesn't come after", "starts? with",
812 "begins? with", "ends? with", "contains?", "does not contain",
813 "doesn't contain", "is in", "is contained by", "is not in",
814 "is not contained by", "isn't contained by", "div", "mod",
815 "not", "(a )?(ref( to)?|reference to)", "is", "does")
816 Control = ('considering', 'else', 'error', 'exit', 'from', 'if',
817 'ignoring', 'in', 'repeat', 'tell', 'then', 'times', 'to',
818 'try', 'until', 'using terms from', 'while', 'whith',
819 'with timeout( of)?', 'with transaction', 'by', 'continue',
820 'end', 'its?', 'me', 'my', 'return', 'of', 'as')
821 Declarations = ('global', 'local', 'prop(erty)?', 'set', 'get')
822 Reserved = ('but', 'put', 'returning', 'the')
823 StudioClasses = ('action cell', 'alert reply', 'application', 'box',
824 'browser( cell)?', 'bundle', 'button( cell)?', 'cell',
825 'clip view', 'color well', 'color-panel',
826 'combo box( item)?', 'control',
827 'data( (cell|column|item|row|source))?', 'default entry',
828 'dialog reply', 'document', 'drag info', 'drawer',
829 'event', 'font(-panel)?', 'formatter',
830 'image( (cell|view))?', 'matrix', 'menu( item)?', 'item',
831 'movie( view)?', 'open-panel', 'outline view', 'panel',
832 'pasteboard', 'plugin', 'popup button',
833 'progress indicator', 'responder', 'save-panel',
834 'scroll view', 'secure text field( cell)?', 'slider',
835 'sound', 'split view', 'stepper', 'tab view( item)?',
836 'table( (column|header cell|header view|view))',
837 'text( (field( cell)?|view))?', 'toolbar( item)?',
838 'user-defaults', 'view', 'window')
839 StudioEvents = ('accept outline drop', 'accept table drop', 'action',
840 'activated', 'alert ended', 'awake from nib', 'became key',
841 'became main', 'begin editing', 'bounds changed',
842 'cell value', 'cell value changed', 'change cell value',
843 'change item value', 'changed', 'child of item',
844 'choose menu item', 'clicked', 'clicked toolbar item',
845 'closed', 'column clicked', 'column moved',
846 'column resized', 'conclude drop', 'data representation',
847 'deminiaturized', 'dialog ended', 'document nib name',
848 'double clicked', 'drag( (entered|exited|updated))?',
849 'drop', 'end editing', 'exposed', 'idle', 'item expandable',
850 'item value', 'item value changed', 'items changed',
851 'keyboard down', 'keyboard up', 'launched',
852 'load data representation', 'miniaturized', 'mouse down',
853 'mouse dragged', 'mouse entered', 'mouse exited',
854 'mouse moved', 'mouse up', 'moved',
855 'number of browser rows', 'number of items',
856 'number of rows', 'open untitled', 'opened', 'panel ended',
857 'parameters updated', 'plugin loaded', 'prepare drop',
858 'prepare outline drag', 'prepare outline drop',
859 'prepare table drag', 'prepare table drop',
860 'read from file', 'resigned active', 'resigned key',
861 'resigned main', 'resized( sub views)?',
862 'right mouse down', 'right mouse dragged',
863 'right mouse up', 'rows changed', 'scroll wheel',
864 'selected tab view item', 'selection changed',
865 'selection changing', 'should begin editing',
866 'should close', 'should collapse item',
867 'should end editing', 'should expand item',
868 'should open( untitled)?',
869 'should quit( after last window closed)?',
870 'should select column', 'should select item',
871 'should select row', 'should select tab view item',
872 'should selection change', 'should zoom', 'shown',
873 'update menu item', 'update parameters',
874 'update toolbar item', 'was hidden', 'was miniaturized',
875 'will become active', 'will close', 'will dismiss',
876 'will display browser cell', 'will display cell',
877 'will display item cell', 'will display outline cell',
878 'will finish launching', 'will hide', 'will miniaturize',
879 'will move', 'will open', 'will pop up', 'will quit',
880 'will resign active', 'will resize( sub views)?',
881 'will select tab view item', 'will show', 'will zoom',
882 'write to file', 'zoomed')
883 StudioCommands = ('animate', 'append', 'call method', 'center',
884 'close drawer', 'close panel', 'display',
885 'display alert', 'display dialog', 'display panel', 'go',
886 'hide', 'highlight', 'increment', 'item for',
887 'load image', 'load movie', 'load nib', 'load panel',
888 'load sound', 'localized string', 'lock focus', 'log',
889 'open drawer', 'path for', 'pause', 'perform action',
890 'play', 'register', 'resume', 'scroll', 'select( all)?',
891 'show', 'size to fit', 'start', 'step back',
892 'step forward', 'stop', 'synchronize', 'unlock focus',
893 'update')
894 StudioProperties = ('accepts arrow key', 'action method', 'active',
895 'alignment', 'allowed identifiers',
896 'allows branch selection', 'allows column reordering',
897 'allows column resizing', 'allows column selection',
898 'allows customization',
899 'allows editing text attributes',
900 'allows empty selection', 'allows mixed state',
901 'allows multiple selection', 'allows reordering',
902 'allows undo', 'alpha( value)?', 'alternate image',
903 'alternate increment value', 'alternate title',
904 'animation delay', 'associated file name',
905 'associated object', 'auto completes', 'auto display',
906 'auto enables items', 'auto repeat',
907 'auto resizes( outline column)?',
908 'auto save expanded items', 'auto save name',
909 'auto save table columns', 'auto saves configuration',
910 'auto scroll', 'auto sizes all columns to fit',
911 'auto sizes cells', 'background color', 'bezel state',
912 'bezel style', 'bezeled', 'border rect', 'border type',
913 'bordered', 'bounds( rotation)?', 'box type',
914 'button returned', 'button type',
915 'can choose directories', 'can choose files',
916 'can draw', 'can hide',
917 'cell( (background color|size|type))?', 'characters',
918 'class', 'click count', 'clicked( data)? column',
919 'clicked data item', 'clicked( data)? row',
920 'closeable', 'collating', 'color( (mode|panel))',
921 'command key down', 'configuration',
922 'content(s| (size|view( margins)?))?', 'context',
923 'continuous', 'control key down', 'control size',
924 'control tint', 'control view',
925 'controller visible', 'coordinate system',
926 'copies( on scroll)?', 'corner view', 'current cell',
927 'current column', 'current( field)? editor',
928 'current( menu)? item', 'current row',
929 'current tab view item', 'data source',
930 'default identifiers', 'delta (x|y|z)',
931 'destination window', 'directory', 'display mode',
932 'displayed cell', 'document( (edited|rect|view))?',
933 'double value', 'dragged column', 'dragged distance',
934 'dragged items', 'draws( cell)? background',
935 'draws grid', 'dynamically scrolls', 'echos bullets',
936 'edge', 'editable', 'edited( data)? column',
937 'edited data item', 'edited( data)? row', 'enabled',
938 'enclosing scroll view', 'ending page',
939 'error handling', 'event number', 'event type',
940 'excluded from windows menu', 'executable path',
941 'expanded', 'fax number', 'field editor', 'file kind',
942 'file name', 'file type', 'first responder',
943 'first visible column', 'flipped', 'floating',
944 'font( panel)?', 'formatter', 'frameworks path',
945 'frontmost', 'gave up', 'grid color', 'has data items',
946 'has horizontal ruler', 'has horizontal scroller',
947 'has parent data item', 'has resize indicator',
948 'has shadow', 'has sub menu', 'has vertical ruler',
949 'has vertical scroller', 'header cell', 'header view',
950 'hidden', 'hides when deactivated', 'highlights by',
951 'horizontal line scroll', 'horizontal page scroll',
952 'horizontal ruler view', 'horizontally resizable',
953 'icon image', 'id', 'identifier',
954 'ignores multiple clicks',
955 'image( (alignment|dims when disabled|frame style|scaling))?',
956 'imports graphics', 'increment value',
957 'indentation per level', 'indeterminate', 'index',
958 'integer value', 'intercell spacing', 'item height',
959 'key( (code|equivalent( modifier)?|window))?',
960 'knob thickness', 'label', 'last( visible)? column',
961 'leading offset', 'leaf', 'level', 'line scroll',
962 'loaded', 'localized sort', 'location', 'loop mode',
963 'main( (bunde|menu|window))?', 'marker follows cell',
964 'matrix mode', 'maximum( content)? size',
965 'maximum visible columns',
966 'menu( form representation)?', 'miniaturizable',
967 'miniaturized', 'minimized image', 'minimized title',
968 'minimum column width', 'minimum( content)? size',
969 'modal', 'modified', 'mouse down state',
970 'movie( (controller|file|rect))?', 'muted', 'name',
971 'needs display', 'next state', 'next text',
972 'number of tick marks', 'only tick mark values',
973 'opaque', 'open panel', 'option key down',
974 'outline table column', 'page scroll', 'pages across',
975 'pages down', 'palette label', 'pane splitter',
976 'parent data item', 'parent window', 'pasteboard',
977 'path( (names|separator))?', 'playing',
978 'plays every frame', 'plays selection only', 'position',
979 'preferred edge', 'preferred type', 'pressure',
980 'previous text', 'prompt', 'properties',
981 'prototype cell', 'pulls down', 'rate',
982 'released when closed', 'repeated',
983 'requested print time', 'required file type',
984 'resizable', 'resized column', 'resource path',
985 'returns records', 'reuses columns', 'rich text',
986 'roll over', 'row height', 'rulers visible',
987 'save panel', 'scripts path', 'scrollable',
988 'selectable( identifiers)?', 'selected cell',
989 'selected( data)? columns?', 'selected data items?',
990 'selected( data)? rows?', 'selected item identifier',
991 'selection by rect', 'send action on arrow key',
992 'sends action when done editing', 'separates columns',
993 'separator item', 'sequence number', 'services menu',
994 'shared frameworks path', 'shared support path',
995 'sheet', 'shift key down', 'shows alpha',
996 'shows state by', 'size( mode)?',
997 'smart insert delete enabled', 'sort case sensitivity',
998 'sort column', 'sort order', 'sort type',
999 'sorted( data rows)?', 'sound', 'source( mask)?',
1000 'spell checking enabled', 'starting page', 'state',
1001 'string value', 'sub menu', 'super menu', 'super view',
1002 'tab key traverses cells', 'tab state', 'tab type',
1003 'tab view', 'table view', 'tag', 'target( printer)?',
1004 'text color', 'text container insert',
1005 'text container origin', 'text returned',
1006 'tick mark position', 'time stamp',
1007 'title(d| (cell|font|height|position|rect))?',
1008 'tool tip', 'toolbar', 'trailing offset', 'transparent',
1009 'treat packages as directories', 'truncated labels',
1010 'types', 'unmodified characters', 'update views',
1011 'use sort indicator', 'user defaults',
1012 'uses data source', 'uses ruler',
1013 'uses threaded animation',
1014 'uses title from previous column', 'value wraps',
1015 'version',
1016 'vertical( (line scroll|page scroll|ruler view))?',
1017 'vertically resizable', 'view',
1018 'visible( document rect)?', 'volume', 'width', 'window',
1019 'windows menu', 'wraps', 'zoomable', 'zoomed')
1020
1021 tokens = {
1022 'root': [
1023 (r'\s+', Text),
1024 (r'¬\n', String.Escape),
1025 (r"'s\s+", Text), # This is a possessive, consider moving
1026 (r'(--|#).*?$', Comment),
1027 (r'\(\*', Comment.Multiline, 'comment'),
1028 (r'[(){}!,.:]', Punctuation),
1029 (r'(«)([^»]+)(»)',
1030 bygroups(Text, Name.Builtin, Text)),
1031 (r'\b((?:considering|ignoring)\s*)'
1032 r'(application responses|case|diacriticals|hyphens|'
1033 r'numeric strings|punctuation|white space)',
1034 bygroups(Keyword, Name.Builtin)),
1035 (r'(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|/|÷|\^)', Operator),
1036 (r"\b({})\b".format('|'.join(Operators)), Operator.Word),
1037 (r'^(\s*(?:on|end)\s+)'
1038 r'({})'.format('|'.join(StudioEvents[::-1])),
1039 bygroups(Keyword, Name.Function)),
1040 (r'^(\s*)(in|on|script|to)(\s+)', bygroups(Text, Keyword, Text)),
1041 (r'\b(as )({})\b'.format('|'.join(Classes)),
1042 bygroups(Keyword, Name.Class)),
1043 (r'\b({})\b'.format('|'.join(Literals)), Name.Constant),
1044 (r'\b({})\b'.format('|'.join(Commands)), Name.Builtin),
1045 (r'\b({})\b'.format('|'.join(Control)), Keyword),
1046 (r'\b({})\b'.format('|'.join(Declarations)), Keyword),
1047 (r'\b({})\b'.format('|'.join(Reserved)), Name.Builtin),
1048 (r'\b({})s?\b'.format('|'.join(BuiltIn)), Name.Builtin),
1049 (r'\b({})\b'.format('|'.join(HandlerParams)), Name.Builtin),
1050 (r'\b({})\b'.format('|'.join(StudioProperties)), Name.Attribute),
1051 (r'\b({})s?\b'.format('|'.join(StudioClasses)), Name.Builtin),
1052 (r'\b({})\b'.format('|'.join(StudioCommands)), Name.Builtin),
1053 (r'\b({})\b'.format('|'.join(References)), Name.Builtin),
1054 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
1055 (rf'\b({Identifiers})\b', Name.Variable),
1056 (r'[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?', Number.Float),
1057 (r'[-+]?\d+', Number.Integer),
1058 ],
1059 'comment': [
1060 (r'\(\*', Comment.Multiline, '#push'),
1061 (r'\*\)', Comment.Multiline, '#pop'),
1062 ('[^*(]+', Comment.Multiline),
1063 ('[*(]', Comment.Multiline),
1064 ],
1065 }
1066
1067
1068class RexxLexer(RegexLexer):
1069 """
1070 Rexx is a scripting language available for
1071 a wide range of different platforms with its roots found on mainframe
1072 systems. It is popular for I/O- and data based tasks and can act as glue
1073 language to bind different applications together.
1074 """
1075 name = 'Rexx'
1076 url = 'http://www.rexxinfo.org/'
1077 aliases = ['rexx', 'arexx']
1078 filenames = ['*.rexx', '*.rex', '*.rx', '*.arexx']
1079 mimetypes = ['text/x-rexx']
1080 version_added = '2.0'
1081 flags = re.IGNORECASE
1082
1083 tokens = {
1084 'root': [
1085 (r'\s+', Whitespace),
1086 (r'/\*', Comment.Multiline, 'comment'),
1087 (r'"', String, 'string_double'),
1088 (r"'", String, 'string_single'),
1089 (r'[0-9]+(\.[0-9]+)?(e[+-]?[0-9])?', Number),
1090 (r'([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b',
1091 bygroups(Name.Function, Whitespace, Operator, Whitespace,
1092 Keyword.Declaration)),
1093 (r'([a-z_]\w*)(\s*)(:)',
1094 bygroups(Name.Label, Whitespace, Operator)),
1095 include('function'),
1096 include('keyword'),
1097 include('operator'),
1098 (r'[a-z_]\w*', Text),
1099 ],
1100 'function': [
1101 (words((
1102 'abbrev', 'abs', 'address', 'arg', 'b2x', 'bitand', 'bitor', 'bitxor',
1103 'c2d', 'c2x', 'center', 'charin', 'charout', 'chars', 'compare',
1104 'condition', 'copies', 'd2c', 'd2x', 'datatype', 'date', 'delstr',
1105 'delword', 'digits', 'errortext', 'form', 'format', 'fuzz', 'insert',
1106 'lastpos', 'left', 'length', 'linein', 'lineout', 'lines', 'max',
1107 'min', 'overlay', 'pos', 'queued', 'random', 'reverse', 'right', 'sign',
1108 'sourceline', 'space', 'stream', 'strip', 'substr', 'subword', 'symbol',
1109 'time', 'trace', 'translate', 'trunc', 'value', 'verify', 'word',
1110 'wordindex', 'wordlength', 'wordpos', 'words', 'x2b', 'x2c', 'x2d',
1111 'xrange'), suffix=r'(\s*)(\()'),
1112 bygroups(Name.Builtin, Whitespace, Operator)),
1113 ],
1114 'keyword': [
1115 (r'(address|arg|by|call|do|drop|else|end|exit|for|forever|if|'
1116 r'interpret|iterate|leave|nop|numeric|off|on|options|parse|'
1117 r'pull|push|queue|return|say|select|signal|to|then|trace|until|'
1118 r'while)\b', Keyword.Reserved),
1119 ],
1120 'operator': [
1121 (r'(-|//|/|\(|\)|\*\*|\*|\\<<|\\<|\\==|\\=|\\>>|\\>|\\|\|\||\||'
1122 r'&&|&|%|\+|<<=|<<|<=|<>|<|==|=|><|>=|>>=|>>|>|¬<<|¬<|¬==|¬=|'
1123 r'¬>>|¬>|¬|\.|,)', Operator),
1124 ],
1125 'string_double': [
1126 (r'[^"\n]+', String),
1127 (r'""', String),
1128 (r'"', String, '#pop'),
1129 (r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
1130 ],
1131 'string_single': [
1132 (r'[^\'\n]+', String),
1133 (r'\'\'', String),
1134 (r'\'', String, '#pop'),
1135 (r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
1136 ],
1137 'comment': [
1138 (r'[^*]+', Comment.Multiline),
1139 (r'\*/', Comment.Multiline, '#pop'),
1140 (r'\*', Comment.Multiline),
1141 ]
1142 }
1143
1144 def _c(s):
1145 return re.compile(s, re.MULTILINE)
1146 _ADDRESS_COMMAND_PATTERN = _c(r'^\s*address\s+command\b')
1147 _ADDRESS_PATTERN = _c(r'^\s*address\s+')
1148 _DO_WHILE_PATTERN = _c(r'^\s*do\s+while\b')
1149 _IF_THEN_DO_PATTERN = _c(r'^\s*if\b.+\bthen\s+do\s*$')
1150 _PROCEDURE_PATTERN = _c(r'^\s*([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b')
1151 _ELSE_DO_PATTERN = _c(r'\belse\s+do\s*$')
1152 _PARSE_ARG_PATTERN = _c(r'^\s*parse\s+(upper\s+)?(arg|value)\b')
1153 PATTERNS_AND_WEIGHTS = (
1154 (_ADDRESS_COMMAND_PATTERN, 0.2),
1155 (_ADDRESS_PATTERN, 0.05),
1156 (_DO_WHILE_PATTERN, 0.1),
1157 (_ELSE_DO_PATTERN, 0.1),
1158 (_IF_THEN_DO_PATTERN, 0.1),
1159 (_PROCEDURE_PATTERN, 0.5),
1160 (_PARSE_ARG_PATTERN, 0.2),
1161 )
1162
1163 def analyse_text(text):
1164 """
1165 Check for initial comment and patterns that distinguish Rexx from other
1166 C-like languages.
1167 """
1168 if re.search(r'/\*\**\s*rexx', text, re.IGNORECASE):
1169 # Header matches MVS Rexx requirements, this is certainly a Rexx
1170 # script.
1171 return 1.0
1172 elif text.startswith('/*'):
1173 # Header matches general Rexx requirements; the source code might
1174 # still be any language using C comments such as C++, C# or Java.
1175 lowerText = text.lower()
1176 result = sum(weight
1177 for (pattern, weight) in RexxLexer.PATTERNS_AND_WEIGHTS
1178 if pattern.search(lowerText)) + 0.01
1179 return min(result, 1.0)
1180
1181
1182class MOOCodeLexer(RegexLexer):
1183 """
1184 For MOOCode (the MOO scripting language).
1185 """
1186 name = 'MOOCode'
1187 url = 'http://www.moo.mud.org/'
1188 filenames = ['*.moo']
1189 aliases = ['moocode', 'moo']
1190 mimetypes = ['text/x-moocode']
1191 version_added = '0.9'
1192
1193 tokens = {
1194 'root': [
1195 # Numbers
1196 (r'(0|[1-9][0-9_]*)', Number.Integer),
1197 # Strings
1198 (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
1199 # exceptions
1200 (r'(E_PERM|E_DIV)', Name.Exception),
1201 # db-refs
1202 (r'((#[-0-9]+)|(\$\w+))', Name.Entity),
1203 # Keywords
1204 (r'\b(if|else|elseif|endif|for|endfor|fork|endfork|while'
1205 r'|endwhile|break|continue|return|try'
1206 r'|except|endtry|finally|in)\b', Keyword),
1207 # builtins
1208 (r'(random|length)', Name.Builtin),
1209 # special variables
1210 (r'(player|caller|this|args)', Name.Variable.Instance),
1211 # skip whitespace
1212 (r'\s+', Text),
1213 (r'\n', Text),
1214 # other operators
1215 (r'([!;=,{}&|:.\[\]@()<>?]+)', Operator),
1216 # function call
1217 (r'(\w+)(\()', bygroups(Name.Function, Operator)),
1218 # variables
1219 (r'(\w+)', Text),
1220 ]
1221 }
1222
1223
1224class HybrisLexer(RegexLexer):
1225 """
1226 For Hybris source code.
1227 """
1228
1229 name = 'Hybris'
1230 aliases = ['hybris']
1231 filenames = ['*.hyb']
1232 mimetypes = ['text/x-hybris', 'application/x-hybris']
1233 url = 'https://github.com/evilsocket/hybris'
1234 version_added = '1.4'
1235
1236 flags = re.MULTILINE | re.DOTALL
1237
1238 tokens = {
1239 'root': [
1240 # method names
1241 (r'^(\s*(?:function|method|operator\s+)+?)'
1242 r'([a-zA-Z_]\w*)'
1243 r'(\s*)(\()', bygroups(Keyword, Name.Function, Text, Operator)),
1244 (r'[^\S\n]+', Text),
1245 (r'//.*?\n', Comment.Single),
1246 (r'/\*.*?\*/', Comment.Multiline),
1247 (r'@[a-zA-Z_][\w.]*', Name.Decorator),
1248 (r'(break|case|catch|next|default|do|else|finally|for|foreach|of|'
1249 r'unless|if|new|return|switch|me|throw|try|while)\b', Keyword),
1250 (r'(extends|private|protected|public|static|throws|function|method|'
1251 r'operator)\b', Keyword.Declaration),
1252 (r'(true|false|null|__FILE__|__LINE__|__VERSION__|__LIB_PATH__|'
1253 r'__INC_PATH__)\b', Keyword.Constant),
1254 (r'(class|struct)(\s+)',
1255 bygroups(Keyword.Declaration, Text), 'class'),
1256 (r'(import|include)(\s+)',
1257 bygroups(Keyword.Namespace, Text), 'import'),
1258 (words((
1259 'gc_collect', 'gc_mm_items', 'gc_mm_usage', 'gc_collect_threshold',
1260 'urlencode', 'urldecode', 'base64encode', 'base64decode', 'sha1', 'crc32',
1261 'sha2', 'md5', 'md5_file', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos',
1262 'cosh', 'exp', 'fabs', 'floor', 'fmod', 'log', 'log10', 'pow', 'sin',
1263 'sinh', 'sqrt', 'tan', 'tanh', 'isint', 'isfloat', 'ischar', 'isstring',
1264 'isarray', 'ismap', 'isalias', 'typeof', 'sizeof', 'toint', 'tostring',
1265 'fromxml', 'toxml', 'binary', 'pack', 'load', 'eval', 'var_names',
1266 'var_values', 'user_functions', 'dyn_functions', 'methods', 'call',
1267 'call_method', 'mknod', 'mkfifo', 'mount', 'umount2', 'umount', 'ticks',
1268 'usleep', 'sleep', 'time', 'strtime', 'strdate', 'dllopen', 'dlllink',
1269 'dllcall', 'dllcall_argv', 'dllclose', 'env', 'exec', 'fork', 'getpid',
1270 'wait', 'popen', 'pclose', 'exit', 'kill', 'pthread_create',
1271 'pthread_create_argv', 'pthread_exit', 'pthread_join', 'pthread_kill',
1272 'smtp_send', 'http_get', 'http_post', 'http_download', 'socket', 'bind',
1273 'listen', 'accept', 'getsockname', 'getpeername', 'settimeout', 'connect',
1274 'server', 'recv', 'send', 'close', 'print', 'println', 'printf', 'input',
1275 'readline', 'serial_open', 'serial_fcntl', 'serial_get_attr',
1276 'serial_get_ispeed', 'serial_get_ospeed', 'serial_set_attr',
1277 'serial_set_ispeed', 'serial_set_ospeed', 'serial_write', 'serial_read',
1278 'serial_close', 'xml_load', 'xml_parse', 'fopen', 'fseek', 'ftell',
1279 'fsize', 'fread', 'fwrite', 'fgets', 'fclose', 'file', 'readdir',
1280 'pcre_replace', 'size', 'pop', 'unmap', 'has', 'keys', 'values',
1281 'length', 'find', 'substr', 'replace', 'split', 'trim', 'remove',
1282 'contains', 'join'), suffix=r'\b'),
1283 Name.Builtin),
1284 (words((
1285 'MethodReference', 'Runner', 'Dll', 'Thread', 'Pipe', 'Process',
1286 'Runnable', 'CGI', 'ClientSocket', 'Socket', 'ServerSocket',
1287 'File', 'Console', 'Directory', 'Exception'), suffix=r'\b'),
1288 Keyword.Type),
1289 (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
1290 (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
1291 (r'(\.)([a-zA-Z_]\w*)',
1292 bygroups(Operator, Name.Attribute)),
1293 (r'[a-zA-Z_]\w*:', Name.Label),
1294 (r'[a-zA-Z_$]\w*', Name),
1295 (r'[~^*!%&\[\](){}<>|+=:;,./?\-@]+', Operator),
1296 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
1297 (r'0x[0-9a-f]+', Number.Hex),
1298 (r'[0-9]+L?', Number.Integer),
1299 (r'\n', Text),
1300 ],
1301 'class': [
1302 (r'[a-zA-Z_]\w*', Name.Class, '#pop')
1303 ],
1304 'import': [
1305 (r'[\w.]+\*?', Name.Namespace, '#pop')
1306 ],
1307 }
1308
1309 def analyse_text(text):
1310 """public method and private method don't seem to be quite common
1311 elsewhere."""
1312 result = 0
1313 if re.search(r'\b(?:public|private)\s+method\b', text):
1314 result += 0.01
1315 return result
1316
1317
1318
1319class EasytrieveLexer(RegexLexer):
1320 """
1321 Easytrieve Plus is a programming language for extracting, filtering and
1322 converting sequential data. Furthermore it can layout data for reports.
1323 It is mainly used on mainframe platforms and can access several of the
1324 mainframe's native file formats. It is somewhat comparable to awk.
1325 """
1326 name = 'Easytrieve'
1327 aliases = ['easytrieve']
1328 filenames = ['*.ezt', '*.mac']
1329 mimetypes = ['text/x-easytrieve']
1330 url = 'https://www.broadcom.com/products/mainframe/application-development/easytrieve-report-generator'
1331 version_added = '2.1'
1332 flags = 0
1333
1334 # Note: We cannot use r'\b' at the start and end of keywords because
1335 # Easytrieve Plus delimiter characters are:
1336 #
1337 # * space ( )
1338 # * apostrophe (')
1339 # * period (.)
1340 # * comma (,)
1341 # * parenthesis ( and )
1342 # * colon (:)
1343 #
1344 # Additionally words end once a '*' appears, indicatins a comment.
1345 _DELIMITERS = r' \'.,():\n'
1346 _DELIMITERS_OR_COMENT = _DELIMITERS + '*'
1347 _DELIMITER_PATTERN = '[' + _DELIMITERS + ']'
1348 _DELIMITER_PATTERN_CAPTURE = '(' + _DELIMITER_PATTERN + ')'
1349 _NON_DELIMITER_OR_COMMENT_PATTERN = '[^' + _DELIMITERS_OR_COMENT + ']'
1350 _OPERATORS_PATTERN = '[.+\\-/=\\[\\](){}<>;,&%¬]'
1351 _KEYWORDS = [
1352 'AFTER-BREAK', 'AFTER-LINE', 'AFTER-SCREEN', 'AIM', 'AND', 'ATTR',
1353 'BEFORE', 'BEFORE-BREAK', 'BEFORE-LINE', 'BEFORE-SCREEN', 'BUSHU',
1354 'BY', 'CALL', 'CASE', 'CHECKPOINT', 'CHKP', 'CHKP-STATUS', 'CLEAR',
1355 'CLOSE', 'COL', 'COLOR', 'COMMIT', 'CONTROL', 'COPY', 'CURSOR', 'D',
1356 'DECLARE', 'DEFAULT', 'DEFINE', 'DELETE', 'DENWA', 'DISPLAY', 'DLI',
1357 'DO', 'DUPLICATE', 'E', 'ELSE', 'ELSE-IF', 'END', 'END-CASE',
1358 'END-DO', 'END-IF', 'END-PROC', 'ENDPAGE', 'ENDTABLE', 'ENTER', 'EOF',
1359 'EQ', 'ERROR', 'EXIT', 'EXTERNAL', 'EZLIB', 'F1', 'F10', 'F11', 'F12',
1360 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F2', 'F20', 'F21',
1361 'F22', 'F23', 'F24', 'F25', 'F26', 'F27', 'F28', 'F29', 'F3', 'F30',
1362 'F31', 'F32', 'F33', 'F34', 'F35', 'F36', 'F4', 'F5', 'F6', 'F7',
1363 'F8', 'F9', 'FETCH', 'FILE-STATUS', 'FILL', 'FINAL', 'FIRST',
1364 'FIRST-DUP', 'FOR', 'GE', 'GET', 'GO', 'GOTO', 'GQ', 'GR', 'GT',
1365 'HEADING', 'HEX', 'HIGH-VALUES', 'IDD', 'IDMS', 'IF', 'IN', 'INSERT',
1366 'JUSTIFY', 'KANJI-DATE', 'KANJI-DATE-LONG', 'KANJI-TIME', 'KEY',
1367 'KEY-PRESSED', 'KOKUGO', 'KUN', 'LAST-DUP', 'LE', 'LEVEL', 'LIKE',
1368 'LINE', 'LINE-COUNT', 'LINE-NUMBER', 'LINK', 'LIST', 'LOW-VALUES',
1369 'LQ', 'LS', 'LT', 'MACRO', 'MASK', 'MATCHED', 'MEND', 'MESSAGE',
1370 'MOVE', 'MSTART', 'NE', 'NEWPAGE', 'NOMASK', 'NOPRINT', 'NOT',
1371 'NOTE', 'NOVERIFY', 'NQ', 'NULL', 'OF', 'OR', 'OTHERWISE', 'PA1',
1372 'PA2', 'PA3', 'PAGE-COUNT', 'PAGE-NUMBER', 'PARM-REGISTER',
1373 'PATH-ID', 'PATTERN', 'PERFORM', 'POINT', 'POS', 'PRIMARY', 'PRINT',
1374 'PROCEDURE', 'PROGRAM', 'PUT', 'READ', 'RECORD', 'RECORD-COUNT',
1375 'RECORD-LENGTH', 'REFRESH', 'RELEASE', 'RENUM', 'REPEAT', 'REPORT',
1376 'REPORT-INPUT', 'RESHOW', 'RESTART', 'RETRIEVE', 'RETURN-CODE',
1377 'ROLLBACK', 'ROW', 'S', 'SCREEN', 'SEARCH', 'SECONDARY', 'SELECT',
1378 'SEQUENCE', 'SIZE', 'SKIP', 'SOKAKU', 'SORT', 'SQL', 'STOP', 'SUM',
1379 'SYSDATE', 'SYSDATE-LONG', 'SYSIN', 'SYSIPT', 'SYSLST', 'SYSPRINT',
1380 'SYSSNAP', 'SYSTIME', 'TALLY', 'TERM-COLUMNS', 'TERM-NAME',
1381 'TERM-ROWS', 'TERMINATION', 'TITLE', 'TO', 'TRANSFER', 'TRC',
1382 'UNIQUE', 'UNTIL', 'UPDATE', 'UPPERCASE', 'USER', 'USERID', 'VALUE',
1383 'VERIFY', 'W', 'WHEN', 'WHILE', 'WORK', 'WRITE', 'X', 'XDM', 'XRST'
1384 ]
1385
1386 tokens = {
1387 'root': [
1388 (r'\*.*\n', Comment.Single),
1389 (r'\n+', Whitespace),
1390 # Macro argument
1391 (r'&' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+\.', Name.Variable,
1392 'after_macro_argument'),
1393 # Macro call
1394 (r'%' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Variable),
1395 (r'(FILE|MACRO|REPORT)(\s+)',
1396 bygroups(Keyword.Declaration, Whitespace), 'after_declaration'),
1397 (r'(JOB|PARM)' + r'(' + _DELIMITER_PATTERN + r')',
1398 bygroups(Keyword.Declaration, Operator)),
1399 (words(_KEYWORDS, suffix=_DELIMITER_PATTERN_CAPTURE),
1400 bygroups(Keyword.Reserved, Operator)),
1401 (_OPERATORS_PATTERN, Operator),
1402 # Procedure declaration
1403 (r'(' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+)(\s*)(\.?)(\s*)(PROC)(\s*\n)',
1404 bygroups(Name.Function, Whitespace, Operator, Whitespace,
1405 Keyword.Declaration, Whitespace)),
1406 (r'[0-9]+\.[0-9]*', Number.Float),
1407 (r'[0-9]+', Number.Integer),
1408 (r"'(''|[^'])*'", String),
1409 (r'\s+', Whitespace),
1410 # Everything else just belongs to a name
1411 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
1412 ],
1413 'after_declaration': [
1414 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Function),
1415 default('#pop'),
1416 ],
1417 'after_macro_argument': [
1418 (r'\*.*\n', Comment.Single, '#pop'),
1419 (r'\s+', Whitespace, '#pop'),
1420 (_OPERATORS_PATTERN, Operator, '#pop'),
1421 (r"'(''|[^'])*'", String, '#pop'),
1422 # Everything else just belongs to a name
1423 (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
1424 ],
1425 }
1426 _COMMENT_LINE_REGEX = re.compile(r'^\s*\*')
1427 _MACRO_HEADER_REGEX = re.compile(r'^\s*MACRO')
1428
1429 def analyse_text(text):
1430 """
1431 Perform a structural analysis for basic Easytrieve constructs.
1432 """
1433 result = 0.0
1434 lines = text.split('\n')
1435 hasEndProc = False
1436 hasHeaderComment = False
1437 hasFile = False
1438 hasJob = False
1439 hasProc = False
1440 hasParm = False
1441 hasReport = False
1442
1443 def isCommentLine(line):
1444 return EasytrieveLexer._COMMENT_LINE_REGEX.match(lines[0]) is not None
1445
1446 def isEmptyLine(line):
1447 return not bool(line.strip())
1448
1449 # Remove possible empty lines and header comments.
1450 while lines and (isEmptyLine(lines[0]) or isCommentLine(lines[0])):
1451 if not isEmptyLine(lines[0]):
1452 hasHeaderComment = True
1453 del lines[0]
1454
1455 if EasytrieveLexer._MACRO_HEADER_REGEX.match(lines[0]):
1456 # Looks like an Easytrieve macro.
1457 result = 0.4
1458 if hasHeaderComment:
1459 result += 0.4
1460 else:
1461 # Scan the source for lines starting with indicators.
1462 for line in lines:
1463 words = line.split()
1464 if (len(words) >= 2):
1465 firstWord = words[0]
1466 if not hasReport:
1467 if not hasJob:
1468 if not hasFile:
1469 if not hasParm:
1470 if firstWord == 'PARM':
1471 hasParm = True
1472 if firstWord == 'FILE':
1473 hasFile = True
1474 if firstWord == 'JOB':
1475 hasJob = True
1476 elif firstWord == 'PROC':
1477 hasProc = True
1478 elif firstWord == 'END-PROC':
1479 hasEndProc = True
1480 elif firstWord == 'REPORT':
1481 hasReport = True
1482
1483 # Weight the findings.
1484 if hasJob and (hasProc == hasEndProc):
1485 if hasHeaderComment:
1486 result += 0.1
1487 if hasParm:
1488 if hasProc:
1489 # Found PARM, JOB and PROC/END-PROC:
1490 # pretty sure this is Easytrieve.
1491 result += 0.8
1492 else:
1493 # Found PARAM and JOB: probably this is Easytrieve
1494 result += 0.5
1495 else:
1496 # Found JOB and possibly other keywords: might be Easytrieve
1497 result += 0.11
1498 if hasParm:
1499 # Note: PARAM is not a proper English word, so this is
1500 # regarded a much better indicator for Easytrieve than
1501 # the other words.
1502 result += 0.2
1503 if hasFile:
1504 result += 0.01
1505 if hasReport:
1506 result += 0.01
1507 assert 0.0 <= result <= 1.0
1508 return result
1509
1510
1511class JclLexer(RegexLexer):
1512 """
1513 Job Control Language (JCL)
1514 is a scripting language used on mainframe platforms to instruct the system
1515 on how to run a batch job or start a subsystem. It is somewhat
1516 comparable to MS DOS batch and Unix shell scripts.
1517 """
1518 name = 'JCL'
1519 aliases = ['jcl']
1520 filenames = ['*.jcl']
1521 mimetypes = ['text/x-jcl']
1522 url = 'https://en.wikipedia.org/wiki/Job_Control_Language'
1523 version_added = '2.1'
1524
1525 flags = re.IGNORECASE
1526
1527 tokens = {
1528 'root': [
1529 (r'//\*.*\n', Comment.Single),
1530 (r'//', Keyword.Pseudo, 'statement'),
1531 (r'/\*', Keyword.Pseudo, 'jes2_statement'),
1532 # TODO: JES3 statement
1533 (r'.*\n', Other) # Input text or inline code in any language.
1534 ],
1535 'statement': [
1536 (r'\s*\n', Whitespace, '#pop'),
1537 (r'([a-z]\w*)(\s+)(exec|job)(\s*)',
1538 bygroups(Name.Label, Whitespace, Keyword.Reserved, Whitespace),
1539 'option'),
1540 (r'[a-z]\w*', Name.Variable, 'statement_command'),
1541 (r'\s+', Whitespace, 'statement_command'),
1542 ],
1543 'statement_command': [
1544 (r'\s+(command|cntl|dd|endctl|endif|else|include|jcllib|'
1545 r'output|pend|proc|set|then|xmit)\s+', Keyword.Reserved, 'option'),
1546 include('option')
1547 ],
1548 'jes2_statement': [
1549 (r'\s*\n', Whitespace, '#pop'),
1550 (r'\$', Keyword, 'option'),
1551 (r'\b(jobparam|message|netacct|notify|output|priority|route|'
1552 r'setup|signoff|xeq|xmit)\b', Keyword, 'option'),
1553 ],
1554 'option': [
1555 # (r'\n', Text, 'root'),
1556 (r'\*', Name.Builtin),
1557 (r'[\[\](){}<>;,]', Punctuation),
1558 (r'[-+*/=&%]', Operator),
1559 (r'[a-z_]\w*', Name),
1560 (r'\d+\.\d*', Number.Float),
1561 (r'\.\d+', Number.Float),
1562 (r'\d+', Number.Integer),
1563 (r"'", String, 'option_string'),
1564 (r'[ \t]+', Whitespace, 'option_comment'),
1565 (r'\.', Punctuation),
1566 ],
1567 'option_string': [
1568 (r"(\n)(//)", bygroups(Text, Keyword.Pseudo)),
1569 (r"''", String),
1570 (r"[^']", String),
1571 (r"'", String, '#pop'),
1572 ],
1573 'option_comment': [
1574 # (r'\n', Text, 'root'),
1575 (r'.+', Comment.Single),
1576 ]
1577 }
1578
1579 _JOB_HEADER_PATTERN = re.compile(r'^//[a-z#$@][a-z0-9#$@]{0,7}\s+job(\s+.*)?$',
1580 re.IGNORECASE)
1581
1582 def analyse_text(text):
1583 """
1584 Recognize JCL job by header.
1585 """
1586 result = 0.0
1587 lines = text.split('\n')
1588 if len(lines) > 0:
1589 if JclLexer._JOB_HEADER_PATTERN.match(lines[0]):
1590 result = 1.0
1591 assert 0.0 <= result <= 1.0
1592 return result
1593
1594
1595class MiniScriptLexer(RegexLexer):
1596 """
1597 For MiniScript source code.
1598 """
1599
1600 name = 'MiniScript'
1601 url = 'https://miniscript.org'
1602 aliases = ['miniscript', 'ms']
1603 filenames = ['*.ms']
1604 mimetypes = ['text/x-minicript', 'application/x-miniscript']
1605 version_added = '2.6'
1606
1607 tokens = {
1608 'root': [
1609 (r'#!(.*?)$', Comment.Preproc),
1610 default('base'),
1611 ],
1612 'base': [
1613 ('//.*$', Comment.Single),
1614 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number),
1615 (r'(?i)\d+e[+-]?\d+', Number),
1616 (r'\d+', Number),
1617 (r'\n', Text),
1618 (r'[^\S\n]+', Text),
1619 (r'"', String, 'string_double'),
1620 (r'(==|!=|<=|>=|[=+\-*/%^<>.:])', Operator),
1621 (r'[;,\[\]{}()]', Punctuation),
1622 (words((
1623 'break', 'continue', 'else', 'end', 'for', 'function', 'if',
1624 'in', 'isa', 'then', 'repeat', 'return', 'while'), suffix=r'\b'),
1625 Keyword),
1626 (words((
1627 'abs', 'acos', 'asin', 'atan', 'ceil', 'char', 'cos', 'floor',
1628 'log', 'round', 'rnd', 'pi', 'sign', 'sin', 'sqrt', 'str', 'tan',
1629 'hasIndex', 'indexOf', 'len', 'val', 'code', 'remove', 'lower',
1630 'upper', 'replace', 'split', 'indexes', 'values', 'join', 'sum',
1631 'sort', 'shuffle', 'push', 'pop', 'pull', 'range',
1632 'print', 'input', 'time', 'wait', 'locals', 'globals', 'outer',
1633 'yield'), suffix=r'\b'),
1634 Name.Builtin),
1635 (r'(true|false|null)\b', Keyword.Constant),
1636 (r'(and|or|not|new)\b', Operator.Word),
1637 (r'(self|super|__isa)\b', Name.Builtin.Pseudo),
1638 (r'[a-zA-Z_]\w*', Name.Variable)
1639 ],
1640 'string_double': [
1641 (r'[^"\n]+', String),
1642 (r'""', String),
1643 (r'"', String, '#pop'),
1644 (r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
1645 ]
1646 }