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