Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

1617 řádky
80 KiB

  1. """
  2. pygments.lexers.scripting
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexer for scripting and embedded languages.
  5. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, include, bygroups, default, combined, \
  10. words
  11. from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
  12. Number, Punctuation, Error, Whitespace, Other
  13. from pygments.util import get_bool_opt, get_list_opt
  14. __all__ = ['LuaLexer', 'LuauLexer', 'MoonScriptLexer', 'ChaiscriptLexer', 'LSLLexer',
  15. 'AppleScriptLexer', 'RexxLexer', 'MOOCodeLexer', 'HybrisLexer',
  16. 'EasytrieveLexer', 'JclLexer', 'MiniScriptLexer']
  17. def all_lua_builtins():
  18. from pygments.lexers._lua_builtins import MODULES
  19. return [w for values in MODULES.values() for w in values]
  20. class LuaLexer(RegexLexer):
  21. """
  22. For Lua source code.
  23. Additional options accepted:
  24. `func_name_highlighting`
  25. If given and ``True``, highlight builtin function names
  26. (default: ``True``).
  27. `disabled_modules`
  28. If given, must be a list of module names whose function names
  29. should not be highlighted. By default all modules are highlighted.
  30. To get a list of allowed modules have a look into the
  31. `_lua_builtins` module:
  32. .. sourcecode:: pycon
  33. >>> from pygments.lexers._lua_builtins import MODULES
  34. >>> MODULES.keys()
  35. ['string', 'coroutine', 'modules', 'io', 'basic', ...]
  36. """
  37. name = 'Lua'
  38. url = 'https://www.lua.org/'
  39. aliases = ['lua']
  40. filenames = ['*.lua', '*.wlua']
  41. mimetypes = ['text/x-lua', 'application/x-lua']
  42. version_added = ''
  43. _comment_multiline = r'(?:--\[(?P<level>=*)\[[\w\W]*?\](?P=level)\])'
  44. _comment_single = r'(?:--.*$)'
  45. _space = r'(?:\s+(?!\s))'
  46. _s = rf'(?:{_comment_multiline}|{_comment_single}|{_space})'
  47. _name = r'(?:[^\W\d]\w*)'
  48. tokens = {
  49. 'root': [
  50. # Lua allows a file to start with a shebang.
  51. (r'#!.*', Comment.Preproc),
  52. default('base'),
  53. ],
  54. 'ws': [
  55. (_comment_multiline, Comment.Multiline),
  56. (_comment_single, Comment.Single),
  57. (_space, Whitespace),
  58. ],
  59. 'base': [
  60. include('ws'),
  61. (r'(?i)0x[\da-f]*(\.[\da-f]*)?(p[+-]?\d+)?', Number.Hex),
  62. (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
  63. (r'(?i)\d+e[+-]?\d+', Number.Float),
  64. (r'\d+', Number.Integer),
  65. # multiline strings
  66. (r'(?s)\[(=*)\[.*?\]\1\]', String),
  67. (r'::', Punctuation, 'label'),
  68. (r'\.{3}', Punctuation),
  69. (r'[=<>|~&+\-*/%#^]+|\.\.', Operator),
  70. (r'[\[\]{}().,:;]+', Punctuation),
  71. (r'(and|or|not)\b', Operator.Word),
  72. (words([
  73. 'break', 'do', 'else', 'elseif', 'end', 'for', 'if', 'in',
  74. 'repeat', 'return', 'then', 'until', 'while'
  75. ], suffix=r'\b'), Keyword.Reserved),
  76. (r'goto\b', Keyword.Reserved, 'goto'),
  77. (r'(local)\b', Keyword.Declaration),
  78. (r'(true|false|nil)\b', Keyword.Constant),
  79. (r'(function)\b', Keyword.Reserved, 'funcname'),
  80. (words(all_lua_builtins(), suffix=r"\b"), Name.Builtin),
  81. (fr'[A-Za-z_]\w*(?={_s}*[.:])', Name.Variable, 'varname'),
  82. (fr'[A-Za-z_]\w*(?={_s}*\()', Name.Function),
  83. (r'[A-Za-z_]\w*', Name.Variable),
  84. ("'", String.Single, combined('stringescape', 'sqs')),
  85. ('"', String.Double, combined('stringescape', 'dqs'))
  86. ],
  87. 'varname': [
  88. include('ws'),
  89. (r'\.\.', Operator, '#pop'),
  90. (r'[.:]', Punctuation),
  91. (rf'{_name}(?={_s}*[.:])', Name.Property),
  92. (rf'{_name}(?={_s}*\()', Name.Function, '#pop'),
  93. (_name, Name.Property, '#pop'),
  94. ],
  95. 'funcname': [
  96. include('ws'),
  97. (r'[.:]', Punctuation),
  98. (rf'{_name}(?={_s}*[.:])', Name.Class),
  99. (_name, Name.Function, '#pop'),
  100. # inline function
  101. (r'\(', Punctuation, '#pop'),
  102. ],
  103. 'goto': [
  104. include('ws'),
  105. (_name, Name.Label, '#pop'),
  106. ],
  107. 'label': [
  108. include('ws'),
  109. (r'::', Punctuation, '#pop'),
  110. (_name, Name.Label),
  111. ],
  112. 'stringescape': [
  113. (r'\\([abfnrtv\\"\']|[\r\n]{1,2}|z\s*|x[0-9a-fA-F]{2}|\d{1,3}|'
  114. r'u\{[0-9a-fA-F]+\})', String.Escape),
  115. ],
  116. 'sqs': [
  117. (r"'", String.Single, '#pop'),
  118. (r"[^\\']+", String.Single),
  119. ],
  120. 'dqs': [
  121. (r'"', String.Double, '#pop'),
  122. (r'[^\\"]+', String.Double),
  123. ]
  124. }
  125. def __init__(self, **options):
  126. self.func_name_highlighting = get_bool_opt(
  127. options, 'func_name_highlighting', True)
  128. self.disabled_modules = get_list_opt(options, 'disabled_modules', [])
  129. self._functions = set()
  130. if self.func_name_highlighting:
  131. from pygments.lexers._lua_builtins import MODULES
  132. for mod, func in MODULES.items():
  133. if mod not in self.disabled_modules:
  134. self._functions.update(func)
  135. RegexLexer.__init__(self, **options)
  136. def get_tokens_unprocessed(self, text):
  137. for index, token, value in \
  138. RegexLexer.get_tokens_unprocessed(self, text):
  139. if token is Name.Builtin and value not in self._functions:
  140. if '.' in value:
  141. a, b = value.split('.')
  142. yield index, Name, a
  143. yield index + len(a), Punctuation, '.'
  144. yield index + len(a) + 1, Name, b
  145. else:
  146. yield index, Name, value
  147. continue
  148. yield index, token, value
  149. def _luau_make_expression(should_pop, _s):
  150. temp_list = [
  151. (r'0[xX][\da-fA-F_]*', Number.Hex, '#pop'),
  152. (r'0[bB][\d_]*', Number.Bin, '#pop'),
  153. (r'\.?\d[\d_]*(?:\.[\d_]*)?(?:[eE][+-]?[\d_]+)?', Number.Float, '#pop'),
  154. (words((
  155. 'true', 'false', 'nil'
  156. ), suffix=r'\b'), Keyword.Constant, '#pop'),
  157. (r'\[(=*)\[[.\n]*?\]\1\]', String, '#pop'),
  158. (r'(\.)([a-zA-Z_]\w*)(?=%s*[({"\'])', bygroups(Punctuation, Name.Function), '#pop'),
  159. (r'(\.)([a-zA-Z_]\w*)', bygroups(Punctuation, Name.Variable), '#pop'),
  160. (rf'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*(?={_s}*[({{"\'])', Name.Other, '#pop'),
  161. (r'[a-zA-Z_]\w*(?:\.[a-zA-Z_]\w*)*', Name, '#pop'),
  162. ]
  163. if should_pop:
  164. return temp_list
  165. return [entry[:2] for entry in temp_list]
  166. def _luau_make_expression_special(should_pop):
  167. temp_list = [
  168. (r'\{', Punctuation, ('#pop', 'closing_brace_base', 'expression')),
  169. (r'\(', Punctuation, ('#pop', 'closing_parenthesis_base', 'expression')),
  170. (r'::?', Punctuation, ('#pop', 'type_end', 'type_start')),
  171. (r"'", String.Single, ('#pop', 'string_single')),
  172. (r'"', String.Double, ('#pop', 'string_double')),
  173. (r'`', String.Backtick, ('#pop', 'string_interpolated')),
  174. ]
  175. if should_pop:
  176. return temp_list
  177. return [(entry[0], entry[1], entry[2][1:]) for entry in temp_list]
  178. class LuauLexer(RegexLexer):
  179. """
  180. For Luau source code.
  181. Additional options accepted:
  182. `include_luau_builtins`
  183. If given and ``True``, automatically highlight Luau builtins
  184. (default: ``True``).
  185. `include_roblox_builtins`
  186. If given and ``True``, automatically highlight Roblox-specific builtins
  187. (default: ``False``).
  188. `additional_builtins`
  189. If given, must be a list of additional builtins to highlight.
  190. `disabled_builtins`
  191. If given, must be a list of builtins that will not be highlighted.
  192. """
  193. name = 'Luau'
  194. url = 'https://luau-lang.org/'
  195. aliases = ['luau']
  196. filenames = ['*.luau']
  197. version_added = '2.18'
  198. _comment_multiline = r'(?:--\[(?P<level>=*)\[[\w\W]*?\](?P=level)\])'
  199. _comment_single = r'(?:--.*$)'
  200. _s = r'(?:{}|{}|{})'.format(_comment_multiline, _comment_single, r'\s+')
  201. tokens = {
  202. 'root': [
  203. (r'#!.*', Comment.Hashbang, 'base'),
  204. default('base'),
  205. ],
  206. 'ws': [
  207. (_comment_multiline, Comment.Multiline),
  208. (_comment_single, Comment.Single),
  209. (r'\s+', Whitespace),
  210. ],
  211. 'base': [
  212. include('ws'),
  213. *_luau_make_expression_special(False),
  214. (r'\.\.\.', Punctuation),
  215. (rf'type\b(?={_s}+[a-zA-Z_])', Keyword.Reserved, 'type_declaration'),
  216. (rf'export\b(?={_s}+[a-zA-Z_])', Keyword.Reserved),
  217. (r'(?:\.\.|//|[+\-*\/%^<>=])=?', Operator, 'expression'),
  218. (r'~=', Operator, 'expression'),
  219. (words((
  220. 'and', 'or', 'not'
  221. ), suffix=r'\b'), Operator.Word, 'expression'),
  222. (words((
  223. 'elseif', 'for', 'if', 'in', 'repeat', 'return', 'until',
  224. 'while'), suffix=r'\b'), Keyword.Reserved, 'expression'),
  225. (r'local\b', Keyword.Declaration, 'expression'),
  226. (r'function\b', Keyword.Reserved, ('expression', 'func_name')),
  227. (r'[\])};]+', Punctuation),
  228. include('expression_static'),
  229. *_luau_make_expression(False, _s),
  230. (r'[\[.,]', Punctuation, 'expression'),
  231. ],
  232. 'expression_static': [
  233. (words((
  234. 'break', 'continue', 'do', 'else', 'elseif', 'end', 'for',
  235. 'if', 'in', 'repeat', 'return', 'then', 'until', 'while'),
  236. suffix=r'\b'), Keyword.Reserved),
  237. ],
  238. 'expression': [
  239. include('ws'),
  240. (r'if\b', Keyword.Reserved, ('ternary', 'expression')),
  241. (r'local\b', Keyword.Declaration),
  242. *_luau_make_expression_special(True),
  243. (r'\.\.\.', Punctuation, '#pop'),
  244. (r'function\b', Keyword.Reserved, 'func_name'),
  245. include('expression_static'),
  246. *_luau_make_expression(True, _s),
  247. default('#pop'),
  248. ],
  249. 'ternary': [
  250. include('ws'),
  251. (r'else\b', Keyword.Reserved, '#pop'),
  252. (words((
  253. 'then', 'elseif',
  254. ), suffix=r'\b'), Operator.Reserved, 'expression'),
  255. default('#pop'),
  256. ],
  257. 'closing_brace_pop': [
  258. (r'\}', Punctuation, '#pop'),
  259. ],
  260. 'closing_parenthesis_pop': [
  261. (r'\)', Punctuation, '#pop'),
  262. ],
  263. 'closing_gt_pop': [
  264. (r'>', Punctuation, '#pop'),
  265. ],
  266. 'closing_parenthesis_base': [
  267. include('closing_parenthesis_pop'),
  268. include('base'),
  269. ],
  270. 'closing_parenthesis_type': [
  271. include('closing_parenthesis_pop'),
  272. include('type'),
  273. ],
  274. 'closing_brace_base': [
  275. include('closing_brace_pop'),
  276. include('base'),
  277. ],
  278. 'closing_brace_type': [
  279. include('closing_brace_pop'),
  280. include('type'),
  281. ],
  282. 'closing_gt_type': [
  283. include('closing_gt_pop'),
  284. include('type'),
  285. ],
  286. 'string_escape': [
  287. (r'\\z\s*', String.Escape),
  288. (r'\\(?:[abfnrtvz\\"\'`\{\n])|[\r\n]{1,2}|x[\da-fA-F]{2}|\d{1,3}|'
  289. r'u\{\}[\da-fA-F]*\}', String.Escape),
  290. ],
  291. 'string_single': [
  292. include('string_escape'),
  293. (r"'", String.Single, "#pop"),
  294. (r"[^\\']+", String.Single),
  295. ],
  296. 'string_double': [
  297. include('string_escape'),
  298. (r'"', String.Double, "#pop"),
  299. (r'[^\\"]+', String.Double),
  300. ],
  301. 'string_interpolated': [
  302. include('string_escape'),
  303. (r'\{', Punctuation, ('closing_brace_base', 'expression')),
  304. (r'`', String.Backtick, "#pop"),
  305. (r'[^\\`\{]+', String.Backtick),
  306. ],
  307. 'func_name': [
  308. include('ws'),
  309. (r'[.:]', Punctuation),
  310. (rf'[a-zA-Z_]\w*(?={_s}*[.:])', Name.Class),
  311. (r'[a-zA-Z_]\w*', Name.Function),
  312. (r'<', Punctuation, 'closing_gt_type'),
  313. (r'\(', Punctuation, '#pop'),
  314. ],
  315. 'type': [
  316. include('ws'),
  317. (r'\(', Punctuation, 'closing_parenthesis_type'),
  318. (r'\{', Punctuation, 'closing_brace_type'),
  319. (r'<', Punctuation, 'closing_gt_type'),
  320. (r"'", String.Single, 'string_single'),
  321. (r'"', String.Double, 'string_double'),
  322. (r'[|&\.,\[\]:=]+', Punctuation),
  323. (r'->', Punctuation),
  324. (r'typeof\(', Name.Builtin, ('closing_parenthesis_base',
  325. 'expression')),
  326. (r'[a-zA-Z_]\w*', Name.Class),
  327. ],
  328. 'type_start': [
  329. include('ws'),
  330. (r'\(', Punctuation, ('#pop', 'closing_parenthesis_type')),
  331. (r'\{', Punctuation, ('#pop', 'closing_brace_type')),
  332. (r'<', Punctuation, ('#pop', 'closing_gt_type')),
  333. (r"'", String.Single, ('#pop', 'string_single')),
  334. (r'"', String.Double, ('#pop', 'string_double')),
  335. (r'typeof\(', Name.Builtin, ('#pop', 'closing_parenthesis_base',
  336. 'expression')),
  337. (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
  338. ],
  339. 'type_end': [
  340. include('ws'),
  341. (r'[|&\.]', Punctuation, 'type_start'),
  342. (r'->', Punctuation, 'type_start'),
  343. (r'<', Punctuation, 'closing_gt_type'),
  344. default('#pop'),
  345. ],
  346. 'type_declaration': [
  347. include('ws'),
  348. (r'[a-zA-Z_]\w*', Name.Class),
  349. (r'<', Punctuation, 'closing_gt_type'),
  350. (r'=', Punctuation, ('#pop', 'type_end', 'type_start')),
  351. ],
  352. }
  353. def __init__(self, **options):
  354. self.include_luau_builtins = get_bool_opt(
  355. options, 'include_luau_builtins', True)
  356. self.include_roblox_builtins = get_bool_opt(
  357. options, 'include_roblox_builtins', False)
  358. self.additional_builtins = get_list_opt(options, 'additional_builtins', [])
  359. self.disabled_builtins = get_list_opt(options, 'disabled_builtins', [])
  360. self._builtins = set(self.additional_builtins)
  361. if self.include_luau_builtins:
  362. from pygments.lexers._luau_builtins import LUAU_BUILTINS
  363. self._builtins.update(LUAU_BUILTINS)
  364. if self.include_roblox_builtins:
  365. from pygments.lexers._luau_builtins import ROBLOX_BUILTINS
  366. self._builtins.update(ROBLOX_BUILTINS)
  367. if self.additional_builtins:
  368. self._builtins.update(self.additional_builtins)
  369. self._builtins.difference_update(self.disabled_builtins)
  370. RegexLexer.__init__(self, **options)
  371. def get_tokens_unprocessed(self, text):
  372. for index, token, value in \
  373. RegexLexer.get_tokens_unprocessed(self, text):
  374. if token is Name or token is Name.Other:
  375. split_value = value.split('.')
  376. complete_value = []
  377. new_index = index
  378. for position in range(len(split_value), 0, -1):
  379. potential_string = '.'.join(split_value[:position])
  380. if potential_string in self._builtins:
  381. yield index, Name.Builtin, potential_string
  382. new_index += len(potential_string)
  383. if complete_value:
  384. yield new_index, Punctuation, '.'
  385. new_index += 1
  386. break
  387. complete_value.insert(0, split_value[position - 1])
  388. for position, substring in enumerate(complete_value):
  389. if position + 1 == len(complete_value):
  390. if token is Name:
  391. yield new_index, Name.Variable, substring
  392. continue
  393. yield new_index, Name.Function, substring
  394. continue
  395. yield new_index, Name.Variable, substring
  396. new_index += len(substring)
  397. yield new_index, Punctuation, '.'
  398. new_index += 1
  399. continue
  400. yield index, token, value
  401. class MoonScriptLexer(LuaLexer):
  402. """
  403. For MoonScript source code.
  404. """
  405. name = 'MoonScript'
  406. url = 'http://moonscript.org'
  407. aliases = ['moonscript', 'moon']
  408. filenames = ['*.moon']
  409. mimetypes = ['text/x-moonscript', 'application/x-moonscript']
  410. version_added = '1.5'
  411. tokens = {
  412. 'root': [
  413. (r'#!(.*?)$', Comment.Preproc),
  414. default('base'),
  415. ],
  416. 'base': [
  417. ('--.*$', Comment.Single),
  418. (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float),
  419. (r'(?i)\d+e[+-]?\d+', Number.Float),
  420. (r'(?i)0x[0-9a-f]*', Number.Hex),
  421. (r'\d+', Number.Integer),
  422. (r'\n', Whitespace),
  423. (r'[^\S\n]+', Text),
  424. (r'(?s)\[(=*)\[.*?\]\1\]', String),
  425. (r'(->|=>)', Name.Function),
  426. (r':[a-zA-Z_]\w*', Name.Variable),
  427. (r'(==|!=|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#!.\\:])', Operator),
  428. (r'[;,]', Punctuation),
  429. (r'[\[\]{}()]', Keyword.Type),
  430. (r'[a-zA-Z_]\w*:', Name.Variable),
  431. (words((
  432. 'class', 'extends', 'if', 'then', 'super', 'do', 'with',
  433. 'import', 'export', 'while', 'elseif', 'return', 'for', 'in',
  434. 'from', 'when', 'using', 'else', 'and', 'or', 'not', 'switch',
  435. 'break'), suffix=r'\b'),
  436. Keyword),
  437. (r'(true|false|nil)\b', Keyword.Constant),
  438. (r'(and|or|not)\b', Operator.Word),
  439. (r'(self)\b', Name.Builtin.Pseudo),
  440. (r'@@?([a-zA-Z_]\w*)?', Name.Variable.Class),
  441. (r'[A-Z]\w*', Name.Class), # proper name
  442. (words(all_lua_builtins(), suffix=r"\b"), Name.Builtin),
  443. (r'[A-Za-z_]\w*', Name),
  444. ("'", String.Single, combined('stringescape', 'sqs')),
  445. ('"', String.Double, combined('stringescape', 'dqs'))
  446. ],
  447. 'stringescape': [
  448. (r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape)
  449. ],
  450. 'sqs': [
  451. ("'", String.Single, '#pop'),
  452. ("[^']+", String)
  453. ],
  454. 'dqs': [
  455. ('"', String.Double, '#pop'),
  456. ('[^"]+', String)
  457. ]
  458. }
  459. def get_tokens_unprocessed(self, text):
  460. # set . as Operator instead of Punctuation
  461. for index, token, value in LuaLexer.get_tokens_unprocessed(self, text):
  462. if token == Punctuation and value == ".":
  463. token = Operator
  464. yield index, token, value
  465. class ChaiscriptLexer(RegexLexer):
  466. """
  467. For ChaiScript source code.
  468. """
  469. name = 'ChaiScript'
  470. url = 'http://chaiscript.com/'
  471. aliases = ['chaiscript', 'chai']
  472. filenames = ['*.chai']
  473. mimetypes = ['text/x-chaiscript', 'application/x-chaiscript']
  474. version_added = '2.0'
  475. flags = re.DOTALL | re.MULTILINE
  476. tokens = {
  477. 'commentsandwhitespace': [
  478. (r'\s+', Text),
  479. (r'//.*?\n', Comment.Single),
  480. (r'/\*.*?\*/', Comment.Multiline),
  481. (r'^\#.*?\n', Comment.Single)
  482. ],
  483. 'slashstartsregex': [
  484. include('commentsandwhitespace'),
  485. (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
  486. r'([gim]+\b|\B)', String.Regex, '#pop'),
  487. (r'(?=/)', Text, ('#pop', 'badregex')),
  488. default('#pop')
  489. ],
  490. 'badregex': [
  491. (r'\n', Text, '#pop')
  492. ],
  493. 'root': [
  494. include('commentsandwhitespace'),
  495. (r'\n', Text),
  496. (r'[^\S\n]+', Text),
  497. (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|\.\.'
  498. r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
  499. (r'[{(\[;,]', Punctuation, 'slashstartsregex'),
  500. (r'[})\].]', Punctuation),
  501. (r'[=+\-*/]', Operator),
  502. (r'(for|in|while|do|break|return|continue|if|else|'
  503. r'throw|try|catch'
  504. r')\b', Keyword, 'slashstartsregex'),
  505. (r'(var)\b', Keyword.Declaration, 'slashstartsregex'),
  506. (r'(attr|def|fun)\b', Keyword.Reserved),
  507. (r'(true|false)\b', Keyword.Constant),
  508. (r'(eval|throw)\b', Name.Builtin),
  509. (r'`\S+`', Name.Builtin),
  510. (r'[$a-zA-Z_]\w*', Name.Other),
  511. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  512. (r'0x[0-9a-fA-F]+', Number.Hex),
  513. (r'[0-9]+', Number.Integer),
  514. (r'"', String.Double, 'dqstring'),
  515. (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
  516. ],
  517. 'dqstring': [
  518. (r'\$\{[^"}]+?\}', String.Interpol),
  519. (r'\$', String.Double),
  520. (r'\\\\', String.Double),
  521. (r'\\"', String.Double),
  522. (r'[^\\"$]+', String.Double),
  523. (r'"', String.Double, '#pop'),
  524. ],
  525. }
  526. class LSLLexer(RegexLexer):
  527. """
  528. For Second Life's Linden Scripting Language source code.
  529. """
  530. name = 'LSL'
  531. aliases = ['lsl']
  532. filenames = ['*.lsl']
  533. mimetypes = ['text/x-lsl']
  534. url = 'https://wiki.secondlife.com/wiki/Linden_Scripting_Language'
  535. version_added = '2.0'
  536. flags = re.MULTILINE
  537. lsl_keywords = r'\b(?:do|else|for|if|jump|return|while)\b'
  538. lsl_types = r'\b(?:float|integer|key|list|quaternion|rotation|string|vector)\b'
  539. lsl_states = r'\b(?:(?:state)\s+\w+|default)\b'
  540. 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'
  541. 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'
  542. lsl_constants_float = r'\b(?:DEG_TO_RAD|PI(?:_BY_TWO)?|RAD_TO_DEG|SQRT2|TWO_PI)\b'
  543. 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'
  544. lsl_constants_integer_boolean = r'\b(?:FALSE|TRUE)\b'
  545. lsl_constants_rotation = r'\b(?:ZERO_ROTATION)\b'
  546. 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'
  547. lsl_constants_vector = r'\b(?:TOUCH_INVALID_(?:TEXCOORD|VECTOR)|ZERO_VECTOR)\b'
  548. lsl_invalid_broken = r'\b(?:LAND_(?:LARGE|MEDIUM|SMALL)_BRUSH)\b'
  549. 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'
  550. lsl_invalid_illegal = r'\b(?:event)\b'
  551. 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'
  552. lsl_reserved_godmode = r'\b(?:ll(?:GodLikeRezObject|Set(?:Inventory|Object)PermMask))\b'
  553. lsl_reserved_log = r'\b(?:print)\b'
  554. lsl_operators = r'\+\+|\-\-|<<|>>|&&?|\|\|?|\^|~|[!%<>=*+\-/]=?'
  555. tokens = {
  556. 'root':
  557. [
  558. (r'//.*?\n', Comment.Single),
  559. (r'/\*', Comment.Multiline, 'comment'),
  560. (r'"', String.Double, 'string'),
  561. (lsl_keywords, Keyword),
  562. (lsl_types, Keyword.Type),
  563. (lsl_states, Name.Class),
  564. (lsl_events, Name.Builtin),
  565. (lsl_functions_builtin, Name.Function),
  566. (lsl_constants_float, Keyword.Constant),
  567. (lsl_constants_integer, Keyword.Constant),
  568. (lsl_constants_integer_boolean, Keyword.Constant),
  569. (lsl_constants_rotation, Keyword.Constant),
  570. (lsl_constants_string, Keyword.Constant),
  571. (lsl_constants_vector, Keyword.Constant),
  572. (lsl_invalid_broken, Error),
  573. (lsl_invalid_deprecated, Error),
  574. (lsl_invalid_illegal, Error),
  575. (lsl_invalid_unimplemented, Error),
  576. (lsl_reserved_godmode, Keyword.Reserved),
  577. (lsl_reserved_log, Keyword.Reserved),
  578. (r'\b([a-zA-Z_]\w*)\b', Name.Variable),
  579. (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d*', Number.Float),
  580. (r'(\d+\.\d*|\.\d+)', Number.Float),
  581. (r'0[xX][0-9a-fA-F]+', Number.Hex),
  582. (r'\d+', Number.Integer),
  583. (lsl_operators, Operator),
  584. (r':=?', Error),
  585. (r'[,;{}()\[\]]', Punctuation),
  586. (r'\n+', Whitespace),
  587. (r'\s+', Whitespace)
  588. ],
  589. 'comment':
  590. [
  591. (r'[^*/]+', Comment.Multiline),
  592. (r'/\*', Comment.Multiline, '#push'),
  593. (r'\*/', Comment.Multiline, '#pop'),
  594. (r'[*/]', Comment.Multiline)
  595. ],
  596. 'string':
  597. [
  598. (r'\\([nt"\\])', String.Escape),
  599. (r'"', String.Double, '#pop'),
  600. (r'\\.', Error),
  601. (r'[^"\\]+', String.Double),
  602. ]
  603. }
  604. class AppleScriptLexer(RegexLexer):
  605. """
  606. For AppleScript source code,
  607. including `AppleScript Studio
  608. <http://developer.apple.com/documentation/AppleScript/
  609. Reference/StudioReference>`_.
  610. Contributed by Andreas Amann <aamann@mac.com>.
  611. """
  612. name = 'AppleScript'
  613. url = 'https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html'
  614. aliases = ['applescript']
  615. filenames = ['*.applescript']
  616. version_added = '1.0'
  617. flags = re.MULTILINE | re.DOTALL
  618. Identifiers = r'[a-zA-Z]\w*'
  619. # XXX: use words() for all of these
  620. Literals = ('AppleScript', 'current application', 'false', 'linefeed',
  621. 'missing value', 'pi', 'quote', 'result', 'return', 'space',
  622. 'tab', 'text item delimiters', 'true', 'version')
  623. Classes = ('alias ', 'application ', 'boolean ', 'class ', 'constant ',
  624. 'date ', 'file ', 'integer ', 'list ', 'number ', 'POSIX file ',
  625. 'real ', 'record ', 'reference ', 'RGB color ', 'script ',
  626. 'text ', 'unit types', '(?:Unicode )?text', 'string')
  627. BuiltIn = ('attachment', 'attribute run', 'character', 'day', 'month',
  628. 'paragraph', 'word', 'year')
  629. HandlerParams = ('about', 'above', 'against', 'apart from', 'around',
  630. 'aside from', 'at', 'below', 'beneath', 'beside',
  631. 'between', 'for', 'given', 'instead of', 'on', 'onto',
  632. 'out of', 'over', 'since')
  633. Commands = ('ASCII (character|number)', 'activate', 'beep', 'choose URL',
  634. 'choose application', 'choose color', 'choose file( name)?',
  635. 'choose folder', 'choose from list',
  636. 'choose remote application', 'clipboard info',
  637. 'close( access)?', 'copy', 'count', 'current date', 'delay',
  638. 'delete', 'display (alert|dialog)', 'do shell script',
  639. 'duplicate', 'exists', 'get eof', 'get volume settings',
  640. 'info for', 'launch', 'list (disks|folder)', 'load script',
  641. 'log', 'make', 'mount volume', 'new', 'offset',
  642. 'open( (for access|location))?', 'path to', 'print', 'quit',
  643. 'random number', 'read', 'round', 'run( script)?',
  644. 'say', 'scripting components',
  645. 'set (eof|the clipboard to|volume)', 'store script',
  646. 'summarize', 'system attribute', 'system info',
  647. 'the clipboard', 'time to GMT', 'write', 'quoted form')
  648. References = ('(in )?back of', '(in )?front of', '[0-9]+(st|nd|rd|th)',
  649. 'first', 'second', 'third', 'fourth', 'fifth', 'sixth',
  650. 'seventh', 'eighth', 'ninth', 'tenth', 'after', 'back',
  651. 'before', 'behind', 'every', 'front', 'index', 'last',
  652. 'middle', 'some', 'that', 'through', 'thru', 'where', 'whose')
  653. Operators = ("and", "or", "is equal", "equals", "(is )?equal to", "is not",
  654. "isn't", "isn't equal( to)?", "is not equal( to)?",
  655. "doesn't equal", "does not equal", "(is )?greater than",
  656. "comes after", "is not less than or equal( to)?",
  657. "isn't less than or equal( to)?", "(is )?less than",
  658. "comes before", "is not greater than or equal( to)?",
  659. "isn't greater than or equal( to)?",
  660. "(is )?greater than or equal( to)?", "is not less than",
  661. "isn't less than", "does not come before",
  662. "doesn't come before", "(is )?less than or equal( to)?",
  663. "is not greater than", "isn't greater than",
  664. "does not come after", "doesn't come after", "starts? with",
  665. "begins? with", "ends? with", "contains?", "does not contain",
  666. "doesn't contain", "is in", "is contained by", "is not in",
  667. "is not contained by", "isn't contained by", "div", "mod",
  668. "not", "(a )?(ref( to)?|reference to)", "is", "does")
  669. Control = ('considering', 'else', 'error', 'exit', 'from', 'if',
  670. 'ignoring', 'in', 'repeat', 'tell', 'then', 'times', 'to',
  671. 'try', 'until', 'using terms from', 'while', 'whith',
  672. 'with timeout( of)?', 'with transaction', 'by', 'continue',
  673. 'end', 'its?', 'me', 'my', 'return', 'of', 'as')
  674. Declarations = ('global', 'local', 'prop(erty)?', 'set', 'get')
  675. Reserved = ('but', 'put', 'returning', 'the')
  676. StudioClasses = ('action cell', 'alert reply', 'application', 'box',
  677. 'browser( cell)?', 'bundle', 'button( cell)?', 'cell',
  678. 'clip view', 'color well', 'color-panel',
  679. 'combo box( item)?', 'control',
  680. 'data( (cell|column|item|row|source))?', 'default entry',
  681. 'dialog reply', 'document', 'drag info', 'drawer',
  682. 'event', 'font(-panel)?', 'formatter',
  683. 'image( (cell|view))?', 'matrix', 'menu( item)?', 'item',
  684. 'movie( view)?', 'open-panel', 'outline view', 'panel',
  685. 'pasteboard', 'plugin', 'popup button',
  686. 'progress indicator', 'responder', 'save-panel',
  687. 'scroll view', 'secure text field( cell)?', 'slider',
  688. 'sound', 'split view', 'stepper', 'tab view( item)?',
  689. 'table( (column|header cell|header view|view))',
  690. 'text( (field( cell)?|view))?', 'toolbar( item)?',
  691. 'user-defaults', 'view', 'window')
  692. StudioEvents = ('accept outline drop', 'accept table drop', 'action',
  693. 'activated', 'alert ended', 'awake from nib', 'became key',
  694. 'became main', 'begin editing', 'bounds changed',
  695. 'cell value', 'cell value changed', 'change cell value',
  696. 'change item value', 'changed', 'child of item',
  697. 'choose menu item', 'clicked', 'clicked toolbar item',
  698. 'closed', 'column clicked', 'column moved',
  699. 'column resized', 'conclude drop', 'data representation',
  700. 'deminiaturized', 'dialog ended', 'document nib name',
  701. 'double clicked', 'drag( (entered|exited|updated))?',
  702. 'drop', 'end editing', 'exposed', 'idle', 'item expandable',
  703. 'item value', 'item value changed', 'items changed',
  704. 'keyboard down', 'keyboard up', 'launched',
  705. 'load data representation', 'miniaturized', 'mouse down',
  706. 'mouse dragged', 'mouse entered', 'mouse exited',
  707. 'mouse moved', 'mouse up', 'moved',
  708. 'number of browser rows', 'number of items',
  709. 'number of rows', 'open untitled', 'opened', 'panel ended',
  710. 'parameters updated', 'plugin loaded', 'prepare drop',
  711. 'prepare outline drag', 'prepare outline drop',
  712. 'prepare table drag', 'prepare table drop',
  713. 'read from file', 'resigned active', 'resigned key',
  714. 'resigned main', 'resized( sub views)?',
  715. 'right mouse down', 'right mouse dragged',
  716. 'right mouse up', 'rows changed', 'scroll wheel',
  717. 'selected tab view item', 'selection changed',
  718. 'selection changing', 'should begin editing',
  719. 'should close', 'should collapse item',
  720. 'should end editing', 'should expand item',
  721. 'should open( untitled)?',
  722. 'should quit( after last window closed)?',
  723. 'should select column', 'should select item',
  724. 'should select row', 'should select tab view item',
  725. 'should selection change', 'should zoom', 'shown',
  726. 'update menu item', 'update parameters',
  727. 'update toolbar item', 'was hidden', 'was miniaturized',
  728. 'will become active', 'will close', 'will dismiss',
  729. 'will display browser cell', 'will display cell',
  730. 'will display item cell', 'will display outline cell',
  731. 'will finish launching', 'will hide', 'will miniaturize',
  732. 'will move', 'will open', 'will pop up', 'will quit',
  733. 'will resign active', 'will resize( sub views)?',
  734. 'will select tab view item', 'will show', 'will zoom',
  735. 'write to file', 'zoomed')
  736. StudioCommands = ('animate', 'append', 'call method', 'center',
  737. 'close drawer', 'close panel', 'display',
  738. 'display alert', 'display dialog', 'display panel', 'go',
  739. 'hide', 'highlight', 'increment', 'item for',
  740. 'load image', 'load movie', 'load nib', 'load panel',
  741. 'load sound', 'localized string', 'lock focus', 'log',
  742. 'open drawer', 'path for', 'pause', 'perform action',
  743. 'play', 'register', 'resume', 'scroll', 'select( all)?',
  744. 'show', 'size to fit', 'start', 'step back',
  745. 'step forward', 'stop', 'synchronize', 'unlock focus',
  746. 'update')
  747. StudioProperties = ('accepts arrow key', 'action method', 'active',
  748. 'alignment', 'allowed identifiers',
  749. 'allows branch selection', 'allows column reordering',
  750. 'allows column resizing', 'allows column selection',
  751. 'allows customization',
  752. 'allows editing text attributes',
  753. 'allows empty selection', 'allows mixed state',
  754. 'allows multiple selection', 'allows reordering',
  755. 'allows undo', 'alpha( value)?', 'alternate image',
  756. 'alternate increment value', 'alternate title',
  757. 'animation delay', 'associated file name',
  758. 'associated object', 'auto completes', 'auto display',
  759. 'auto enables items', 'auto repeat',
  760. 'auto resizes( outline column)?',
  761. 'auto save expanded items', 'auto save name',
  762. 'auto save table columns', 'auto saves configuration',
  763. 'auto scroll', 'auto sizes all columns to fit',
  764. 'auto sizes cells', 'background color', 'bezel state',
  765. 'bezel style', 'bezeled', 'border rect', 'border type',
  766. 'bordered', 'bounds( rotation)?', 'box type',
  767. 'button returned', 'button type',
  768. 'can choose directories', 'can choose files',
  769. 'can draw', 'can hide',
  770. 'cell( (background color|size|type))?', 'characters',
  771. 'class', 'click count', 'clicked( data)? column',
  772. 'clicked data item', 'clicked( data)? row',
  773. 'closeable', 'collating', 'color( (mode|panel))',
  774. 'command key down', 'configuration',
  775. 'content(s| (size|view( margins)?))?', 'context',
  776. 'continuous', 'control key down', 'control size',
  777. 'control tint', 'control view',
  778. 'controller visible', 'coordinate system',
  779. 'copies( on scroll)?', 'corner view', 'current cell',
  780. 'current column', 'current( field)? editor',
  781. 'current( menu)? item', 'current row',
  782. 'current tab view item', 'data source',
  783. 'default identifiers', 'delta (x|y|z)',
  784. 'destination window', 'directory', 'display mode',
  785. 'displayed cell', 'document( (edited|rect|view))?',
  786. 'double value', 'dragged column', 'dragged distance',
  787. 'dragged items', 'draws( cell)? background',
  788. 'draws grid', 'dynamically scrolls', 'echos bullets',
  789. 'edge', 'editable', 'edited( data)? column',
  790. 'edited data item', 'edited( data)? row', 'enabled',
  791. 'enclosing scroll view', 'ending page',
  792. 'error handling', 'event number', 'event type',
  793. 'excluded from windows menu', 'executable path',
  794. 'expanded', 'fax number', 'field editor', 'file kind',
  795. 'file name', 'file type', 'first responder',
  796. 'first visible column', 'flipped', 'floating',
  797. 'font( panel)?', 'formatter', 'frameworks path',
  798. 'frontmost', 'gave up', 'grid color', 'has data items',
  799. 'has horizontal ruler', 'has horizontal scroller',
  800. 'has parent data item', 'has resize indicator',
  801. 'has shadow', 'has sub menu', 'has vertical ruler',
  802. 'has vertical scroller', 'header cell', 'header view',
  803. 'hidden', 'hides when deactivated', 'highlights by',
  804. 'horizontal line scroll', 'horizontal page scroll',
  805. 'horizontal ruler view', 'horizontally resizable',
  806. 'icon image', 'id', 'identifier',
  807. 'ignores multiple clicks',
  808. 'image( (alignment|dims when disabled|frame style|scaling))?',
  809. 'imports graphics', 'increment value',
  810. 'indentation per level', 'indeterminate', 'index',
  811. 'integer value', 'intercell spacing', 'item height',
  812. 'key( (code|equivalent( modifier)?|window))?',
  813. 'knob thickness', 'label', 'last( visible)? column',
  814. 'leading offset', 'leaf', 'level', 'line scroll',
  815. 'loaded', 'localized sort', 'location', 'loop mode',
  816. 'main( (bunde|menu|window))?', 'marker follows cell',
  817. 'matrix mode', 'maximum( content)? size',
  818. 'maximum visible columns',
  819. 'menu( form representation)?', 'miniaturizable',
  820. 'miniaturized', 'minimized image', 'minimized title',
  821. 'minimum column width', 'minimum( content)? size',
  822. 'modal', 'modified', 'mouse down state',
  823. 'movie( (controller|file|rect))?', 'muted', 'name',
  824. 'needs display', 'next state', 'next text',
  825. 'number of tick marks', 'only tick mark values',
  826. 'opaque', 'open panel', 'option key down',
  827. 'outline table column', 'page scroll', 'pages across',
  828. 'pages down', 'palette label', 'pane splitter',
  829. 'parent data item', 'parent window', 'pasteboard',
  830. 'path( (names|separator))?', 'playing',
  831. 'plays every frame', 'plays selection only', 'position',
  832. 'preferred edge', 'preferred type', 'pressure',
  833. 'previous text', 'prompt', 'properties',
  834. 'prototype cell', 'pulls down', 'rate',
  835. 'released when closed', 'repeated',
  836. 'requested print time', 'required file type',
  837. 'resizable', 'resized column', 'resource path',
  838. 'returns records', 'reuses columns', 'rich text',
  839. 'roll over', 'row height', 'rulers visible',
  840. 'save panel', 'scripts path', 'scrollable',
  841. 'selectable( identifiers)?', 'selected cell',
  842. 'selected( data)? columns?', 'selected data items?',
  843. 'selected( data)? rows?', 'selected item identifier',
  844. 'selection by rect', 'send action on arrow key',
  845. 'sends action when done editing', 'separates columns',
  846. 'separator item', 'sequence number', 'services menu',
  847. 'shared frameworks path', 'shared support path',
  848. 'sheet', 'shift key down', 'shows alpha',
  849. 'shows state by', 'size( mode)?',
  850. 'smart insert delete enabled', 'sort case sensitivity',
  851. 'sort column', 'sort order', 'sort type',
  852. 'sorted( data rows)?', 'sound', 'source( mask)?',
  853. 'spell checking enabled', 'starting page', 'state',
  854. 'string value', 'sub menu', 'super menu', 'super view',
  855. 'tab key traverses cells', 'tab state', 'tab type',
  856. 'tab view', 'table view', 'tag', 'target( printer)?',
  857. 'text color', 'text container insert',
  858. 'text container origin', 'text returned',
  859. 'tick mark position', 'time stamp',
  860. 'title(d| (cell|font|height|position|rect))?',
  861. 'tool tip', 'toolbar', 'trailing offset', 'transparent',
  862. 'treat packages as directories', 'truncated labels',
  863. 'types', 'unmodified characters', 'update views',
  864. 'use sort indicator', 'user defaults',
  865. 'uses data source', 'uses ruler',
  866. 'uses threaded animation',
  867. 'uses title from previous column', 'value wraps',
  868. 'version',
  869. 'vertical( (line scroll|page scroll|ruler view))?',
  870. 'vertically resizable', 'view',
  871. 'visible( document rect)?', 'volume', 'width', 'window',
  872. 'windows menu', 'wraps', 'zoomable', 'zoomed')
  873. tokens = {
  874. 'root': [
  875. (r'\s+', Text),
  876. (r'¬\n', String.Escape),
  877. (r"'s\s+", Text), # This is a possessive, consider moving
  878. (r'(--|#).*?$', Comment),
  879. (r'\(\*', Comment.Multiline, 'comment'),
  880. (r'[(){}!,.:]', Punctuation),
  881. (r'(«)([^»]+)(»)',
  882. bygroups(Text, Name.Builtin, Text)),
  883. (r'\b((?:considering|ignoring)\s*)'
  884. r'(application responses|case|diacriticals|hyphens|'
  885. r'numeric strings|punctuation|white space)',
  886. bygroups(Keyword, Name.Builtin)),
  887. (r'(-|\*|\+|&|≠|>=?|<=?|=|≥|≤|/|÷|\^)', Operator),
  888. (r"\b({})\b".format('|'.join(Operators)), Operator.Word),
  889. (r'^(\s*(?:on|end)\s+)'
  890. r'({})'.format('|'.join(StudioEvents[::-1])),
  891. bygroups(Keyword, Name.Function)),
  892. (r'^(\s*)(in|on|script|to)(\s+)', bygroups(Text, Keyword, Text)),
  893. (r'\b(as )({})\b'.format('|'.join(Classes)),
  894. bygroups(Keyword, Name.Class)),
  895. (r'\b({})\b'.format('|'.join(Literals)), Name.Constant),
  896. (r'\b({})\b'.format('|'.join(Commands)), Name.Builtin),
  897. (r'\b({})\b'.format('|'.join(Control)), Keyword),
  898. (r'\b({})\b'.format('|'.join(Declarations)), Keyword),
  899. (r'\b({})\b'.format('|'.join(Reserved)), Name.Builtin),
  900. (r'\b({})s?\b'.format('|'.join(BuiltIn)), Name.Builtin),
  901. (r'\b({})\b'.format('|'.join(HandlerParams)), Name.Builtin),
  902. (r'\b({})\b'.format('|'.join(StudioProperties)), Name.Attribute),
  903. (r'\b({})s?\b'.format('|'.join(StudioClasses)), Name.Builtin),
  904. (r'\b({})\b'.format('|'.join(StudioCommands)), Name.Builtin),
  905. (r'\b({})\b'.format('|'.join(References)), Name.Builtin),
  906. (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
  907. (rf'\b({Identifiers})\b', Name.Variable),
  908. (r'[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?', Number.Float),
  909. (r'[-+]?\d+', Number.Integer),
  910. ],
  911. 'comment': [
  912. (r'\(\*', Comment.Multiline, '#push'),
  913. (r'\*\)', Comment.Multiline, '#pop'),
  914. ('[^*(]+', Comment.Multiline),
  915. ('[*(]', Comment.Multiline),
  916. ],
  917. }
  918. class RexxLexer(RegexLexer):
  919. """
  920. Rexx is a scripting language available for
  921. a wide range of different platforms with its roots found on mainframe
  922. systems. It is popular for I/O- and data based tasks and can act as glue
  923. language to bind different applications together.
  924. """
  925. name = 'Rexx'
  926. url = 'http://www.rexxinfo.org/'
  927. aliases = ['rexx', 'arexx']
  928. filenames = ['*.rexx', '*.rex', '*.rx', '*.arexx']
  929. mimetypes = ['text/x-rexx']
  930. version_added = '2.0'
  931. flags = re.IGNORECASE
  932. tokens = {
  933. 'root': [
  934. (r'\s+', Whitespace),
  935. (r'/\*', Comment.Multiline, 'comment'),
  936. (r'"', String, 'string_double'),
  937. (r"'", String, 'string_single'),
  938. (r'[0-9]+(\.[0-9]+)?(e[+-]?[0-9])?', Number),
  939. (r'([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b',
  940. bygroups(Name.Function, Whitespace, Operator, Whitespace,
  941. Keyword.Declaration)),
  942. (r'([a-z_]\w*)(\s*)(:)',
  943. bygroups(Name.Label, Whitespace, Operator)),
  944. include('function'),
  945. include('keyword'),
  946. include('operator'),
  947. (r'[a-z_]\w*', Text),
  948. ],
  949. 'function': [
  950. (words((
  951. 'abbrev', 'abs', 'address', 'arg', 'b2x', 'bitand', 'bitor', 'bitxor',
  952. 'c2d', 'c2x', 'center', 'charin', 'charout', 'chars', 'compare',
  953. 'condition', 'copies', 'd2c', 'd2x', 'datatype', 'date', 'delstr',
  954. 'delword', 'digits', 'errortext', 'form', 'format', 'fuzz', 'insert',
  955. 'lastpos', 'left', 'length', 'linein', 'lineout', 'lines', 'max',
  956. 'min', 'overlay', 'pos', 'queued', 'random', 'reverse', 'right', 'sign',
  957. 'sourceline', 'space', 'stream', 'strip', 'substr', 'subword', 'symbol',
  958. 'time', 'trace', 'translate', 'trunc', 'value', 'verify', 'word',
  959. 'wordindex', 'wordlength', 'wordpos', 'words', 'x2b', 'x2c', 'x2d',
  960. 'xrange'), suffix=r'(\s*)(\()'),
  961. bygroups(Name.Builtin, Whitespace, Operator)),
  962. ],
  963. 'keyword': [
  964. (r'(address|arg|by|call|do|drop|else|end|exit|for|forever|if|'
  965. r'interpret|iterate|leave|nop|numeric|off|on|options|parse|'
  966. r'pull|push|queue|return|say|select|signal|to|then|trace|until|'
  967. r'while)\b', Keyword.Reserved),
  968. ],
  969. 'operator': [
  970. (r'(-|//|/|\(|\)|\*\*|\*|\\<<|\\<|\\==|\\=|\\>>|\\>|\\|\|\||\||'
  971. r'&&|&|%|\+|<<=|<<|<=|<>|<|==|=|><|>=|>>=|>>|>|¬<<|¬<|¬==|¬=|'
  972. r'¬>>|¬>|¬|\.|,)', Operator),
  973. ],
  974. 'string_double': [
  975. (r'[^"\n]+', String),
  976. (r'""', String),
  977. (r'"', String, '#pop'),
  978. (r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
  979. ],
  980. 'string_single': [
  981. (r'[^\'\n]+', String),
  982. (r'\'\'', String),
  983. (r'\'', String, '#pop'),
  984. (r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
  985. ],
  986. 'comment': [
  987. (r'[^*]+', Comment.Multiline),
  988. (r'\*/', Comment.Multiline, '#pop'),
  989. (r'\*', Comment.Multiline),
  990. ]
  991. }
  992. def _c(s):
  993. return re.compile(s, re.MULTILINE)
  994. _ADDRESS_COMMAND_PATTERN = _c(r'^\s*address\s+command\b')
  995. _ADDRESS_PATTERN = _c(r'^\s*address\s+')
  996. _DO_WHILE_PATTERN = _c(r'^\s*do\s+while\b')
  997. _IF_THEN_DO_PATTERN = _c(r'^\s*if\b.+\bthen\s+do\s*$')
  998. _PROCEDURE_PATTERN = _c(r'^\s*([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b')
  999. _ELSE_DO_PATTERN = _c(r'\belse\s+do\s*$')
  1000. _PARSE_ARG_PATTERN = _c(r'^\s*parse\s+(upper\s+)?(arg|value)\b')
  1001. PATTERNS_AND_WEIGHTS = (
  1002. (_ADDRESS_COMMAND_PATTERN, 0.2),
  1003. (_ADDRESS_PATTERN, 0.05),
  1004. (_DO_WHILE_PATTERN, 0.1),
  1005. (_ELSE_DO_PATTERN, 0.1),
  1006. (_IF_THEN_DO_PATTERN, 0.1),
  1007. (_PROCEDURE_PATTERN, 0.5),
  1008. (_PARSE_ARG_PATTERN, 0.2),
  1009. )
  1010. def analyse_text(text):
  1011. """
  1012. Check for initial comment and patterns that distinguish Rexx from other
  1013. C-like languages.
  1014. """
  1015. if re.search(r'/\*\**\s*rexx', text, re.IGNORECASE):
  1016. # Header matches MVS Rexx requirements, this is certainly a Rexx
  1017. # script.
  1018. return 1.0
  1019. elif text.startswith('/*'):
  1020. # Header matches general Rexx requirements; the source code might
  1021. # still be any language using C comments such as C++, C# or Java.
  1022. lowerText = text.lower()
  1023. result = sum(weight
  1024. for (pattern, weight) in RexxLexer.PATTERNS_AND_WEIGHTS
  1025. if pattern.search(lowerText)) + 0.01
  1026. return min(result, 1.0)
  1027. class MOOCodeLexer(RegexLexer):
  1028. """
  1029. For MOOCode (the MOO scripting language).
  1030. """
  1031. name = 'MOOCode'
  1032. url = 'http://www.moo.mud.org/'
  1033. filenames = ['*.moo']
  1034. aliases = ['moocode', 'moo']
  1035. mimetypes = ['text/x-moocode']
  1036. version_added = '0.9'
  1037. tokens = {
  1038. 'root': [
  1039. # Numbers
  1040. (r'(0|[1-9][0-9_]*)', Number.Integer),
  1041. # Strings
  1042. (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
  1043. # exceptions
  1044. (r'(E_PERM|E_DIV)', Name.Exception),
  1045. # db-refs
  1046. (r'((#[-0-9]+)|(\$\w+))', Name.Entity),
  1047. # Keywords
  1048. (r'\b(if|else|elseif|endif|for|endfor|fork|endfork|while'
  1049. r'|endwhile|break|continue|return|try'
  1050. r'|except|endtry|finally|in)\b', Keyword),
  1051. # builtins
  1052. (r'(random|length)', Name.Builtin),
  1053. # special variables
  1054. (r'(player|caller|this|args)', Name.Variable.Instance),
  1055. # skip whitespace
  1056. (r'\s+', Text),
  1057. (r'\n', Text),
  1058. # other operators
  1059. (r'([!;=,{}&|:.\[\]@()<>?]+)', Operator),
  1060. # function call
  1061. (r'(\w+)(\()', bygroups(Name.Function, Operator)),
  1062. # variables
  1063. (r'(\w+)', Text),
  1064. ]
  1065. }
  1066. class HybrisLexer(RegexLexer):
  1067. """
  1068. For Hybris source code.
  1069. """
  1070. name = 'Hybris'
  1071. aliases = ['hybris']
  1072. filenames = ['*.hyb']
  1073. mimetypes = ['text/x-hybris', 'application/x-hybris']
  1074. url = 'https://github.com/evilsocket/hybris'
  1075. version_added = '1.4'
  1076. flags = re.MULTILINE | re.DOTALL
  1077. tokens = {
  1078. 'root': [
  1079. # method names
  1080. (r'^(\s*(?:function|method|operator\s+)+?)'
  1081. r'([a-zA-Z_]\w*)'
  1082. r'(\s*)(\()', bygroups(Keyword, Name.Function, Text, Operator)),
  1083. (r'[^\S\n]+', Text),
  1084. (r'//.*?\n', Comment.Single),
  1085. (r'/\*.*?\*/', Comment.Multiline),
  1086. (r'@[a-zA-Z_][\w.]*', Name.Decorator),
  1087. (r'(break|case|catch|next|default|do|else|finally|for|foreach|of|'
  1088. r'unless|if|new|return|switch|me|throw|try|while)\b', Keyword),
  1089. (r'(extends|private|protected|public|static|throws|function|method|'
  1090. r'operator)\b', Keyword.Declaration),
  1091. (r'(true|false|null|__FILE__|__LINE__|__VERSION__|__LIB_PATH__|'
  1092. r'__INC_PATH__)\b', Keyword.Constant),
  1093. (r'(class|struct)(\s+)',
  1094. bygroups(Keyword.Declaration, Text), 'class'),
  1095. (r'(import|include)(\s+)',
  1096. bygroups(Keyword.Namespace, Text), 'import'),
  1097. (words((
  1098. 'gc_collect', 'gc_mm_items', 'gc_mm_usage', 'gc_collect_threshold',
  1099. 'urlencode', 'urldecode', 'base64encode', 'base64decode', 'sha1', 'crc32',
  1100. 'sha2', 'md5', 'md5_file', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos',
  1101. 'cosh', 'exp', 'fabs', 'floor', 'fmod', 'log', 'log10', 'pow', 'sin',
  1102. 'sinh', 'sqrt', 'tan', 'tanh', 'isint', 'isfloat', 'ischar', 'isstring',
  1103. 'isarray', 'ismap', 'isalias', 'typeof', 'sizeof', 'toint', 'tostring',
  1104. 'fromxml', 'toxml', 'binary', 'pack', 'load', 'eval', 'var_names',
  1105. 'var_values', 'user_functions', 'dyn_functions', 'methods', 'call',
  1106. 'call_method', 'mknod', 'mkfifo', 'mount', 'umount2', 'umount', 'ticks',
  1107. 'usleep', 'sleep', 'time', 'strtime', 'strdate', 'dllopen', 'dlllink',
  1108. 'dllcall', 'dllcall_argv', 'dllclose', 'env', 'exec', 'fork', 'getpid',
  1109. 'wait', 'popen', 'pclose', 'exit', 'kill', 'pthread_create',
  1110. 'pthread_create_argv', 'pthread_exit', 'pthread_join', 'pthread_kill',
  1111. 'smtp_send', 'http_get', 'http_post', 'http_download', 'socket', 'bind',
  1112. 'listen', 'accept', 'getsockname', 'getpeername', 'settimeout', 'connect',
  1113. 'server', 'recv', 'send', 'close', 'print', 'println', 'printf', 'input',
  1114. 'readline', 'serial_open', 'serial_fcntl', 'serial_get_attr',
  1115. 'serial_get_ispeed', 'serial_get_ospeed', 'serial_set_attr',
  1116. 'serial_set_ispeed', 'serial_set_ospeed', 'serial_write', 'serial_read',
  1117. 'serial_close', 'xml_load', 'xml_parse', 'fopen', 'fseek', 'ftell',
  1118. 'fsize', 'fread', 'fwrite', 'fgets', 'fclose', 'file', 'readdir',
  1119. 'pcre_replace', 'size', 'pop', 'unmap', 'has', 'keys', 'values',
  1120. 'length', 'find', 'substr', 'replace', 'split', 'trim', 'remove',
  1121. 'contains', 'join'), suffix=r'\b'),
  1122. Name.Builtin),
  1123. (words((
  1124. 'MethodReference', 'Runner', 'Dll', 'Thread', 'Pipe', 'Process',
  1125. 'Runnable', 'CGI', 'ClientSocket', 'Socket', 'ServerSocket',
  1126. 'File', 'Console', 'Directory', 'Exception'), suffix=r'\b'),
  1127. Keyword.Type),
  1128. (r'"(\\\\|\\[^\\]|[^"\\])*"', String),
  1129. (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
  1130. (r'(\.)([a-zA-Z_]\w*)',
  1131. bygroups(Operator, Name.Attribute)),
  1132. (r'[a-zA-Z_]\w*:', Name.Label),
  1133. (r'[a-zA-Z_$]\w*', Name),
  1134. (r'[~^*!%&\[\](){}<>|+=:;,./?\-@]+', Operator),
  1135. (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
  1136. (r'0x[0-9a-f]+', Number.Hex),
  1137. (r'[0-9]+L?', Number.Integer),
  1138. (r'\n', Text),
  1139. ],
  1140. 'class': [
  1141. (r'[a-zA-Z_]\w*', Name.Class, '#pop')
  1142. ],
  1143. 'import': [
  1144. (r'[\w.]+\*?', Name.Namespace, '#pop')
  1145. ],
  1146. }
  1147. def analyse_text(text):
  1148. """public method and private method don't seem to be quite common
  1149. elsewhere."""
  1150. result = 0
  1151. if re.search(r'\b(?:public|private)\s+method\b', text):
  1152. result += 0.01
  1153. return result
  1154. class EasytrieveLexer(RegexLexer):
  1155. """
  1156. Easytrieve Plus is a programming language for extracting, filtering and
  1157. converting sequential data. Furthermore it can layout data for reports.
  1158. It is mainly used on mainframe platforms and can access several of the
  1159. mainframe's native file formats. It is somewhat comparable to awk.
  1160. """
  1161. name = 'Easytrieve'
  1162. aliases = ['easytrieve']
  1163. filenames = ['*.ezt', '*.mac']
  1164. mimetypes = ['text/x-easytrieve']
  1165. url = 'https://www.broadcom.com/products/mainframe/application-development/easytrieve-report-generator'
  1166. version_added = '2.1'
  1167. flags = 0
  1168. # Note: We cannot use r'\b' at the start and end of keywords because
  1169. # Easytrieve Plus delimiter characters are:
  1170. #
  1171. # * space ( )
  1172. # * apostrophe (')
  1173. # * period (.)
  1174. # * comma (,)
  1175. # * parenthesis ( and )
  1176. # * colon (:)
  1177. #
  1178. # Additionally words end once a '*' appears, indicatins a comment.
  1179. _DELIMITERS = r' \'.,():\n'
  1180. _DELIMITERS_OR_COMENT = _DELIMITERS + '*'
  1181. _DELIMITER_PATTERN = '[' + _DELIMITERS + ']'
  1182. _DELIMITER_PATTERN_CAPTURE = '(' + _DELIMITER_PATTERN + ')'
  1183. _NON_DELIMITER_OR_COMMENT_PATTERN = '[^' + _DELIMITERS_OR_COMENT + ']'
  1184. _OPERATORS_PATTERN = '[.+\\-/=\\[\\](){}<>;,&%¬]'
  1185. _KEYWORDS = [
  1186. 'AFTER-BREAK', 'AFTER-LINE', 'AFTER-SCREEN', 'AIM', 'AND', 'ATTR',
  1187. 'BEFORE', 'BEFORE-BREAK', 'BEFORE-LINE', 'BEFORE-SCREEN', 'BUSHU',
  1188. 'BY', 'CALL', 'CASE', 'CHECKPOINT', 'CHKP', 'CHKP-STATUS', 'CLEAR',
  1189. 'CLOSE', 'COL', 'COLOR', 'COMMIT', 'CONTROL', 'COPY', 'CURSOR', 'D',
  1190. 'DECLARE', 'DEFAULT', 'DEFINE', 'DELETE', 'DENWA', 'DISPLAY', 'DLI',
  1191. 'DO', 'DUPLICATE', 'E', 'ELSE', 'ELSE-IF', 'END', 'END-CASE',
  1192. 'END-DO', 'END-IF', 'END-PROC', 'ENDPAGE', 'ENDTABLE', 'ENTER', 'EOF',
  1193. 'EQ', 'ERROR', 'EXIT', 'EXTERNAL', 'EZLIB', 'F1', 'F10', 'F11', 'F12',
  1194. 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F2', 'F20', 'F21',
  1195. 'F22', 'F23', 'F24', 'F25', 'F26', 'F27', 'F28', 'F29', 'F3', 'F30',
  1196. 'F31', 'F32', 'F33', 'F34', 'F35', 'F36', 'F4', 'F5', 'F6', 'F7',
  1197. 'F8', 'F9', 'FETCH', 'FILE-STATUS', 'FILL', 'FINAL', 'FIRST',
  1198. 'FIRST-DUP', 'FOR', 'GE', 'GET', 'GO', 'GOTO', 'GQ', 'GR', 'GT',
  1199. 'HEADING', 'HEX', 'HIGH-VALUES', 'IDD', 'IDMS', 'IF', 'IN', 'INSERT',
  1200. 'JUSTIFY', 'KANJI-DATE', 'KANJI-DATE-LONG', 'KANJI-TIME', 'KEY',
  1201. 'KEY-PRESSED', 'KOKUGO', 'KUN', 'LAST-DUP', 'LE', 'LEVEL', 'LIKE',
  1202. 'LINE', 'LINE-COUNT', 'LINE-NUMBER', 'LINK', 'LIST', 'LOW-VALUES',
  1203. 'LQ', 'LS', 'LT', 'MACRO', 'MASK', 'MATCHED', 'MEND', 'MESSAGE',
  1204. 'MOVE', 'MSTART', 'NE', 'NEWPAGE', 'NOMASK', 'NOPRINT', 'NOT',
  1205. 'NOTE', 'NOVERIFY', 'NQ', 'NULL', 'OF', 'OR', 'OTHERWISE', 'PA1',
  1206. 'PA2', 'PA3', 'PAGE-COUNT', 'PAGE-NUMBER', 'PARM-REGISTER',
  1207. 'PATH-ID', 'PATTERN', 'PERFORM', 'POINT', 'POS', 'PRIMARY', 'PRINT',
  1208. 'PROCEDURE', 'PROGRAM', 'PUT', 'READ', 'RECORD', 'RECORD-COUNT',
  1209. 'RECORD-LENGTH', 'REFRESH', 'RELEASE', 'RENUM', 'REPEAT', 'REPORT',
  1210. 'REPORT-INPUT', 'RESHOW', 'RESTART', 'RETRIEVE', 'RETURN-CODE',
  1211. 'ROLLBACK', 'ROW', 'S', 'SCREEN', 'SEARCH', 'SECONDARY', 'SELECT',
  1212. 'SEQUENCE', 'SIZE', 'SKIP', 'SOKAKU', 'SORT', 'SQL', 'STOP', 'SUM',
  1213. 'SYSDATE', 'SYSDATE-LONG', 'SYSIN', 'SYSIPT', 'SYSLST', 'SYSPRINT',
  1214. 'SYSSNAP', 'SYSTIME', 'TALLY', 'TERM-COLUMNS', 'TERM-NAME',
  1215. 'TERM-ROWS', 'TERMINATION', 'TITLE', 'TO', 'TRANSFER', 'TRC',
  1216. 'UNIQUE', 'UNTIL', 'UPDATE', 'UPPERCASE', 'USER', 'USERID', 'VALUE',
  1217. 'VERIFY', 'W', 'WHEN', 'WHILE', 'WORK', 'WRITE', 'X', 'XDM', 'XRST'
  1218. ]
  1219. tokens = {
  1220. 'root': [
  1221. (r'\*.*\n', Comment.Single),
  1222. (r'\n+', Whitespace),
  1223. # Macro argument
  1224. (r'&' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+\.', Name.Variable,
  1225. 'after_macro_argument'),
  1226. # Macro call
  1227. (r'%' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Variable),
  1228. (r'(FILE|MACRO|REPORT)(\s+)',
  1229. bygroups(Keyword.Declaration, Whitespace), 'after_declaration'),
  1230. (r'(JOB|PARM)' + r'(' + _DELIMITER_PATTERN + r')',
  1231. bygroups(Keyword.Declaration, Operator)),
  1232. (words(_KEYWORDS, suffix=_DELIMITER_PATTERN_CAPTURE),
  1233. bygroups(Keyword.Reserved, Operator)),
  1234. (_OPERATORS_PATTERN, Operator),
  1235. # Procedure declaration
  1236. (r'(' + _NON_DELIMITER_OR_COMMENT_PATTERN + r'+)(\s*)(\.?)(\s*)(PROC)(\s*\n)',
  1237. bygroups(Name.Function, Whitespace, Operator, Whitespace,
  1238. Keyword.Declaration, Whitespace)),
  1239. (r'[0-9]+\.[0-9]*', Number.Float),
  1240. (r'[0-9]+', Number.Integer),
  1241. (r"'(''|[^'])*'", String),
  1242. (r'\s+', Whitespace),
  1243. # Everything else just belongs to a name
  1244. (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
  1245. ],
  1246. 'after_declaration': [
  1247. (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name.Function),
  1248. default('#pop'),
  1249. ],
  1250. 'after_macro_argument': [
  1251. (r'\*.*\n', Comment.Single, '#pop'),
  1252. (r'\s+', Whitespace, '#pop'),
  1253. (_OPERATORS_PATTERN, Operator, '#pop'),
  1254. (r"'(''|[^'])*'", String, '#pop'),
  1255. # Everything else just belongs to a name
  1256. (_NON_DELIMITER_OR_COMMENT_PATTERN + r'+', Name),
  1257. ],
  1258. }
  1259. _COMMENT_LINE_REGEX = re.compile(r'^\s*\*')
  1260. _MACRO_HEADER_REGEX = re.compile(r'^\s*MACRO')
  1261. def analyse_text(text):
  1262. """
  1263. Perform a structural analysis for basic Easytrieve constructs.
  1264. """
  1265. result = 0.0
  1266. lines = text.split('\n')
  1267. hasEndProc = False
  1268. hasHeaderComment = False
  1269. hasFile = False
  1270. hasJob = False
  1271. hasProc = False
  1272. hasParm = False
  1273. hasReport = False
  1274. def isCommentLine(line):
  1275. return EasytrieveLexer._COMMENT_LINE_REGEX.match(lines[0]) is not None
  1276. def isEmptyLine(line):
  1277. return not bool(line.strip())
  1278. # Remove possible empty lines and header comments.
  1279. while lines and (isEmptyLine(lines[0]) or isCommentLine(lines[0])):
  1280. if not isEmptyLine(lines[0]):
  1281. hasHeaderComment = True
  1282. del lines[0]
  1283. if EasytrieveLexer._MACRO_HEADER_REGEX.match(lines[0]):
  1284. # Looks like an Easytrieve macro.
  1285. result = 0.4
  1286. if hasHeaderComment:
  1287. result += 0.4
  1288. else:
  1289. # Scan the source for lines starting with indicators.
  1290. for line in lines:
  1291. words = line.split()
  1292. if (len(words) >= 2):
  1293. firstWord = words[0]
  1294. if not hasReport:
  1295. if not hasJob:
  1296. if not hasFile:
  1297. if not hasParm:
  1298. if firstWord == 'PARM':
  1299. hasParm = True
  1300. if firstWord == 'FILE':
  1301. hasFile = True
  1302. if firstWord == 'JOB':
  1303. hasJob = True
  1304. elif firstWord == 'PROC':
  1305. hasProc = True
  1306. elif firstWord == 'END-PROC':
  1307. hasEndProc = True
  1308. elif firstWord == 'REPORT':
  1309. hasReport = True
  1310. # Weight the findings.
  1311. if hasJob and (hasProc == hasEndProc):
  1312. if hasHeaderComment:
  1313. result += 0.1
  1314. if hasParm:
  1315. if hasProc:
  1316. # Found PARM, JOB and PROC/END-PROC:
  1317. # pretty sure this is Easytrieve.
  1318. result += 0.8
  1319. else:
  1320. # Found PARAM and JOB: probably this is Easytrieve
  1321. result += 0.5
  1322. else:
  1323. # Found JOB and possibly other keywords: might be Easytrieve
  1324. result += 0.11
  1325. if hasParm:
  1326. # Note: PARAM is not a proper English word, so this is
  1327. # regarded a much better indicator for Easytrieve than
  1328. # the other words.
  1329. result += 0.2
  1330. if hasFile:
  1331. result += 0.01
  1332. if hasReport:
  1333. result += 0.01
  1334. assert 0.0 <= result <= 1.0
  1335. return result
  1336. class JclLexer(RegexLexer):
  1337. """
  1338. Job Control Language (JCL)
  1339. is a scripting language used on mainframe platforms to instruct the system
  1340. on how to run a batch job or start a subsystem. It is somewhat
  1341. comparable to MS DOS batch and Unix shell scripts.
  1342. """
  1343. name = 'JCL'
  1344. aliases = ['jcl']
  1345. filenames = ['*.jcl']
  1346. mimetypes = ['text/x-jcl']
  1347. url = 'https://en.wikipedia.org/wiki/Job_Control_Language'
  1348. version_added = '2.1'
  1349. flags = re.IGNORECASE
  1350. tokens = {
  1351. 'root': [
  1352. (r'//\*.*\n', Comment.Single),
  1353. (r'//', Keyword.Pseudo, 'statement'),
  1354. (r'/\*', Keyword.Pseudo, 'jes2_statement'),
  1355. # TODO: JES3 statement
  1356. (r'.*\n', Other) # Input text or inline code in any language.
  1357. ],
  1358. 'statement': [
  1359. (r'\s*\n', Whitespace, '#pop'),
  1360. (r'([a-z]\w*)(\s+)(exec|job)(\s*)',
  1361. bygroups(Name.Label, Whitespace, Keyword.Reserved, Whitespace),
  1362. 'option'),
  1363. (r'[a-z]\w*', Name.Variable, 'statement_command'),
  1364. (r'\s+', Whitespace, 'statement_command'),
  1365. ],
  1366. 'statement_command': [
  1367. (r'\s+(command|cntl|dd|endctl|endif|else|include|jcllib|'
  1368. r'output|pend|proc|set|then|xmit)\s+', Keyword.Reserved, 'option'),
  1369. include('option')
  1370. ],
  1371. 'jes2_statement': [
  1372. (r'\s*\n', Whitespace, '#pop'),
  1373. (r'\$', Keyword, 'option'),
  1374. (r'\b(jobparam|message|netacct|notify|output|priority|route|'
  1375. r'setup|signoff|xeq|xmit)\b', Keyword, 'option'),
  1376. ],
  1377. 'option': [
  1378. # (r'\n', Text, 'root'),
  1379. (r'\*', Name.Builtin),
  1380. (r'[\[\](){}<>;,]', Punctuation),
  1381. (r'[-+*/=&%]', Operator),
  1382. (r'[a-z_]\w*', Name),
  1383. (r'\d+\.\d*', Number.Float),
  1384. (r'\.\d+', Number.Float),
  1385. (r'\d+', Number.Integer),
  1386. (r"'", String, 'option_string'),
  1387. (r'[ \t]+', Whitespace, 'option_comment'),
  1388. (r'\.', Punctuation),
  1389. ],
  1390. 'option_string': [
  1391. (r"(\n)(//)", bygroups(Text, Keyword.Pseudo)),
  1392. (r"''", String),
  1393. (r"[^']", String),
  1394. (r"'", String, '#pop'),
  1395. ],
  1396. 'option_comment': [
  1397. # (r'\n', Text, 'root'),
  1398. (r'.+', Comment.Single),
  1399. ]
  1400. }
  1401. _JOB_HEADER_PATTERN = re.compile(r'^//[a-z#$@][a-z0-9#$@]{0,7}\s+job(\s+.*)?$',
  1402. re.IGNORECASE)
  1403. def analyse_text(text):
  1404. """
  1405. Recognize JCL job by header.
  1406. """
  1407. result = 0.0
  1408. lines = text.split('\n')
  1409. if len(lines) > 0:
  1410. if JclLexer._JOB_HEADER_PATTERN.match(lines[0]):
  1411. result = 1.0
  1412. assert 0.0 <= result <= 1.0
  1413. return result
  1414. class MiniScriptLexer(RegexLexer):
  1415. """
  1416. For MiniScript source code.
  1417. """
  1418. name = 'MiniScript'
  1419. url = 'https://miniscript.org'
  1420. aliases = ['miniscript', 'ms']
  1421. filenames = ['*.ms']
  1422. mimetypes = ['text/x-minicript', 'application/x-miniscript']
  1423. version_added = '2.6'
  1424. tokens = {
  1425. 'root': [
  1426. (r'#!(.*?)$', Comment.Preproc),
  1427. default('base'),
  1428. ],
  1429. 'base': [
  1430. ('//.*$', Comment.Single),
  1431. (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number),
  1432. (r'(?i)\d+e[+-]?\d+', Number),
  1433. (r'\d+', Number),
  1434. (r'\n', Text),
  1435. (r'[^\S\n]+', Text),
  1436. (r'"', String, 'string_double'),
  1437. (r'(==|!=|<=|>=|[=+\-*/%^<>.:])', Operator),
  1438. (r'[;,\[\]{}()]', Punctuation),
  1439. (words((
  1440. 'break', 'continue', 'else', 'end', 'for', 'function', 'if',
  1441. 'in', 'isa', 'then', 'repeat', 'return', 'while'), suffix=r'\b'),
  1442. Keyword),
  1443. (words((
  1444. 'abs', 'acos', 'asin', 'atan', 'ceil', 'char', 'cos', 'floor',
  1445. 'log', 'round', 'rnd', 'pi', 'sign', 'sin', 'sqrt', 'str', 'tan',
  1446. 'hasIndex', 'indexOf', 'len', 'val', 'code', 'remove', 'lower',
  1447. 'upper', 'replace', 'split', 'indexes', 'values', 'join', 'sum',
  1448. 'sort', 'shuffle', 'push', 'pop', 'pull', 'range',
  1449. 'print', 'input', 'time', 'wait', 'locals', 'globals', 'outer',
  1450. 'yield'), suffix=r'\b'),
  1451. Name.Builtin),
  1452. (r'(true|false|null)\b', Keyword.Constant),
  1453. (r'(and|or|not|new)\b', Operator.Word),
  1454. (r'(self|super|__isa)\b', Name.Builtin.Pseudo),
  1455. (r'[a-zA-Z_]\w*', Name.Variable)
  1456. ],
  1457. 'string_double': [
  1458. (r'[^"\n]+', String),
  1459. (r'""', String),
  1460. (r'"', String, '#pop'),
  1461. (r'\n', Text, '#pop'), # Stray linefeed also terminates strings.
  1462. ]
  1463. }