"Fossies" - the Fresh Open Source Software Archive

Member "eric6-20.9/eric/eric6/ThirdParty/Pygments/pygments/lexers/scripting.py" (2 May 2020, 69759 Bytes) of package /linux/misc/eric6-20.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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