Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

# -*- coding: utf-8 -*- 

""" 

    pygments.lexers.actionscript 

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 

    Lexers for ActionScript and MXML. 

 

    :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. 

    :license: BSD, see LICENSE for details. 

""" 

 

import re 

 

from pygments.lexer import RegexLexer, bygroups, using, this, words, default 

from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

    Number, Punctuation 

 

__all__ = ['ActionScriptLexer', 'ActionScript3Lexer', 'MxmlLexer'] 

 

 

class ActionScriptLexer(RegexLexer): 

    """ 

    For ActionScript source code. 

 

    .. versionadded:: 0.9 

    """ 

 

    name = 'ActionScript' 

    aliases = ['as', 'actionscript'] 

    filenames = ['*.as'] 

    mimetypes = ['application/x-actionscript', 'text/x-actionscript', 

                 'text/actionscript'] 

 

    flags = re.DOTALL 

    tokens = { 

        'root': [ 

            (r'\s+', Text), 

            (r'//.*?\n', Comment.Single), 

            (r'/\*.*?\*/', Comment.Multiline), 

            (r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex), 

            (r'[~^*!%&<>|+=:;,/?\\-]+', Operator), 

            (r'[{}\[\]();.]+', Punctuation), 

            (words(( 

                'case', 'default', 'for', 'each', 'in', 'while', 'do', 'break', 

                'return', 'continue', 'if', 'else', 'throw', 'try', 'catch', 

                'var', 'with', 'new', 'typeof', 'arguments', 'instanceof', 'this', 

                'switch'), suffix=r'\b'), 

             Keyword), 

            (words(( 

                'class', 'public', 'final', 'internal', 'native', 'override', 'private', 

                'protected', 'static', 'import', 'extends', 'implements', 'interface', 

                'intrinsic', 'return', 'super', 'dynamic', 'function', 'const', 'get', 

                'namespace', 'package', 'set'), suffix=r'\b'), 

             Keyword.Declaration), 

            (r'(true|false|null|NaN|Infinity|-Infinity|undefined|Void)\b', 

             Keyword.Constant), 

            (words(( 

                'Accessibility', 'AccessibilityProperties', 'ActionScriptVersion', 

                'ActivityEvent', 'AntiAliasType', 'ApplicationDomain', 'AsBroadcaster', 'Array', 

                'AsyncErrorEvent', 'AVM1Movie', 'BevelFilter', 'Bitmap', 'BitmapData', 

                'BitmapDataChannel', 'BitmapFilter', 'BitmapFilterQuality', 'BitmapFilterType', 

                'BlendMode', 'BlurFilter', 'Boolean', 'ByteArray', 'Camera', 'Capabilities', 'CapsStyle', 

                'Class', 'Color', 'ColorMatrixFilter', 'ColorTransform', 'ContextMenu', 

                'ContextMenuBuiltInItems', 'ContextMenuEvent', 'ContextMenuItem', 

                'ConvultionFilter', 'CSMSettings', 'DataEvent', 'Date', 'DefinitionError', 

                'DeleteObjectSample', 'Dictionary', 'DisplacmentMapFilter', 'DisplayObject', 

                'DisplacmentMapFilterMode', 'DisplayObjectContainer', 'DropShadowFilter', 

                'Endian', 'EOFError', 'Error', 'ErrorEvent', 'EvalError', 'Event', 'EventDispatcher', 

                'EventPhase', 'ExternalInterface', 'FileFilter', 'FileReference', 

                'FileReferenceList', 'FocusDirection', 'FocusEvent', 'Font', 'FontStyle', 'FontType', 

                'FrameLabel', 'FullScreenEvent', 'Function', 'GlowFilter', 'GradientBevelFilter', 

                'GradientGlowFilter', 'GradientType', 'Graphics', 'GridFitType', 'HTTPStatusEvent', 

                'IBitmapDrawable', 'ID3Info', 'IDataInput', 'IDataOutput', 'IDynamicPropertyOutput' 

                'IDynamicPropertyWriter', 'IEventDispatcher', 'IExternalizable', 

                'IllegalOperationError', 'IME', 'IMEConversionMode', 'IMEEvent', 'int', 

                'InteractiveObject', 'InterpolationMethod', 'InvalidSWFError', 'InvokeEvent', 

                'IOError', 'IOErrorEvent', 'JointStyle', 'Key', 'Keyboard', 'KeyboardEvent', 'KeyLocation', 

                'LineScaleMode', 'Loader', 'LoaderContext', 'LoaderInfo', 'LoadVars', 'LocalConnection', 

                'Locale', 'Math', 'Matrix', 'MemoryError', 'Microphone', 'MorphShape', 'Mouse', 'MouseEvent', 

                'MovieClip', 'MovieClipLoader', 'Namespace', 'NetConnection', 'NetStatusEvent', 

                'NetStream', 'NewObjectSample', 'Number', 'Object', 'ObjectEncoding', 'PixelSnapping', 

                'Point', 'PrintJob', 'PrintJobOptions', 'PrintJobOrientation', 'ProgressEvent', 'Proxy', 

                'QName', 'RangeError', 'Rectangle', 'ReferenceError', 'RegExp', 'Responder', 'Sample', 

                'Scene', 'ScriptTimeoutError', 'Security', 'SecurityDomain', 'SecurityError', 

                'SecurityErrorEvent', 'SecurityPanel', 'Selection', 'Shape', 'SharedObject', 

                'SharedObjectFlushStatus', 'SimpleButton', 'Socket', 'Sound', 'SoundChannel', 

                'SoundLoaderContext', 'SoundMixer', 'SoundTransform', 'SpreadMethod', 'Sprite', 

                'StackFrame', 'StackOverflowError', 'Stage', 'StageAlign', 'StageDisplayState', 

                'StageQuality', 'StageScaleMode', 'StaticText', 'StatusEvent', 'String', 'StyleSheet', 

                'SWFVersion', 'SyncEvent', 'SyntaxError', 'System', 'TextColorType', 'TextField', 

                'TextFieldAutoSize', 'TextFieldType', 'TextFormat', 'TextFormatAlign', 

                'TextLineMetrics', 'TextRenderer', 'TextSnapshot', 'Timer', 'TimerEvent', 'Transform', 

                'TypeError', 'uint', 'URIError', 'URLLoader', 'URLLoaderDataFormat', 'URLRequest', 

                'URLRequestHeader', 'URLRequestMethod', 'URLStream', 'URLVariabeles', 'VerifyError', 

                'Video', 'XML', 'XMLDocument', 'XMLList', 'XMLNode', 'XMLNodeType', 'XMLSocket', 

                'XMLUI'), suffix=r'\b'), 

             Name.Builtin), 

            (words(( 

                'decodeURI', 'decodeURIComponent', 'encodeURI', 'escape', 'eval', 'isFinite', 'isNaN', 

                'isXMLName', 'clearInterval', 'fscommand', 'getTimer', 'getURL', 'getVersion', 

                'parseFloat', 'parseInt', 'setInterval', 'trace', 'updateAfterEvent', 

                'unescape'), suffix=r'\b'), 

             Name.Function), 

            (r'[$a-zA-Z_]\w*', Name.Other), 

            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

            (r'0x[0-9a-f]+', Number.Hex), 

            (r'[0-9]+', Number.Integer), 

            (r'"(\\\\|\\"|[^"])*"', String.Double), 

            (r"'(\\\\|\\'|[^'])*'", String.Single), 

        ] 

    } 

 

 

class ActionScript3Lexer(RegexLexer): 

    """ 

    For ActionScript 3 source code. 

 

    .. versionadded:: 0.11 

    """ 

 

    name = 'ActionScript 3' 

    aliases = ['as3', 'actionscript3'] 

    filenames = ['*.as'] 

    mimetypes = ['application/x-actionscript3', 'text/x-actionscript3', 

                 'text/actionscript3'] 

 

    identifier = r'[$a-zA-Z_]\w*' 

    typeidentifier = identifier + '(?:\.<\w+>)?' 

 

    flags = re.DOTALL | re.MULTILINE 

    tokens = { 

        'root': [ 

            (r'\s+', Text), 

            (r'(function\s+)(' + identifier + r')(\s*)(\()', 

             bygroups(Keyword.Declaration, Name.Function, Text, Operator), 

             'funcparams'), 

            (r'(var|const)(\s+)(' + identifier + r')(\s*)(:)(\s*)(' + 

             typeidentifier + r')', 

             bygroups(Keyword.Declaration, Text, Name, Text, Punctuation, Text, 

                      Keyword.Type)), 

            (r'(import|package)(\s+)((?:' + identifier + r'|\.)+)(\s*)', 

             bygroups(Keyword, Text, Name.Namespace, Text)), 

            (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()', 

             bygroups(Keyword, Text, Keyword.Type, Text, Operator)), 

            (r'//.*?\n', Comment.Single), 

            (r'/\*.*?\*/', Comment.Multiline), 

            (r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex), 

            (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)), 

            (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' 

             r'throw|try|catch|with|new|typeof|arguments|instanceof|this|' 

             r'switch|import|include|as|is)\b', 

             Keyword), 

            (r'(class|public|final|internal|native|override|private|protected|' 

             r'static|import|extends|implements|interface|intrinsic|return|super|' 

             r'dynamic|function|const|get|namespace|package|set)\b', 

             Keyword.Declaration), 

            (r'(true|false|null|NaN|Infinity|-Infinity|undefined|void)\b', 

             Keyword.Constant), 

            (r'(decodeURI|decodeURIComponent|encodeURI|escape|eval|isFinite|isNaN|' 

             r'isXMLName|clearInterval|fscommand|getTimer|getURL|getVersion|' 

             r'isFinite|parseFloat|parseInt|setInterval|trace|updateAfterEvent|' 

             r'unescape)\b', Name.Function), 

            (identifier, Name), 

            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

            (r'0x[0-9a-f]+', Number.Hex), 

            (r'[0-9]+', Number.Integer), 

            (r'"(\\\\|\\"|[^"])*"', String.Double), 

            (r"'(\\\\|\\'|[^'])*'", String.Single), 

            (r'[~^*!%&<>|+=:;,/?\\{}\[\]().-]+', Operator), 

        ], 

        'funcparams': [ 

            (r'\s+', Text), 

            (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' + 

             typeidentifier + r'|\*)(\s*)', 

             bygroups(Text, Punctuation, Name, Text, Operator, Text, 

                      Keyword.Type, Text), 'defval'), 

            (r'\)', Operator, 'type') 

        ], 

        'type': [ 

            (r'(\s*)(:)(\s*)(' + typeidentifier + r'|\*)', 

             bygroups(Text, Operator, Text, Keyword.Type), '#pop:2'), 

            (r'\s+', Text, '#pop:2'), 

            default('#pop:2') 

        ], 

        'defval': [ 

            (r'(=)(\s*)([^(),]+)(\s*)(,?)', 

             bygroups(Operator, Text, using(this), Text, Operator), '#pop'), 

            (r',', Operator, '#pop'), 

            default('#pop') 

        ] 

    } 

 

    def analyse_text(text): 

        if re.match(r'\w+\s*:\s*\w', text): 

            return 0.3 

        return 0 

 

 

class MxmlLexer(RegexLexer): 

    """ 

    For MXML markup. 

    Nested AS3 in <script> tags is highlighted by the appropriate lexer. 

 

    .. versionadded:: 1.1 

    """ 

    flags = re.MULTILINE | re.DOTALL 

    name = 'MXML' 

    aliases = ['mxml'] 

    filenames = ['*.mxml'] 

    mimetimes = ['text/xml', 'application/xml'] 

 

    tokens = { 

        'root': [ 

            ('[^<&]+', Text), 

            (r'&\S*?;', Name.Entity), 

            (r'(\<\!\[CDATA\[)(.*?)(\]\]\>)', 

             bygroups(String, using(ActionScript3Lexer), String)), 

            ('<!--', Comment, 'comment'), 

            (r'<\?.*?\?>', Comment.Preproc), 

            ('<![^>]*>', Comment.Preproc), 

            (r'<\s*[\w:.-]+', Name.Tag, 'tag'), 

            (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), 

        ], 

        'comment': [ 

            ('[^-]+', Comment), 

            ('-->', Comment, '#pop'), 

            ('-', Comment), 

        ], 

        'tag': [ 

            (r'\s+', Text), 

            (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), 

            (r'/?\s*>', Name.Tag, '#pop'), 

        ], 

        'attr': [ 

            ('\s+', Text), 

            ('".*?"', String, '#pop'), 

            ("'.*?'", String, '#pop'), 

            (r'[^\s>]+', String, '#pop'), 

        ], 

    }