Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
actionscript.py244 linesDownload Raw Back to lexers
1"""2    pygments.lexers.actionscript3    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for ActionScript and MXML.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11import re12 13from pygments.lexer import RegexLexer, bygroups, using, this, words, default14from pygments.token import Text, Comment, Operator, Keyword, Name, String, \15    Number, Punctuation, Whitespace16 17__all__ = ['ActionScriptLexer', 'ActionScript3Lexer', 'MxmlLexer']18 19 20class ActionScriptLexer(RegexLexer):21    """22    For ActionScript source code.23    """24 25    name = 'ActionScript'26    aliases = ['actionscript', 'as']27    filenames = ['*.as']28    mimetypes = ['application/x-actionscript', 'text/x-actionscript',29                 'text/actionscript']30    url = 'https://en.wikipedia.org/wiki/ActionScript'31    version_added = '0.9'32 33    flags = re.DOTALL34    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    }111 112    def analyse_text(text):113        """This is only used to disambiguate between ActionScript and114        ActionScript3. We return 0 here; the ActionScript3 lexer will match115        AS3 variable definitions and that will hopefully suffice."""116        return 0117 118class ActionScript3Lexer(RegexLexer):119    """120    For ActionScript 3 source code.121    """122 123    name = 'ActionScript 3'124    url = 'https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html'125    aliases = ['actionscript3', 'as3']126    filenames = ['*.as']127    mimetypes = ['application/x-actionscript3', 'text/x-actionscript3',128                 'text/actionscript3']129    version_added = '0.11'130 131    identifier = r'[$a-zA-Z_]\w*'132    typeidentifier = identifier + r'(?:\.<\w+>)?'133 134    flags = re.DOTALL | re.MULTILINE135    tokens = {136        'root': [137            (r'\s+', Whitespace),138            (r'(function\s+)(' + identifier + r')(\s*)(\()',139             bygroups(Keyword.Declaration, Name.Function, Text, Operator),140             'funcparams'),141            (r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' +142             typeidentifier + r')',143             bygroups(Keyword.Declaration, Whitespace, Name, Whitespace, Punctuation, Whitespace,144                      Keyword.Type)),145            (r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)',146             bygroups(Keyword, Whitespace, Name.Namespace, Whitespace)),147            (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()',148             bygroups(Keyword, Whitespace, Keyword.Type, Whitespace, Operator)),149            (r'//.*?\n', Comment.Single),150            (r'/\*.*?\*/', Comment.Multiline),151            (r'/(\\\\|\\[^\\]|[^\\\n])*/[gisx]*', String.Regex),152            (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)),153            (r'(case|default|for|each|in|while|do|break|return|continue|if|else|'154             r'throw|try|catch|with|new|typeof|arguments|instanceof|this|'155             r'switch|import|include|as|is)\b',156             Keyword),157            (r'(class|public|final|internal|native|override|private|protected|'158             r'static|import|extends|implements|interface|intrinsic|return|super|'159             r'dynamic|function|const|get|namespace|package|set)\b',160             Keyword.Declaration),161            (r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b',162             Keyword.Constant),163            (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|'164             r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|'165             r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|'166             r'unescape)\b', Name.Function),167            (identifier, Name),168            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),169            (r'0x[0-9a-f]+', Number.Hex),170            (r'[0-9]+', Number.Integer),171            (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),172            (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single),173            (r'[~^*!%&<>|+=:;,/?\\{}\[\]().-]+', Operator),174        ],175        'funcparams': [176            (r'\s+', Whitespace),177            (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' +178             typeidentifier + r'|\*)(\s*)',179             bygroups(Whitespace, Punctuation, Name, Whitespace, Operator, Whitespace,180                      Keyword.Type, Whitespace), 'defval'),181            (r'\)', Operator, 'type')182        ],183        'type': [184            (r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)',185             bygroups(Whitespace, Operator, Whitespace, Keyword.Type), '#pop:2'),186            (r'\s+', Text, '#pop:2'),187            default('#pop:2')188        ],189        'defval': [190            (r'(=)(\s*)([^(),]+)(\s*)(,?)',191             bygroups(Operator, Whitespace, using(this), Whitespace, Operator), '#pop'),192            (r',', Operator, '#pop'),193            default('#pop')194        ]195    }196 197    def analyse_text(text):198        if re.match(r'\w+\s*:\s*\w', text):199            return 0.3200        return 0201 202 203class MxmlLexer(RegexLexer):204    """205    For MXML markup.206    Nested AS3 in <script> tags is highlighted by the appropriate lexer.207    """208    flags = re.MULTILINE | re.DOTALL209    name = 'MXML'210    aliases = ['mxml']211    filenames = ['*.mxml']212    url = 'https://en.wikipedia.org/wiki/MXML'213    version_added = '1.1'214 215    tokens = {216        'root': [217            ('[^<&]+', Text),218            (r'&\S*?;', Name.Entity),219            (r'(\<\!\[CDATA\[)(.*?)(\]\]\>)',220             bygroups(String, using(ActionScript3Lexer), String)),221            ('<!--', Comment, 'comment'),222            (r'<\?.*?\?>', Comment.Preproc),223            ('<![^>]*>', Comment.Preproc),224            (r'<\s*[\w:.-]+', Name.Tag, 'tag'),225            (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag),226        ],227        'comment': [228            ('[^-]+', Comment),229            ('-->', Comment, '#pop'),230            ('-', Comment),231        ],232        'tag': [233            (r'\s+', Whitespace),234            (r'[\w.:-]+\s*=', Name.Attribute, 'attr'),235            (r'/?\s*>', Name.Tag, '#pop'),236        ],237        'attr': [238            (r'\s+', Whitespace),239            ('".*?"', String, '#pop'),240            ("'.*?'", String, '#pop'),241            (r'[^\s>]+', String, '#pop'),242        ],243    }244 
codekingpro/portable-devtools · Team Ai