|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.scripting |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexer for scripting and embedded languages. |
|
7 |
|
8 :copyright: Copyright 2006-2014 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 |
|
18 from pygments.util import get_bool_opt, get_list_opt, iteritems |
|
19 |
|
20 __all__ = ['LuaLexer', 'MoonScriptLexer', 'ChaiscriptLexer', 'LSLLexer', |
|
21 'AppleScriptLexer', 'RexxLexer', 'MOOCodeLexer', 'HybrisLexer'] |
|
22 |
|
23 |
|
24 class LuaLexer(RegexLexer): |
|
25 """ |
|
26 For `Lua <http://www.lua.org>`_ source code. |
|
27 |
|
28 Additional options accepted: |
|
29 |
|
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. |
|
36 |
|
37 To get a list of allowed modules have a look into the |
|
38 `_lua_builtins` module: |
|
39 |
|
40 .. sourcecode:: pycon |
|
41 |
|
42 >>> from pygments.lexers._lua_builtins import MODULES |
|
43 >>> MODULES.keys() |
|
44 ['string', 'coroutine', 'modules', 'io', 'basic', ...] |
|
45 """ |
|
46 |
|
47 name = 'Lua' |
|
48 aliases = ['lua'] |
|
49 filenames = ['*.lua', '*.wlua'] |
|
50 mimetypes = ['text/x-lua', 'application/x-lua'] |
|
51 |
|
52 tokens = { |
|
53 'root': [ |
|
54 # lua allows a file to start with a shebang |
|
55 (r'#!(.*?)$', Comment.Preproc), |
|
56 default('base'), |
|
57 ], |
|
58 'base': [ |
|
59 (r'(?s)--\[(=*)\[.*?\]\1\]', Comment.Multiline), |
|
60 ('--.*$', Comment.Single), |
|
61 |
|
62 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float), |
|
63 (r'(?i)\d+e[+-]?\d+', Number.Float), |
|
64 ('(?i)0x[0-9a-f]*', Number.Hex), |
|
65 (r'\d+', Number.Integer), |
|
66 |
|
67 (r'\n', Text), |
|
68 (r'[^\S\n]', Text), |
|
69 # multiline strings |
|
70 (r'(?s)\[(=*)\[.*?\]\1\]', String), |
|
71 |
|
72 (r'(==|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#])', Operator), |
|
73 (r'[\[\]{}().,:;]', Punctuation), |
|
74 (r'(and|or|not)\b', Operator.Word), |
|
75 |
|
76 ('(break|do|else|elseif|end|for|if|in|repeat|return|then|until|' |
|
77 r'while)\b', Keyword), |
|
78 (r'(local)\b', Keyword.Declaration), |
|
79 (r'(true|false|nil)\b', Keyword.Constant), |
|
80 |
|
81 (r'(function)\b', Keyword, 'funcname'), |
|
82 |
|
83 (r'[A-Za-z_]\w*(\.[A-Za-z_]\w*)?', Name), |
|
84 |
|
85 ("'", String.Single, combined('stringescape', 'sqs')), |
|
86 ('"', String.Double, combined('stringescape', 'dqs')) |
|
87 ], |
|
88 |
|
89 'funcname': [ |
|
90 (r'\s+', Text), |
|
91 ('(?:([A-Za-z_]\w*)(\.))?([A-Za-z_]\w*)', |
|
92 bygroups(Name.Class, Punctuation, Name.Function), '#pop'), |
|
93 # inline function |
|
94 ('\(', Punctuation, '#pop'), |
|
95 ], |
|
96 |
|
97 # if I understand correctly, every character is valid in a lua string, |
|
98 # so this state is only for later corrections |
|
99 'string': [ |
|
100 ('.', String) |
|
101 ], |
|
102 |
|
103 'stringescape': [ |
|
104 (r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape) |
|
105 ], |
|
106 |
|
107 'sqs': [ |
|
108 ("'", String, '#pop'), |
|
109 include('string') |
|
110 ], |
|
111 |
|
112 'dqs': [ |
|
113 ('"', String, '#pop'), |
|
114 include('string') |
|
115 ] |
|
116 } |
|
117 |
|
118 def __init__(self, **options): |
|
119 self.func_name_highlighting = get_bool_opt( |
|
120 options, 'func_name_highlighting', True) |
|
121 self.disabled_modules = get_list_opt(options, 'disabled_modules', []) |
|
122 |
|
123 self._functions = set() |
|
124 if self.func_name_highlighting: |
|
125 from pygments.lexers._lua_builtins import MODULES |
|
126 for mod, func in iteritems(MODULES): |
|
127 if mod not in self.disabled_modules: |
|
128 self._functions.update(func) |
|
129 RegexLexer.__init__(self, **options) |
|
130 |
|
131 def get_tokens_unprocessed(self, text): |
|
132 for index, token, value in \ |
|
133 RegexLexer.get_tokens_unprocessed(self, text): |
|
134 if token is Name: |
|
135 if value in self._functions: |
|
136 yield index, Name.Builtin, value |
|
137 continue |
|
138 elif '.' in value: |
|
139 a, b = value.split('.') |
|
140 yield index, Name, a |
|
141 yield index + len(a), Punctuation, u'.' |
|
142 yield index + len(a) + 1, Name, b |
|
143 continue |
|
144 yield index, token, value |
|
145 |
|
146 |
|
147 class MoonScriptLexer(LuaLexer): |
|
148 """ |
|
149 For `MoonScript <http://moonscript.org>`_ source code. |
|
150 |
|
151 .. versionadded:: 1.5 |
|
152 """ |
|
153 |
|
154 name = "MoonScript" |
|
155 aliases = ["moon", "moonscript"] |
|
156 filenames = ["*.moon"] |
|
157 mimetypes = ['text/x-moonscript', 'application/x-moonscript'] |
|
158 |
|
159 tokens = { |
|
160 'root': [ |
|
161 (r'#!(.*?)$', Comment.Preproc), |
|
162 default('base'), |
|
163 ], |
|
164 'base': [ |
|
165 ('--.*$', Comment.Single), |
|
166 (r'(?i)(\d*\.\d+|\d+\.\d*)(e[+-]?\d+)?', Number.Float), |
|
167 (r'(?i)\d+e[+-]?\d+', Number.Float), |
|
168 (r'(?i)0x[0-9a-f]*', Number.Hex), |
|
169 (r'\d+', Number.Integer), |
|
170 (r'\n', Text), |
|
171 (r'[^\S\n]+', Text), |
|
172 (r'(?s)\[(=*)\[.*?\]\1\]', String), |
|
173 (r'(->|=>)', Name.Function), |
|
174 (r':[a-zA-Z_]\w*', Name.Variable), |
|
175 (r'(==|!=|~=|<=|>=|\.\.\.|\.\.|[=+\-*/%^<>#!.\\:])', Operator), |
|
176 (r'[;,]', Punctuation), |
|
177 (r'[\[\]{}()]', Keyword.Type), |
|
178 (r'[a-zA-Z_]\w*:', Name.Variable), |
|
179 (words(( |
|
180 'class', 'extends', 'if', 'then', 'super', 'do', 'with', |
|
181 'import', 'export', 'while', 'elseif', 'return', 'for', 'in', |
|
182 'from', 'when', 'using', 'else', 'and', 'or', 'not', 'switch', |
|
183 'break'), suffix=r'\b'), |
|
184 Keyword), |
|
185 (r'(true|false|nil)\b', Keyword.Constant), |
|
186 (r'(and|or|not)\b', Operator.Word), |
|
187 (r'(self)\b', Name.Builtin.Pseudo), |
|
188 (r'@@?([a-zA-Z_]\w*)?', Name.Variable.Class), |
|
189 (r'[A-Z]\w*', Name.Class), # proper name |
|
190 (r'[A-Za-z_]\w*(\.[A-Za-z_]\w*)?', Name), |
|
191 ("'", String.Single, combined('stringescape', 'sqs')), |
|
192 ('"', String.Double, combined('stringescape', 'dqs')) |
|
193 ], |
|
194 'stringescape': [ |
|
195 (r'''\\([abfnrtv\\"']|\d{1,3})''', String.Escape) |
|
196 ], |
|
197 'sqs': [ |
|
198 ("'", String.Single, '#pop'), |
|
199 (".", String) |
|
200 ], |
|
201 'dqs': [ |
|
202 ('"', String.Double, '#pop'), |
|
203 (".", String) |
|
204 ] |
|
205 } |
|
206 |
|
207 def get_tokens_unprocessed(self, text): |
|
208 # set . as Operator instead of Punctuation |
|
209 for index, token, value in LuaLexer.get_tokens_unprocessed(self, text): |
|
210 if token == Punctuation and value == ".": |
|
211 token = Operator |
|
212 yield index, token, value |
|
213 |
|
214 |
|
215 class ChaiscriptLexer(RegexLexer): |
|
216 """ |
|
217 For `ChaiScript <http://chaiscript.com/>`_ source code. |
|
218 |
|
219 .. versionadded:: 2.0 |
|
220 """ |
|
221 |
|
222 name = 'ChaiScript' |
|
223 aliases = ['chai', 'chaiscript'] |
|
224 filenames = ['*.chai'] |
|
225 mimetypes = ['text/x-chaiscript', 'application/x-chaiscript'] |
|
226 |
|
227 flags = re.DOTALL | re.MULTILINE |
|
228 |
|
229 tokens = { |
|
230 'commentsandwhitespace': [ |
|
231 (r'\s+', Text), |
|
232 (r'//.*?\n', Comment.Single), |
|
233 (r'/\*.*?\*/', Comment.Multiline), |
|
234 (r'^\#.*?\n', Comment.Single) |
|
235 ], |
|
236 'slashstartsregex': [ |
|
237 include('commentsandwhitespace'), |
|
238 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
239 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
240 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
241 default('#pop') |
|
242 ], |
|
243 'badregex': [ |
|
244 (r'\n', Text, '#pop') |
|
245 ], |
|
246 'root': [ |
|
247 include('commentsandwhitespace'), |
|
248 (r'\n', Text), |
|
249 (r'[^\S\n]+', Text), |
|
250 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|\.\.' |
|
251 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), |
|
252 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
253 (r'[})\].]', Punctuation), |
|
254 (r'[=+\-*/]', Operator), |
|
255 (r'(for|in|while|do|break|return|continue|if|else|' |
|
256 r'throw|try|catch' |
|
257 r')\b', Keyword, 'slashstartsregex'), |
|
258 (r'(var)\b', Keyword.Declaration, 'slashstartsregex'), |
|
259 (r'(attr|def|fun)\b', Keyword.Reserved), |
|
260 (r'(true|false)\b', Keyword.Constant), |
|
261 (r'(eval|throw)\b', Name.Builtin), |
|
262 (r'`\S+`', Name.Builtin), |
|
263 (r'[$a-zA-Z_]\w*', Name.Other), |
|
264 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
265 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
266 (r'[0-9]+', Number.Integer), |
|
267 (r'"', String.Double, 'dqstring'), |
|
268 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
269 ], |
|
270 'dqstring': [ |
|
271 (r'\$\{[^"}]+?\}', String.Interpol), |
|
272 (r'\$', String.Double), |
|
273 (r'\\\\', String.Double), |
|
274 (r'\\"', String.Double), |
|
275 (r'[^\\"$]+', String.Double), |
|
276 (r'"', String.Double, '#pop'), |
|
277 ], |
|
278 } |
|
279 |
|
280 |
|
281 class LSLLexer(RegexLexer): |
|
282 """ |
|
283 For Second Life's Linden Scripting Language source code. |
|
284 |
|
285 .. versionadded:: 2.0 |
|
286 """ |
|
287 |
|
288 name = 'LSL' |
|
289 aliases = ['lsl'] |
|
290 filenames = ['*.lsl'] |
|
291 mimetypes = ['text/x-lsl'] |
|
292 |
|
293 flags = re.MULTILINE |
|
294 |
|
295 lsl_keywords = r'\b(?:do|else|for|if|jump|return|while)\b' |
|
296 lsl_types = r'\b(?:float|integer|key|list|quaternion|rotation|string|vector)\b' |
|
297 lsl_states = r'\b(?:(?:state)\s+\w+|default)\b' |
|
298 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' |
|
299 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' |
|
300 lsl_constants_float = r'\b(?:DEG_TO_RAD|PI(?:_BY_TWO)?|RAD_TO_DEG|SQRT2|TWO_PI)\b' |
|
301 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' |
|
302 lsl_constants_integer_boolean = r'\b(?:FALSE|TRUE)\b' |
|
303 lsl_constants_rotation = r'\b(?:ZERO_ROTATION)\b' |
|
304 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' |
|
305 lsl_constants_vector = r'\b(?:TOUCH_INVALID_(?:TEXCOORD|VECTOR)|ZERO_VECTOR)\b' |
|
306 lsl_invalid_broken = r'\b(?:LAND_(?:LARGE|MEDIUM|SMALL)_BRUSH)\b' |
|
307 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' |
|
308 lsl_invalid_illegal = r'\b(?:event)\b' |
|
309 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' |
|
310 lsl_reserved_godmode = r'\b(?:ll(?:GodLikeRezObject|Set(?:Inventory|Object)PermMask))\b' |
|
311 lsl_reserved_log = r'\b(?:print)\b' |
|
312 lsl_operators = r'\+\+|\-\-|<<|>>|&&?|\|\|?|\^|~|[!%<>=*+\-/]=?' |
|
313 |
|
314 tokens = { |
|
315 'root': |
|
316 [ |
|
317 (r'//.*?\n', Comment.Single), |
|
318 (r'/\*', Comment.Multiline, 'comment'), |
|
319 (r'"', String.Double, 'string'), |
|
320 (lsl_keywords, Keyword), |
|
321 (lsl_types, Keyword.Type), |
|
322 (lsl_states, Name.Class), |
|
323 (lsl_events, Name.Builtin), |
|
324 (lsl_functions_builtin, Name.Function), |
|
325 (lsl_constants_float, Keyword.Constant), |
|
326 (lsl_constants_integer, Keyword.Constant), |
|
327 (lsl_constants_integer_boolean, Keyword.Constant), |
|
328 (lsl_constants_rotation, Keyword.Constant), |
|
329 (lsl_constants_string, Keyword.Constant), |
|
330 (lsl_constants_vector, Keyword.Constant), |
|
331 (lsl_invalid_broken, Error), |
|
332 (lsl_invalid_deprecated, Error), |
|
333 (lsl_invalid_illegal, Error), |
|
334 (lsl_invalid_unimplemented, Error), |
|
335 (lsl_reserved_godmode, Keyword.Reserved), |
|
336 (lsl_reserved_log, Keyword.Reserved), |
|
337 (r'\b([a-zA-Z_]\w*)\b', Name.Variable), |
|
338 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d*', Number.Float), |
|
339 (r'(\d+\.\d*|\.\d+)', Number.Float), |
|
340 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
341 (r'\d+', Number.Integer), |
|
342 (lsl_operators, Operator), |
|
343 (r':=?', Error), |
|
344 (r'[,;{}()\[\]]', Punctuation), |
|
345 (r'\n+', Whitespace), |
|
346 (r'\s+', Whitespace) |
|
347 ], |
|
348 'comment': |
|
349 [ |
|
350 (r'[^*/]+', Comment.Multiline), |
|
351 (r'/\*', Comment.Multiline, '#push'), |
|
352 (r'\*/', Comment.Multiline, '#pop'), |
|
353 (r'[*/]', Comment.Multiline) |
|
354 ], |
|
355 'string': |
|
356 [ |
|
357 (r'\\([nt"\\])', String.Escape), |
|
358 (r'"', String.Double, '#pop'), |
|
359 (r'\\.', Error), |
|
360 (r'[^"\\]+', String.Double), |
|
361 ] |
|
362 } |
|
363 |
|
364 |
|
365 class AppleScriptLexer(RegexLexer): |
|
366 """ |
|
367 For `AppleScript source code |
|
368 <http://developer.apple.com/documentation/AppleScript/ |
|
369 Conceptual/AppleScriptLangGuide>`_, |
|
370 including `AppleScript Studio |
|
371 <http://developer.apple.com/documentation/AppleScript/ |
|
372 Reference/StudioReference>`_. |
|
373 Contributed by Andreas Amann <aamann@mac.com>. |
|
374 |
|
375 .. versionadded:: 1.0 |
|
376 """ |
|
377 |
|
378 name = 'AppleScript' |
|
379 aliases = ['applescript'] |
|
380 filenames = ['*.applescript'] |
|
381 |
|
382 flags = re.MULTILINE | re.DOTALL |
|
383 |
|
384 Identifiers = r'[a-zA-Z]\w*' |
|
385 |
|
386 # XXX: use words() for all of these |
|
387 Literals = ('AppleScript', 'current application', 'false', 'linefeed', |
|
388 'missing value', 'pi', 'quote', 'result', 'return', 'space', |
|
389 'tab', 'text item delimiters', 'true', 'version') |
|
390 Classes = ('alias ', 'application ', 'boolean ', 'class ', 'constant ', |
|
391 'date ', 'file ', 'integer ', 'list ', 'number ', 'POSIX file ', |
|
392 'real ', 'record ', 'reference ', 'RGB color ', 'script ', |
|
393 'text ', 'unit types', '(?:Unicode )?text', 'string') |
|
394 BuiltIn = ('attachment', 'attribute run', 'character', 'day', 'month', |
|
395 'paragraph', 'word', 'year') |
|
396 HandlerParams = ('about', 'above', 'against', 'apart from', 'around', |
|
397 'aside from', 'at', 'below', 'beneath', 'beside', |
|
398 'between', 'for', 'given', 'instead of', 'on', 'onto', |
|
399 'out of', 'over', 'since') |
|
400 Commands = ('ASCII (character|number)', 'activate', 'beep', 'choose URL', |
|
401 'choose application', 'choose color', 'choose file( name)?', |
|
402 'choose folder', 'choose from list', |
|
403 'choose remote application', 'clipboard info', |
|
404 'close( access)?', 'copy', 'count', 'current date', 'delay', |
|
405 'delete', 'display (alert|dialog)', 'do shell script', |
|
406 'duplicate', 'exists', 'get eof', 'get volume settings', |
|
407 'info for', 'launch', 'list (disks|folder)', 'load script', |
|
408 'log', 'make', 'mount volume', 'new', 'offset', |
|
409 'open( (for access|location))?', 'path to', 'print', 'quit', |
|
410 'random number', 'read', 'round', 'run( script)?', |
|
411 'say', 'scripting components', |
|
412 'set (eof|the clipboard to|volume)', 'store script', |
|
413 'summarize', 'system attribute', 'system info', |
|
414 'the clipboard', 'time to GMT', 'write', 'quoted form') |
|
415 References = ('(in )?back of', '(in )?front of', '[0-9]+(st|nd|rd|th)', |
|
416 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', |
|
417 'seventh', 'eighth', 'ninth', 'tenth', 'after', 'back', |
|
418 'before', 'behind', 'every', 'front', 'index', 'last', |
|
419 'middle', 'some', 'that', 'through', 'thru', 'where', 'whose') |
|
420 Operators = ("and", "or", "is equal", "equals", "(is )?equal to", "is not", |
|
421 "isn't", "isn't equal( to)?", "is not equal( to)?", |
|
422 "doesn't equal", "does not equal", "(is )?greater than", |
|
423 "comes after", "is not less than or equal( to)?", |
|
424 "isn't less than or equal( to)?", "(is )?less than", |
|
425 "comes before", "is not greater than or equal( to)?", |
|
426 "isn't greater than or equal( to)?", |
|
427 "(is )?greater than or equal( to)?", "is not less than", |
|
428 "isn't less than", "does not come before", |
|
429 "doesn't come before", "(is )?less than or equal( to)?", |
|
430 "is not greater than", "isn't greater than", |
|
431 "does not come after", "doesn't come after", "starts? with", |
|
432 "begins? with", "ends? with", "contains?", "does not contain", |
|
433 "doesn't contain", "is in", "is contained by", "is not in", |
|
434 "is not contained by", "isn't contained by", "div", "mod", |
|
435 "not", "(a )?(ref( to)?|reference to)", "is", "does") |
|
436 Control = ('considering', 'else', 'error', 'exit', 'from', 'if', |
|
437 'ignoring', 'in', 'repeat', 'tell', 'then', 'times', 'to', |
|
438 'try', 'until', 'using terms from', 'while', 'whith', |
|
439 'with timeout( of)?', 'with transaction', 'by', 'continue', |
|
440 'end', 'its?', 'me', 'my', 'return', 'of', 'as') |
|
441 Declarations = ('global', 'local', 'prop(erty)?', 'set', 'get') |
|
442 Reserved = ('but', 'put', 'returning', 'the') |
|
443 StudioClasses = ('action cell', 'alert reply', 'application', 'box', |
|
444 'browser( cell)?', 'bundle', 'button( cell)?', 'cell', |
|
445 'clip view', 'color well', 'color-panel', |
|
446 'combo box( item)?', 'control', |
|
447 'data( (cell|column|item|row|source))?', 'default entry', |
|
448 'dialog reply', 'document', 'drag info', 'drawer', |
|
449 'event', 'font(-panel)?', 'formatter', |
|
450 'image( (cell|view))?', 'matrix', 'menu( item)?', 'item', |
|
451 'movie( view)?', 'open-panel', 'outline view', 'panel', |
|
452 'pasteboard', 'plugin', 'popup button', |
|
453 'progress indicator', 'responder', 'save-panel', |
|
454 'scroll view', 'secure text field( cell)?', 'slider', |
|
455 'sound', 'split view', 'stepper', 'tab view( item)?', |
|
456 'table( (column|header cell|header view|view))', |
|
457 'text( (field( cell)?|view))?', 'toolbar( item)?', |
|
458 'user-defaults', 'view', 'window') |
|
459 StudioEvents = ('accept outline drop', 'accept table drop', 'action', |
|
460 'activated', 'alert ended', 'awake from nib', 'became key', |
|
461 'became main', 'begin editing', 'bounds changed', |
|
462 'cell value', 'cell value changed', 'change cell value', |
|
463 'change item value', 'changed', 'child of item', |
|
464 'choose menu item', 'clicked', 'clicked toolbar item', |
|
465 'closed', 'column clicked', 'column moved', |
|
466 'column resized', 'conclude drop', 'data representation', |
|
467 'deminiaturized', 'dialog ended', 'document nib name', |
|
468 'double clicked', 'drag( (entered|exited|updated))?', |
|
469 'drop', 'end editing', 'exposed', 'idle', 'item expandable', |
|
470 'item value', 'item value changed', 'items changed', |
|
471 'keyboard down', 'keyboard up', 'launched', |
|
472 'load data representation', 'miniaturized', 'mouse down', |
|
473 'mouse dragged', 'mouse entered', 'mouse exited', |
|
474 'mouse moved', 'mouse up', 'moved', |
|
475 'number of browser rows', 'number of items', |
|
476 'number of rows', 'open untitled', 'opened', 'panel ended', |
|
477 'parameters updated', 'plugin loaded', 'prepare drop', |
|
478 'prepare outline drag', 'prepare outline drop', |
|
479 'prepare table drag', 'prepare table drop', |
|
480 'read from file', 'resigned active', 'resigned key', |
|
481 'resigned main', 'resized( sub views)?', |
|
482 'right mouse down', 'right mouse dragged', |
|
483 'right mouse up', 'rows changed', 'scroll wheel', |
|
484 'selected tab view item', 'selection changed', |
|
485 'selection changing', 'should begin editing', |
|
486 'should close', 'should collapse item', |
|
487 'should end editing', 'should expand item', |
|
488 'should open( untitled)?', |
|
489 'should quit( after last window closed)?', |
|
490 'should select column', 'should select item', |
|
491 'should select row', 'should select tab view item', |
|
492 'should selection change', 'should zoom', 'shown', |
|
493 'update menu item', 'update parameters', |
|
494 'update toolbar item', 'was hidden', 'was miniaturized', |
|
495 'will become active', 'will close', 'will dismiss', |
|
496 'will display browser cell', 'will display cell', |
|
497 'will display item cell', 'will display outline cell', |
|
498 'will finish launching', 'will hide', 'will miniaturize', |
|
499 'will move', 'will open', 'will pop up', 'will quit', |
|
500 'will resign active', 'will resize( sub views)?', |
|
501 'will select tab view item', 'will show', 'will zoom', |
|
502 'write to file', 'zoomed') |
|
503 StudioCommands = ('animate', 'append', 'call method', 'center', |
|
504 'close drawer', 'close panel', 'display', |
|
505 'display alert', 'display dialog', 'display panel', 'go', |
|
506 'hide', 'highlight', 'increment', 'item for', |
|
507 'load image', 'load movie', 'load nib', 'load panel', |
|
508 'load sound', 'localized string', 'lock focus', 'log', |
|
509 'open drawer', 'path for', 'pause', 'perform action', |
|
510 'play', 'register', 'resume', 'scroll', 'select( all)?', |
|
511 'show', 'size to fit', 'start', 'step back', |
|
512 'step forward', 'stop', 'synchronize', 'unlock focus', |
|
513 'update') |
|
514 StudioProperties = ('accepts arrow key', 'action method', 'active', |
|
515 'alignment', 'allowed identifiers', |
|
516 'allows branch selection', 'allows column reordering', |
|
517 'allows column resizing', 'allows column selection', |
|
518 'allows customization', |
|
519 'allows editing text attributes', |
|
520 'allows empty selection', 'allows mixed state', |
|
521 'allows multiple selection', 'allows reordering', |
|
522 'allows undo', 'alpha( value)?', 'alternate image', |
|
523 'alternate increment value', 'alternate title', |
|
524 'animation delay', 'associated file name', |
|
525 'associated object', 'auto completes', 'auto display', |
|
526 'auto enables items', 'auto repeat', |
|
527 'auto resizes( outline column)?', |
|
528 'auto save expanded items', 'auto save name', |
|
529 'auto save table columns', 'auto saves configuration', |
|
530 'auto scroll', 'auto sizes all columns to fit', |
|
531 'auto sizes cells', 'background color', 'bezel state', |
|
532 'bezel style', 'bezeled', 'border rect', 'border type', |
|
533 'bordered', 'bounds( rotation)?', 'box type', |
|
534 'button returned', 'button type', |
|
535 'can choose directories', 'can choose files', |
|
536 'can draw', 'can hide', |
|
537 'cell( (background color|size|type))?', 'characters', |
|
538 'class', 'click count', 'clicked( data)? column', |
|
539 'clicked data item', 'clicked( data)? row', |
|
540 'closeable', 'collating', 'color( (mode|panel))', |
|
541 'command key down', 'configuration', |
|
542 'content(s| (size|view( margins)?))?', 'context', |
|
543 'continuous', 'control key down', 'control size', |
|
544 'control tint', 'control view', |
|
545 'controller visible', 'coordinate system', |
|
546 'copies( on scroll)?', 'corner view', 'current cell', |
|
547 'current column', 'current( field)? editor', |
|
548 'current( menu)? item', 'current row', |
|
549 'current tab view item', 'data source', |
|
550 'default identifiers', 'delta (x|y|z)', |
|
551 'destination window', 'directory', 'display mode', |
|
552 'displayed cell', 'document( (edited|rect|view))?', |
|
553 'double value', 'dragged column', 'dragged distance', |
|
554 'dragged items', 'draws( cell)? background', |
|
555 'draws grid', 'dynamically scrolls', 'echos bullets', |
|
556 'edge', 'editable', 'edited( data)? column', |
|
557 'edited data item', 'edited( data)? row', 'enabled', |
|
558 'enclosing scroll view', 'ending page', |
|
559 'error handling', 'event number', 'event type', |
|
560 'excluded from windows menu', 'executable path', |
|
561 'expanded', 'fax number', 'field editor', 'file kind', |
|
562 'file name', 'file type', 'first responder', |
|
563 'first visible column', 'flipped', 'floating', |
|
564 'font( panel)?', 'formatter', 'frameworks path', |
|
565 'frontmost', 'gave up', 'grid color', 'has data items', |
|
566 'has horizontal ruler', 'has horizontal scroller', |
|
567 'has parent data item', 'has resize indicator', |
|
568 'has shadow', 'has sub menu', 'has vertical ruler', |
|
569 'has vertical scroller', 'header cell', 'header view', |
|
570 'hidden', 'hides when deactivated', 'highlights by', |
|
571 'horizontal line scroll', 'horizontal page scroll', |
|
572 'horizontal ruler view', 'horizontally resizable', |
|
573 'icon image', 'id', 'identifier', |
|
574 'ignores multiple clicks', |
|
575 'image( (alignment|dims when disabled|frame style|scaling))?', |
|
576 'imports graphics', 'increment value', |
|
577 'indentation per level', 'indeterminate', 'index', |
|
578 'integer value', 'intercell spacing', 'item height', |
|
579 'key( (code|equivalent( modifier)?|window))?', |
|
580 'knob thickness', 'label', 'last( visible)? column', |
|
581 'leading offset', 'leaf', 'level', 'line scroll', |
|
582 'loaded', 'localized sort', 'location', 'loop mode', |
|
583 'main( (bunde|menu|window))?', 'marker follows cell', |
|
584 'matrix mode', 'maximum( content)? size', |
|
585 'maximum visible columns', |
|
586 'menu( form representation)?', 'miniaturizable', |
|
587 'miniaturized', 'minimized image', 'minimized title', |
|
588 'minimum column width', 'minimum( content)? size', |
|
589 'modal', 'modified', 'mouse down state', |
|
590 'movie( (controller|file|rect))?', 'muted', 'name', |
|
591 'needs display', 'next state', 'next text', |
|
592 'number of tick marks', 'only tick mark values', |
|
593 'opaque', 'open panel', 'option key down', |
|
594 'outline table column', 'page scroll', 'pages across', |
|
595 'pages down', 'palette label', 'pane splitter', |
|
596 'parent data item', 'parent window', 'pasteboard', |
|
597 'path( (names|separator))?', 'playing', |
|
598 'plays every frame', 'plays selection only', 'position', |
|
599 'preferred edge', 'preferred type', 'pressure', |
|
600 'previous text', 'prompt', 'properties', |
|
601 'prototype cell', 'pulls down', 'rate', |
|
602 'released when closed', 'repeated', |
|
603 'requested print time', 'required file type', |
|
604 'resizable', 'resized column', 'resource path', |
|
605 'returns records', 'reuses columns', 'rich text', |
|
606 'roll over', 'row height', 'rulers visible', |
|
607 'save panel', 'scripts path', 'scrollable', |
|
608 'selectable( identifiers)?', 'selected cell', |
|
609 'selected( data)? columns?', 'selected data items?', |
|
610 'selected( data)? rows?', 'selected item identifier', |
|
611 'selection by rect', 'send action on arrow key', |
|
612 'sends action when done editing', 'separates columns', |
|
613 'separator item', 'sequence number', 'services menu', |
|
614 'shared frameworks path', 'shared support path', |
|
615 'sheet', 'shift key down', 'shows alpha', |
|
616 'shows state by', 'size( mode)?', |
|
617 'smart insert delete enabled', 'sort case sensitivity', |
|
618 'sort column', 'sort order', 'sort type', |
|
619 'sorted( data rows)?', 'sound', 'source( mask)?', |
|
620 'spell checking enabled', 'starting page', 'state', |
|
621 'string value', 'sub menu', 'super menu', 'super view', |
|
622 'tab key traverses cells', 'tab state', 'tab type', |
|
623 'tab view', 'table view', 'tag', 'target( printer)?', |
|
624 'text color', 'text container insert', |
|
625 'text container origin', 'text returned', |
|
626 'tick mark position', 'time stamp', |
|
627 'title(d| (cell|font|height|position|rect))?', |
|
628 'tool tip', 'toolbar', 'trailing offset', 'transparent', |
|
629 'treat packages as directories', 'truncated labels', |
|
630 'types', 'unmodified characters', 'update views', |
|
631 'use sort indicator', 'user defaults', |
|
632 'uses data source', 'uses ruler', |
|
633 'uses threaded animation', |
|
634 'uses title from previous column', 'value wraps', |
|
635 'version', |
|
636 'vertical( (line scroll|page scroll|ruler view))?', |
|
637 'vertically resizable', 'view', |
|
638 'visible( document rect)?', 'volume', 'width', 'window', |
|
639 'windows menu', 'wraps', 'zoomable', 'zoomed') |
|
640 |
|
641 tokens = { |
|
642 'root': [ |
|
643 (r'\s+', Text), |
|
644 (u'¬\\n', String.Escape), |
|
645 (r"'s\s+", Text), # This is a possessive, consider moving |
|
646 (r'(--|#).*?$', Comment), |
|
647 (r'\(\*', Comment.Multiline, 'comment'), |
|
648 (r'[(){}!,.:]', Punctuation), |
|
649 (u'(«)([^»]+)(»)', |
|
650 bygroups(Text, Name.Builtin, Text)), |
|
651 (r'\b((?:considering|ignoring)\s*)' |
|
652 r'(application responses|case|diacriticals|hyphens|' |
|
653 r'numeric strings|punctuation|white space)', |
|
654 bygroups(Keyword, Name.Builtin)), |
|
655 (u'(-|\\*|\\+|&|≠|>=?|<=?|=|≥|≤|/|÷|\\^)', Operator), |
|
656 (r"\b(%s)\b" % '|'.join(Operators), Operator.Word), |
|
657 (r'^(\s*(?:on|end)\s+)' |
|
658 r'(%s)' % '|'.join(StudioEvents[::-1]), |
|
659 bygroups(Keyword, Name.Function)), |
|
660 (r'^(\s*)(in|on|script|to)(\s+)', bygroups(Text, Keyword, Text)), |
|
661 (r'\b(as )(%s)\b' % '|'.join(Classes), |
|
662 bygroups(Keyword, Name.Class)), |
|
663 (r'\b(%s)\b' % '|'.join(Literals), Name.Constant), |
|
664 (r'\b(%s)\b' % '|'.join(Commands), Name.Builtin), |
|
665 (r'\b(%s)\b' % '|'.join(Control), Keyword), |
|
666 (r'\b(%s)\b' % '|'.join(Declarations), Keyword), |
|
667 (r'\b(%s)\b' % '|'.join(Reserved), Name.Builtin), |
|
668 (r'\b(%s)s?\b' % '|'.join(BuiltIn), Name.Builtin), |
|
669 (r'\b(%s)\b' % '|'.join(HandlerParams), Name.Builtin), |
|
670 (r'\b(%s)\b' % '|'.join(StudioProperties), Name.Attribute), |
|
671 (r'\b(%s)s?\b' % '|'.join(StudioClasses), Name.Builtin), |
|
672 (r'\b(%s)\b' % '|'.join(StudioCommands), Name.Builtin), |
|
673 (r'\b(%s)\b' % '|'.join(References), Name.Builtin), |
|
674 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
675 (r'\b(%s)\b' % Identifiers, Name.Variable), |
|
676 (r'[-+]?(\d+\.\d*|\d*\.\d+)(E[-+][0-9]+)?', Number.Float), |
|
677 (r'[-+]?\d+', Number.Integer), |
|
678 ], |
|
679 'comment': [ |
|
680 ('\(\*', Comment.Multiline, '#push'), |
|
681 ('\*\)', Comment.Multiline, '#pop'), |
|
682 ('[^*(]+', Comment.Multiline), |
|
683 ('[*(]', Comment.Multiline), |
|
684 ], |
|
685 } |
|
686 |
|
687 |
|
688 class RexxLexer(RegexLexer): |
|
689 """ |
|
690 `Rexx <http://www.rexxinfo.org/>`_ is a scripting language available for |
|
691 a wide range of different platforms with its roots found on mainframe |
|
692 systems. It is popular for I/O- and data based tasks and can act as glue |
|
693 language to bind different applications together. |
|
694 |
|
695 .. versionadded:: 2.0 |
|
696 """ |
|
697 name = 'Rexx' |
|
698 aliases = ['rexx', 'arexx'] |
|
699 filenames = ['*.rexx', '*.rex', '*.rx', '*.arexx'] |
|
700 mimetypes = ['text/x-rexx'] |
|
701 flags = re.IGNORECASE |
|
702 |
|
703 tokens = { |
|
704 'root': [ |
|
705 (r'\s', Whitespace), |
|
706 (r'/\*', Comment.Multiline, 'comment'), |
|
707 (r'"', String, 'string_double'), |
|
708 (r"'", String, 'string_single'), |
|
709 (r'[0-9]+(\.[0-9]+)?(e[+-]?[0-9])?', Number), |
|
710 (r'([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b', |
|
711 bygroups(Name.Function, Whitespace, Operator, Whitespace, |
|
712 Keyword.Declaration)), |
|
713 (r'([a-z_]\w*)(\s*)(:)', |
|
714 bygroups(Name.Label, Whitespace, Operator)), |
|
715 include('function'), |
|
716 include('keyword'), |
|
717 include('operator'), |
|
718 (r'[a-z_]\w*', Text), |
|
719 ], |
|
720 'function': [ |
|
721 (words(( |
|
722 'abbrev', 'abs', 'address', 'arg', 'b2x', 'bitand', 'bitor', 'bitxor', |
|
723 'c2d', 'c2x', 'center', 'charin', 'charout', 'chars', 'compare', |
|
724 'condition', 'copies', 'd2c', 'd2x', 'datatype', 'date', 'delstr', |
|
725 'delword', 'digits', 'errortext', 'form', 'format', 'fuzz', 'insert', |
|
726 'lastpos', 'left', 'length', 'linein', 'lineout', 'lines', 'max', |
|
727 'min', 'overlay', 'pos', 'queued', 'random', 'reverse', 'right', 'sign', |
|
728 'sourceline', 'space', 'stream', 'strip', 'substr', 'subword', 'symbol', |
|
729 'time', 'trace', 'translate', 'trunc', 'value', 'verify', 'word', |
|
730 'wordindex', 'wordlength', 'wordpos', 'words', 'x2b', 'x2c', 'x2d', |
|
731 'xrange'), suffix=r'(\s*)(\()'), |
|
732 bygroups(Name.Builtin, Whitespace, Operator)), |
|
733 ], |
|
734 'keyword': [ |
|
735 (r'(address|arg|by|call|do|drop|else|end|exit|for|forever|if|' |
|
736 r'interpret|iterate|leave|nop|numeric|off|on|options|parse|' |
|
737 r'pull|push|queue|return|say|select|signal|to|then|trace|until|' |
|
738 r'while)\b', Keyword.Reserved), |
|
739 ], |
|
740 'operator': [ |
|
741 (r'(-|//|/|\(|\)|\*\*|\*|\\<<|\\<|\\==|\\=|\\>>|\\>|\\|\|\||\||' |
|
742 r'&&|&|%|\+|<<=|<<|<=|<>|<|==|=|><|>=|>>=|>>|>|¬<<|¬<|¬==|¬=|' |
|
743 r'¬>>|¬>|¬|\.|,)', Operator), |
|
744 ], |
|
745 'string_double': [ |
|
746 (r'[^"\n]+', String), |
|
747 (r'""', String), |
|
748 (r'"', String, '#pop'), |
|
749 (r'\n', Text, '#pop'), # Stray linefeed also terminates strings. |
|
750 ], |
|
751 'string_single': [ |
|
752 (r'[^\'\n]', String), |
|
753 (r'\'\'', String), |
|
754 (r'\'', String, '#pop'), |
|
755 (r'\n', Text, '#pop'), # Stray linefeed also terminates strings. |
|
756 ], |
|
757 'comment': [ |
|
758 (r'[^*]+', Comment.Multiline), |
|
759 (r'\*/', Comment.Multiline, '#pop'), |
|
760 (r'\*', Comment.Multiline), |
|
761 ] |
|
762 } |
|
763 |
|
764 _c = lambda s: re.compile(s, re.MULTILINE) |
|
765 _ADDRESS_COMMAND_PATTERN = _c(r'^\s*address\s+command\b') |
|
766 _ADDRESS_PATTERN = _c(r'^\s*address\s+') |
|
767 _DO_WHILE_PATTERN = _c(r'^\s*do\s+while\b') |
|
768 _IF_THEN_DO_PATTERN = _c(r'^\s*if\b.+\bthen\s+do\s*$') |
|
769 _PROCEDURE_PATTERN = _c(r'^\s*([a-z_]\w*)(\s*)(:)(\s*)(procedure)\b') |
|
770 _ELSE_DO_PATTERN = _c(r'\belse\s+do\s*$') |
|
771 _PARSE_ARG_PATTERN = _c(r'^\s*parse\s+(upper\s+)?(arg|value)\b') |
|
772 PATTERNS_AND_WEIGHTS = ( |
|
773 (_ADDRESS_COMMAND_PATTERN, 0.2), |
|
774 (_ADDRESS_PATTERN, 0.05), |
|
775 (_DO_WHILE_PATTERN, 0.1), |
|
776 (_ELSE_DO_PATTERN, 0.1), |
|
777 (_IF_THEN_DO_PATTERN, 0.1), |
|
778 (_PROCEDURE_PATTERN, 0.5), |
|
779 (_PARSE_ARG_PATTERN, 0.2), |
|
780 ) |
|
781 |
|
782 def analyse_text(text): |
|
783 """ |
|
784 Check for inital comment and patterns that distinguish Rexx from other |
|
785 C-like languages. |
|
786 """ |
|
787 if re.search(r'/\*\**\s*rexx', text, re.IGNORECASE): |
|
788 # Header matches MVS Rexx requirements, this is certainly a Rexx |
|
789 # script. |
|
790 return 1.0 |
|
791 elif text.startswith('/*'): |
|
792 # Header matches general Rexx requirements; the source code might |
|
793 # still be any language using C comments such as C++, C# or Java. |
|
794 lowerText = text.lower() |
|
795 result = sum(weight |
|
796 for (pattern, weight) in RexxLexer.PATTERNS_AND_WEIGHTS |
|
797 if pattern.search(lowerText)) + 0.01 |
|
798 return min(result, 1.0) |
|
799 |
|
800 |
|
801 class MOOCodeLexer(RegexLexer): |
|
802 """ |
|
803 For `MOOCode <http://www.moo.mud.org/>`_ (the MOO scripting |
|
804 language). |
|
805 |
|
806 .. versionadded:: 0.9 |
|
807 """ |
|
808 name = 'MOOCode' |
|
809 filenames = ['*.moo'] |
|
810 aliases = ['moocode', 'moo'] |
|
811 mimetypes = ['text/x-moocode'] |
|
812 |
|
813 tokens = { |
|
814 'root': [ |
|
815 # Numbers |
|
816 (r'(0|[1-9][0-9_]*)', Number.Integer), |
|
817 # Strings |
|
818 (r'"(\\\\|\\"|[^"])*"', String), |
|
819 # exceptions |
|
820 (r'(E_PERM|E_DIV)', Name.Exception), |
|
821 # db-refs |
|
822 (r'((#[-0-9]+)|(\$\w+))', Name.Entity), |
|
823 # Keywords |
|
824 (r'\b(if|else|elseif|endif|for|endfor|fork|endfork|while' |
|
825 r'|endwhile|break|continue|return|try' |
|
826 r'|except|endtry|finally|in)\b', Keyword), |
|
827 # builtins |
|
828 (r'(random|length)', Name.Builtin), |
|
829 # special variables |
|
830 (r'(player|caller|this|args)', Name.Variable.Instance), |
|
831 # skip whitespace |
|
832 (r'\s+', Text), |
|
833 (r'\n', Text), |
|
834 # other operators |
|
835 (r'([!;=,{}&|:.\[\]@()<>?]+)', Operator), |
|
836 # function call |
|
837 (r'(\w+)(\()', bygroups(Name.Function, Operator)), |
|
838 # variables |
|
839 (r'(\w+)', Text), |
|
840 ] |
|
841 } |
|
842 |
|
843 |
|
844 class HybrisLexer(RegexLexer): |
|
845 """ |
|
846 For `Hybris <http://www.hybris-lang.org>`_ source code. |
|
847 |
|
848 .. versionadded:: 1.4 |
|
849 """ |
|
850 |
|
851 name = 'Hybris' |
|
852 aliases = ['hybris', 'hy'] |
|
853 filenames = ['*.hy', '*.hyb'] |
|
854 mimetypes = ['text/x-hybris', 'application/x-hybris'] |
|
855 |
|
856 flags = re.MULTILINE | re.DOTALL |
|
857 |
|
858 tokens = { |
|
859 'root': [ |
|
860 # method names |
|
861 (r'^(\s*(?:function|method|operator\s+)+?)' |
|
862 r'([a-zA-Z_]\w*)' |
|
863 r'(\s*)(\()', bygroups(Keyword, Name.Function, Text, Operator)), |
|
864 (r'[^\S\n]+', Text), |
|
865 (r'//.*?\n', Comment.Single), |
|
866 (r'/\*.*?\*/', Comment.Multiline), |
|
867 (r'@[a-zA-Z_][\w.]*', Name.Decorator), |
|
868 (r'(break|case|catch|next|default|do|else|finally|for|foreach|of|' |
|
869 r'unless|if|new|return|switch|me|throw|try|while)\b', Keyword), |
|
870 (r'(extends|private|protected|public|static|throws|function|method|' |
|
871 r'operator)\b', Keyword.Declaration), |
|
872 (r'(true|false|null|__FILE__|__LINE__|__VERSION__|__LIB_PATH__|' |
|
873 r'__INC_PATH__)\b', Keyword.Constant), |
|
874 (r'(class|struct)(\s+)', |
|
875 bygroups(Keyword.Declaration, Text), 'class'), |
|
876 (r'(import|include)(\s+)', |
|
877 bygroups(Keyword.Namespace, Text), 'import'), |
|
878 (words(( |
|
879 'gc_collect', 'gc_mm_items', 'gc_mm_usage', 'gc_collect_threshold', |
|
880 'urlencode', 'urldecode', 'base64encode', 'base64decode', 'sha1', 'crc32', 'sha2', |
|
881 'md5', 'md5_file', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'exp', |
|
882 'fabs', 'floor', 'fmod', 'log', 'log10', 'pow', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', |
|
883 'isint', 'isfloat', 'ischar', 'isstring', 'isarray', 'ismap', 'isalias', 'typeof', |
|
884 'sizeof', 'toint', 'tostring', 'fromxml', 'toxml', 'binary', 'pack', 'load', 'eval', |
|
885 'var_names', 'var_values', 'user_functions', 'dyn_functions', 'methods', 'call', |
|
886 'call_method', 'mknod', 'mkfifo', 'mount', 'umount2', 'umount', 'ticks', 'usleep', |
|
887 'sleep', 'time', 'strtime', 'strdate', 'dllopen', 'dlllink', 'dllcall', 'dllcall_argv', |
|
888 'dllclose', 'env', 'exec', 'fork', 'getpid', 'wait', 'popen', 'pclose', 'exit', 'kill', |
|
889 'pthread_create', 'pthread_create_argv', 'pthread_exit', 'pthread_join', 'pthread_kill', |
|
890 'smtp_send', 'http_get', 'http_post', 'http_download', 'socket', 'bind', 'listen', |
|
891 'accept', 'getsockname', 'getpeername', 'settimeout', 'connect', 'server', 'recv', |
|
892 'send', 'close', 'print', 'println', 'printf', 'input', 'readline', 'serial_open', |
|
893 'serial_fcntl', 'serial_get_attr', 'serial_get_ispeed', 'serial_get_ospeed', |
|
894 'serial_set_attr', 'serial_set_ispeed', 'serial_set_ospeed', 'serial_write', |
|
895 'serial_read', 'serial_close', 'xml_load', 'xml_parse', 'fopen', 'fseek', 'ftell', |
|
896 'fsize', 'fread', 'fwrite', 'fgets', 'fclose', 'file', 'readdir', 'pcre_replace', 'size', |
|
897 'pop', 'unmap', 'has', 'keys', 'values', 'length', 'find', 'substr', 'replace', 'split', |
|
898 'trim', 'remove', 'contains', 'join'), suffix=r'\b'), |
|
899 Name.Builtin), |
|
900 (words(( |
|
901 'MethodReference', 'Runner', 'Dll', 'Thread', 'Pipe', 'Process', |
|
902 'Runnable', 'CGI', 'ClientSocket', 'Socket', 'ServerSocket', |
|
903 'File', 'Console', 'Directory', 'Exception'), suffix=r'\b'), |
|
904 Keyword.Type), |
|
905 (r'"(\\\\|\\"|[^"])*"', String), |
|
906 (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char), |
|
907 (r'(\.)([a-zA-Z_]\w*)', |
|
908 bygroups(Operator, Name.Attribute)), |
|
909 (r'[a-zA-Z_]\w*:', Name.Label), |
|
910 (r'[a-zA-Z_$]\w*', Name), |
|
911 (r'[~^*!%&\[\](){}<>|+=:;,./?\-@]+', Operator), |
|
912 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
913 (r'0x[0-9a-f]+', Number.Hex), |
|
914 (r'[0-9]+L?', Number.Integer), |
|
915 (r'\n', Text), |
|
916 ], |
|
917 'class': [ |
|
918 (r'[a-zA-Z_]\w*', Name.Class, '#pop') |
|
919 ], |
|
920 'import': [ |
|
921 (r'[\w.]+\*?', Name.Namespace, '#pop') |
|
922 ], |
|
923 } |