scripting.py 79 KB

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