scripting.py 68 KB

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