eric6/ThirdParty/Pygments/pygments/lexers/actionscript.py

changeset 8258
82b608e352ec
parent 8257
28146736bbfc
child 8259
2bbec88047dd
equal deleted inserted replaced
8257:28146736bbfc 8258:82b608e352ec
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.actionscript
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 Lexers for ActionScript and MXML.
7
8 :copyright: Copyright 2006-2021 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, bygroups, using, this, words, default
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 Number, Punctuation
17
18 __all__ = ['ActionScriptLexer', 'ActionScript3Lexer', 'MxmlLexer']
19
20
21 class ActionScriptLexer(RegexLexer):
22 """
23 For ActionScript source code.
24
25 .. versionadded:: 0.9
26 """
27
28 name = 'ActionScript'
29 aliases = ['as', 'actionscript']
30 filenames = ['*.as']
31 mimetypes = ['application/x-actionscript', 'text/x-actionscript',
32 'text/actionscript']
33
34 flags = re.DOTALL
35 tokens = {
36 'root': [
37 (r'\s+', Text),
38 (r'//.*?\n', Comment.Single),
39 (r'/\*.*?\*/', Comment.Multiline),
40 (r'/(\\\\|\\[^\\]|[^/\\\n])*/[gim]*', String.Regex),
41 (r'[~^*!%&<>|+=:;,/?\\-]+', Operator),
42 (r'[{}\[\]();.]+', Punctuation),
43 (words((
44 'case', 'default', 'for', 'each', 'in', 'while', 'do', 'break',
45 'return', 'continue', 'if', 'else', 'throw', 'try', 'catch',
46 'var', 'with', 'new', 'typeof', 'arguments', 'instanceof', 'this',
47 'switch'), suffix=r'\b'),
48 Keyword),
49 (words((
50 'class', 'public', 'final', 'internal', 'native', 'override', 'private',
51 'protected', 'static', 'import', 'extends', 'implements', 'interface',
52 'intrinsic', 'return', 'super', 'dynamic', 'function', 'const', 'get',
53 'namespace', 'package', 'set'), suffix=r'\b'),
54 Keyword.Declaration),
55 (r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b',
56 Keyword.Constant),
57 (words((
58 'Accessibility', 'AccessibilityProperties', 'ActionScriptVersion',
59 'ActivityEvent', 'AntiAliasType', 'ApplicationDomain', 'AsBroadcaster', 'Array',
60 'AsyncErrorEvent', 'AVM1Movie', 'BevelFilter', 'Bitmap', 'BitmapData',
61 'BitmapDataChannel', 'BitmapFilter', 'BitmapFilterQuality', 'BitmapFilterType',
62 'BlendMode', 'BlurFilter', 'Boolean', 'ByteArray', 'Camera', 'Capabilities', 'CapsStyle',
63 'Class', 'Color', 'ColorMatrixFilter', 'ColorTransform', 'ContextMenu',
64 'ContextMenuBuiltInItems', 'ContextMenuEvent', 'ContextMenuItem',
65 'ConvultionFilter', 'CSMSettings', 'DataEvent', 'Date', 'DefinitionError',
66 'DeleteObjectSample', 'Dictionary', 'DisplacmentMapFilter', 'DisplayObject',
67 'DisplacmentMapFilterMode', 'DisplayObjectContainer', 'DropShadowFilter',
68 'Endian', 'EOFError', 'Error', 'ErrorEvent', 'EvalError', 'Event', 'EventDispatcher',
69 'EventPhase', 'ExternalInterface', 'FileFilter', 'FileReference',
70 'FileReferenceList', 'FocusDirection', 'FocusEvent', 'Font', 'FontStyle', 'FontType',
71 'FrameLabel', 'FullScreenEvent', 'Function', 'GlowFilter', 'GradientBevelFilter',
72 'GradientGlowFilter', 'GradientType', 'Graphics', 'GridFitType', 'HTTPStatusEvent',
73 'IBitmapDrawable', 'ID3Info', 'IDataInput', 'IDataOutput', 'IDynamicPropertyOutput'
74 'IDynamicPropertyWriter', 'IEventDispatcher', 'IExternalizable',
75 'IllegalOperationError', 'IME', 'IMEConversionMode', 'IMEEvent', 'int',
76 'InteractiveObject', 'InterpolationMethod', 'InvalidSWFError', 'InvokeEvent',
77 'IOError', 'IOErrorEvent', 'JointStyle', 'Key', 'Keyboard', 'KeyboardEvent', 'KeyLocation',
78 'LineScaleMode', 'Loader', 'LoaderContext', 'LoaderInfo', 'LoadVars', 'LocalConnection',
79 'Locale', 'Math', 'Matrix', 'MemoryError', 'Microphone', 'MorphShape', 'Mouse', 'MouseEvent',
80 'MovieClip', 'MovieClipLoader', 'Namespace', 'NetConnection', 'NetStatusEvent',
81 'NetStream', 'NewObjectSample', 'Number', 'Object', 'ObjectEncoding', 'PixelSnapping',
82 'Point', 'PrintJob', 'PrintJobOptions', 'PrintJobOrientation', 'ProgressEvent', 'Proxy',
83 'QName', 'RangeError', 'Rectangle', 'ReferenceError', 'RegExp', 'Responder', 'Sample',
84 'Scene', 'ScriptTimeoutError', 'Security', 'SecurityDomain', 'SecurityError',
85 'SecurityErrorEvent', 'SecurityPanel', 'Selection', 'Shape', 'SharedObject',
86 'SharedObjectFlushStatus', 'SimpleButton', 'Socket', 'Sound', 'SoundChannel',
87 'SoundLoaderContext', 'SoundMixer', 'SoundTransform', 'SpreadMethod', 'Sprite',
88 'StackFrame', 'StackOverflowError', 'Stage', 'StageAlign', 'StageDisplayState',
89 'StageQuality', 'StageScaleMode', 'StaticText', 'StatusEvent', 'String', 'StyleSheet',
90 'SWFVersion', 'SyncEvent', 'SyntaxError', 'System', 'TextColorType', 'TextField',
91 'TextFieldAutoSize', 'TextFieldType', 'TextFormat', 'TextFormatAlign',
92 'TextLineMetrics', 'TextRenderer', 'TextSnapshot', 'Timer', 'TimerEvent', 'Transform',
93 'TypeError', 'uint', 'URIError', 'URLLoader', 'URLLoaderDataFormat', 'URLRequest',
94 'URLRequestHeader', 'URLRequestMethod', 'URLStream', 'URLVariabeles', 'VerifyError',
95 'Video', 'XML', 'XMLDocument', 'XMLList', 'XMLNode', 'XMLNodeType', 'XMLSocket',
96 'XMLUI'), suffix=r'\b'),
97 Name.Builtin),
98 (words((
99 'decodeURI', 'decodeURIComponent', 'encodeURI', 'escape', 'eval', 'isFinite', 'isNaN',
100 'isXMLName', 'clearInterval', 'fscommand', 'getTimer', 'getURL', 'getVersion',
101 'parseFloat', 'parseInt', 'setInterval', 'trace', 'updateAfterEvent',
102 'unescape'), suffix=r'\b'),
103 Name.Function),
104 (r'[$a-zA-Z_]\w*', Name.Other),
105 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
106 (r'0x[0-9a-f]+', Number.Hex),
107 (r'[0-9]+', Number.Integer),
108 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
109 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
110 ]
111 }
112
113 def analyse_text(text):
114 """This is only used to disambiguate between ActionScript and
115 ActionScript3. We return 0 here; the ActionScript3 lexer will match
116 AS3 variable definitions and that will hopefully suffice."""
117 return 0
118
119 class ActionScript3Lexer(RegexLexer):
120 """
121 For ActionScript 3 source code.
122
123 .. versionadded:: 0.11
124 """
125
126 name = 'ActionScript 3'
127 aliases = ['as3', 'actionscript3']
128 filenames = ['*.as']
129 mimetypes = ['application/x-actionscript3', 'text/x-actionscript3',
130 'text/actionscript3']
131
132 identifier = r'[$a-zA-Z_]\w*'
133 typeidentifier = identifier + r'(?:\.<\w+>)?'
134
135 flags = re.DOTALL | re.MULTILINE
136 tokens = {
137 'root': [
138 (r'\s+', Text),
139 (r'(function\s+)(' + identifier + r')(\s*)(\()',
140 bygroups(Keyword.Declaration, Name.Function, Text, Operator),
141 'funcparams'),
142 (r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' +
143 typeidentifier + r')',
144 bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text,
145 Keyword.Type)),
146 (r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)',
147 bygroups(Keyword, Text, Name.Namespace, Text)),
148 (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()',
149 bygroups(Keyword, Text, Keyword.Type, Text, Operator)),
150 (r'//.*?\n', Comment.Single),
151 (r'/\*.*?\*/', Comment.Multiline),
152 (r'/(\\\\|\\[^\\]|[^\\\n])*/[gisx]*', String.Regex),
153 (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)),
154 (r'(case|default|for|each|in|while|do|break|return|continue|if|else|'
155 r'throw|try|catch|with|new|typeof|arguments|instanceof|this|'
156 r'switch|import|include|as|is)\b',
157 Keyword),
158 (r'(class|public|final|internal|native|override|private|protected|'
159 r'static|import|extends|implements|interface|intrinsic|return|super|'
160 r'dynamic|function|const|get|namespace|package|set)\b',
161 Keyword.Declaration),
162 (r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b',
163 Keyword.Constant),
164 (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'
165 r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'
166 r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'
167 r'unescape)\b', Name.Function),
168 (identifier, Name),
169 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
170 (r'0x[0-9a-f]+', Number.Hex),
171 (r'[0-9]+', Number.Integer),
172 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
173 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),
174 (r'[~^*!%&<>|+=:;,/?\\{}\[\]().-]+', Operator),
175 ],
176 'funcparams': [
177 (r'\s+', Text),
178 (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' +
179 typeidentifier + r'|\*)(\s*)',
180 bygroups(Text, Punctuation, Name, Text, Operator, Text,
181 Keyword.Type, Text), 'defval'),
182 (r'\)', Operator, 'type')
183 ],
184 'type': [
185 (r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)',
186 bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'),
187 (r'\s+', Text, '#pop:2'),
188 default('#pop:2')
189 ],
190 'defval': [
191 (r'(=)(\s*)([^(),]+)(\s*)(,?)',
192 bygroups(Operator, Text, using(this), Text, Operator), '#pop'),
193 (r',', Operator, '#pop'),
194 default('#pop')
195 ]
196 }
197
198 def analyse_text(text):
199 if re.match(r'\w+\s*:\s*\w', text):
200 return 0.3
201 return 0
202
203
204 class MxmlLexer(RegexLexer):
205 """
206 For MXML markup.
207 Nested AS3 in <script> tags is highlighted by the appropriate lexer.
208
209 .. versionadded:: 1.1
210 """
211 flags = re.MULTILINE | re.DOTALL
212 name = 'MXML'
213 aliases = ['mxml']
214 filenames = ['*.mxml']
215 mimetimes = ['text/xml', 'application/xml']
216
217 tokens = {
218 'root': [
219 ('[^<&]+', Text),
220 (r'&\S*?;', Name.Entity),
221 (r'(\<\!\[CDATA\[)(.*?)(\]\]\>)',
222 bygroups(String, using(ActionScript3Lexer), String)),
223 ('<!--', Comment, 'comment'),
224 (r'<\?.*?\?>', Comment.Preproc),
225 ('<![^>]*>', Comment.Preproc),
226 (r'<\s*[\w:.-]+', Name.Tag, 'tag'),
227 (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag),
228 ],
229 'comment': [
230 ('[^-]+', Comment),
231 ('-->', Comment, '#pop'),
232 ('-', Comment),
233 ],
234 'tag': [
235 (r'\s+', Text),
236 (r'[\w.:-]+\s*=', Name.Attribute, 'attr'),
237 (r'/?\s*>', Name.Tag, '#pop'),
238 ],
239 'attr': [
240 (r'\s+', Text),
241 ('".*?"', String, '#pop'),
242 ("'.*?'", String, '#pop'),
243 (r'[^\s>]+', String, '#pop'),
244 ],
245 }

eric ide

mercurial