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