3 pygments.lexers.actionscript |
3 pygments.lexers.actionscript |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for ActionScript and MXML. |
6 Lexers for ActionScript and MXML. |
7 |
7 |
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
35 tokens = { |
35 tokens = { |
36 'root': [ |
36 'root': [ |
37 (r'\s+', Text), |
37 (r'\s+', Text), |
38 (r'//.*?\n', Comment.Single), |
38 (r'//.*?\n', Comment.Single), |
39 (r'/\*.*?\*/', Comment.Multiline), |
39 (r'/\*.*?\*/', Comment.Multiline), |
40 (r'/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex), |
40 (r'/(\\\\|\\[^\\]|[^/\\\n])*/[gim]*', String.Regex), |
41 (r'[~^*!%&<>|+=:;,/?\\-]+', Operator), |
41 (r'[~^*!%&<>|+=:;,/?\\-]+', Operator), |
42 (r'[{}\[\]();.]+', Punctuation), |
42 (r'[{}\[\]();.]+', Punctuation), |
43 (words(( |
43 (words(( |
44 'case', 'default', 'for', 'each', 'in', 'while', 'do', 'break', |
44 'case', 'default', 'for', 'each', 'in', 'while', 'do', 'break', |
45 'return', 'continue', 'if', 'else', 'throw', 'try', 'catch', |
45 'return', 'continue', 'if', 'else', 'throw', 'try', 'catch', |
103 Name.Function), |
103 Name.Function), |
104 (r'[$a-zA-Z_]\w*', Name.Other), |
104 (r'[$a-zA-Z_]\w*', Name.Other), |
105 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
105 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
106 (r'0x[0-9a-f]+', Number.Hex), |
106 (r'0x[0-9a-f]+', Number.Hex), |
107 (r'[0-9]+', Number.Integer), |
107 (r'[0-9]+', Number.Integer), |
108 (r'"(\\\\|\\"|[^"])*"', String.Double), |
108 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), |
109 (r"'(\\\\|\\'|[^'])*'", String.Single), |
109 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single), |
110 ] |
110 ] |
111 } |
111 } |
112 |
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 |
113 |
118 |
114 class ActionScript3Lexer(RegexLexer): |
119 class ActionScript3Lexer(RegexLexer): |
115 """ |
120 """ |
116 For ActionScript 3 source code. |
121 For ActionScript 3 source code. |
117 |
122 |
142 bygroups(Keyword, Text, Name.Namespace, Text)), |
147 bygroups(Keyword, Text, Name.Namespace, Text)), |
143 (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()', |
148 (r'(new)(\s+)(' + typeidentifier + r')(\s*)(\()', |
144 bygroups(Keyword, Text, Keyword.Type, Text, Operator)), |
149 bygroups(Keyword, Text, Keyword.Type, Text, Operator)), |
145 (r'//.*?\n', Comment.Single), |
150 (r'//.*?\n', Comment.Single), |
146 (r'/\*.*?\*/', Comment.Multiline), |
151 (r'/\*.*?\*/', Comment.Multiline), |
147 (r'/(\\\\|\\/|[^\n])*/[gisx]*', String.Regex), |
152 (r'/(\\\\|\\[^\\]|[^\\\n])*/[gisx]*', String.Regex), |
148 (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)), |
153 (r'(\.)(' + identifier + r')', bygroups(Operator, Name.Attribute)), |
149 (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' |
154 (r'(case|default|for|each|in|while|do|break|return|continue|if|else|' |
150 r'throw|try|catch|with|new|typeof|arguments|instanceof|this|' |
155 r'throw|try|catch|with|new|typeof|arguments|instanceof|this|' |
151 r'switch|import|include|as|is)\b', |
156 r'switch|import|include|as|is)\b', |
152 Keyword), |
157 Keyword), |
162 r'unescape)\b', Name.Function), |
167 r'unescape)\b', Name.Function), |
163 (identifier, Name), |
168 (identifier, Name), |
164 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
169 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
165 (r'0x[0-9a-f]+', Number.Hex), |
170 (r'0x[0-9a-f]+', Number.Hex), |
166 (r'[0-9]+', Number.Integer), |
171 (r'[0-9]+', Number.Integer), |
167 (r'"(\\\\|\\"|[^"])*"', String.Double), |
172 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), |
168 (r"'(\\\\|\\'|[^'])*'", String.Single), |
173 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single), |
169 (r'[~^*!%&<>|+=:;,/?\\{}\[\]().-]+', Operator), |
174 (r'[~^*!%&<>|+=:;,/?\\{}\[\]().-]+', Operator), |
170 ], |
175 ], |
171 'funcparams': [ |
176 'funcparams': [ |
172 (r'\s+', Text), |
177 (r'\s+', Text), |
173 (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' + |
178 (r'(\s*)(\.\.\.)?(' + identifier + r')(\s*)(:)(\s*)(' + |