1 | # -*- coding: utf-8 -*- |
---|
2 | """ |
---|
3 | pygments.lexers.dotnet |
---|
4 | ~~~~~~~~~~~~~~~~~~~~~~ |
---|
5 | |
---|
6 | Lexers for .net languages. |
---|
7 | |
---|
8 | :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. |
---|
9 | :license: BSD, see LICENSE for details. |
---|
10 | """ |
---|
11 | import re |
---|
12 | |
---|
13 | from pygments.lexer import Lexer, RegexLexer, DelegatingLexer, bygroups, using, this, include |
---|
14 | from pygments.token import Punctuation, \ |
---|
15 | Text, Comment, Generic, Operator, Keyword, Name, String, Number, Literal, Other |
---|
16 | from pygments.util import get_choice_opt |
---|
17 | from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \ |
---|
18 | make_analysator |
---|
19 | from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \ |
---|
20 | make_analysator |
---|
21 | from pygments import unistring as uni |
---|
22 | |
---|
23 | from pygments.lexers.web import XmlLexer |
---|
24 | |
---|
25 | __all__ = ['CobraLexer', 'CSharpLexer', 'BooLexer', 'VbNetLexer', 'CSharpAspxLexer', |
---|
26 | 'VbNetAspxLexer'] |
---|
27 | |
---|
28 | |
---|
29 | def _escape(st): |
---|
30 | return st.replace(u'\\', ur'\\').replace(u'-', ur'\-').\ |
---|
31 | replace(u'[', ur'\[').replace(u']', ur'\]') |
---|
32 | |
---|
33 | class CobraLexer(RegexLexer): |
---|
34 | """ |
---|
35 | For `Cobra <http://www.cobra-language.org/>`_ source code. |
---|
36 | """ |
---|
37 | |
---|
38 | def __init__(self, **options): |
---|
39 | Lexer.__init__(self, **options) |
---|
40 | self.tabsize = get_int_opt(options, 'tabsize', 4) |
---|
41 | |
---|
42 | name = 'Cobra' |
---|
43 | aliases = ['cobra'] |
---|
44 | filenames = ['*.cobra'] |
---|
45 | mimetypes = ['text/x-cobra'] |
---|
46 | flags = re.X | re.M | re.S |
---|
47 | |
---|
48 | tokens = { |
---|
49 | 'root': [ |
---|
50 | (r'\s*"""', Comment.Multiline, 'doublequote-multiline-comment'), |
---|
51 | (r"\s*'''", Comment.Multiline, 'singlequote-multiline-comment'), |
---|
52 | (r'/\#', Comment.Multiline, 'arbitrary-comment'), |
---|
53 | (r'\s*\#\s*', Comment, 'singleline-comment'), |
---|
54 | (r'^\s*(@args\s+) (?:\-([^\s]+?) (:) ([^:]+?))+?$', bygroups(Name.Decorator, Name.Label, Text, Name.Variable)), |
---|
55 | (r'[]{}:@($!),.;[]', Punctuation), |
---|
56 | include('operators'), |
---|
57 | (r'^(use|namespace) (\s+) ([\w_.]+)', bygroups(Keyword, Text, Name.Namespace)), |
---|
58 | (r'(cue|def|sig) (\s+) ([a-zA-Z_][\w_]*)', |
---|
59 | bygroups(Keyword, Text, Name.Function)), |
---|
60 | (r'(pro|get|set) (\s+) ([A-Za-z_][\w_]+) (\s*?)', bygroups(Keyword, Text, Name.Function, Text)), |
---|
61 | (r'(class|enum|interface|mixin|struct|has|implements|inherits) (\s+) ([a-zA-Z_][\w_.]*) (<) (of\s+)', |
---|
62 | bygroups(Keyword, Text, Name.Class, Punctuation, Keyword), 'generics'), |
---|
63 | (r'(class|enum|interface|mixin|struct) (\s+) ([a-zA-Z_][\w_.]*)', bygroups(Keyword, Text, Name.Class)), |
---|
64 | (r'^(\s+) (var) (\s+) ([a-zA-Z_][\w_]*?) (\s*)(=)?(\s*)', |
---|
65 | bygroups(Text, Keyword, Text, Name.Variable, Text, Operator, Text)), |
---|
66 | (r'(\s*) (as|to) (inout|out|vari)? (\s+) ([A-Za-z][\w_.]*) (<) (of) (\s+)', |
---|
67 | bygroups(Text, Keyword, Keyword, Text, Name.Class, Punctuation, Keyword, Text), 'generics'), |
---|
68 | (r'(\s*) (as|to) (inout|out|vari)? (\s+) ([A-Za-z][\w_.]* \?? | !) (\s*)', |
---|
69 | bygroups(Text, Keyword, Keyword, Text, Name.Class, Text)), |
---|
70 | (r'(from) (\s+) (var)', bygroups(Keyword, Text, Name.Variable)), |
---|
71 | (r'(?<!def|get|pro|set)\s*[\w]+\s+?(?=as|,)', Name.Variable), |
---|
72 | (r'(has|implements|inherits)(\s+)', bygroups(Keyword, Text), 'typelist'), |
---|
73 | (r'([A-Z][\w_.]+) (<) (of) (\s+)', bygroups(Name.Class, Punctuation, Keyword, Text), 'generics'), |
---|
74 | (r'(\.|_) ([a-zA-Z][\w_.]*) ([(])', bygroups(Punctuation, Text, Punctuation), 'initialization'), |
---|
75 | (r'(?<!\.) \b([A-Z][\w_.]*) ([(])', bygroups(Name.Class, Punctuation), 'initialization'), |
---|
76 | (r'\b(in|is|and|or|not)\b', Operator.Word), |
---|
77 | ((r'\b(?: (abstract|base|internal|is|false|nil|nonvirtual|par|private|protected|' |
---|
78 | r'public|shared|override|partial|this|true|virtual) | ' |
---|
79 | r'(adds|all|any|assert|body|branch|break|callable|' |
---|
80 | r'catch|class|const|continue|do|dynamiceach|else|end|' |
---|
81 | r'ensure|enum|event|every|except|expect|extend|finally|' |
---|
82 | r'for|from|get|has|if|ignore|implements|implies|inherits|' |
---|
83 | r'inlined|interface|invariant|is|listen|lock|mixin|must|namespace|' |
---|
84 | r'objc|of|off|old|on|out|pass|passthrough|post|' |
---|
85 | r'print|pro|raise|ref|require|return|same|set|step|stop|struct|' |
---|
86 | r'success|test|throw|to|trace|try|use|using|var|vari|' |
---|
87 | r'where|while|yield) )\b'), bygroups(Keyword.Type, Keyword)), |
---|
88 | (r'(?: (\.|_)? ([A-Za-z_][\w_.]*) )', bygroups(Punctuation, Name)), |
---|
89 | (r'[\s\t]+(\n)?', Text), |
---|
90 | include('literals'), |
---|
91 | ], |
---|
92 | 'operators': [ |
---|
93 | (r'[&|=~<>!\-\+*%?/^]{1,3}', Operator), |
---|
94 | ], |
---|
95 | 'literals': [ |
---|
96 | (r'(\d+\.\d*|\d*\.\d+) [fF]? ([eE][+-]?[\d]+)?', Number.Float), |
---|
97 | (r'[0-9][0-9\.]*(f|m|ms|d|h|s)', Number), |
---|
98 | (r'0[0-7_]+', Number.Oct), |
---|
99 | (r'0x[a-fA-F0-9_]+', Number.Hex), |
---|
100 | (r'[\d_]+L', Number.Integer.Long), |
---|
101 | (r'[\d][\d_]*', Number.Integer), |
---|
102 | (r"([cnrsu]*|[CNRSU]*) ('')", bygroups(String.Symbol, String)), |
---|
103 | (r'([cnrsu]*|[CNRSU]*) ("")', bygroups(String.Symbol, String)), |
---|
104 | (r'([cnrsu]*|[CNRSU]*) (?<!") (") (?!")', bygroups(String.Symbol, String), 'doublequote-string'), |
---|
105 | (r"([cnrsu]*|[CNRSU]*) (?<!') (') (?!')", bygroups(String.Symbol, String), 'singlequote-string'), |
---|
106 | ], |
---|
107 | 'doublequote-multiline-comment' : [ |
---|
108 | (r'"""\s*?$', Comment.Multiline, '#pop'), |
---|
109 | include('in-comment'), |
---|
110 | (r'(?<!")"(?!")', Comment.Multiline), |
---|
111 | (r'[^"]+?', Comment), |
---|
112 | ], |
---|
113 | 'singlequote-multiline-comment' : [ |
---|
114 | include('in-comment'), |
---|
115 | (r"(<?!') ' (?!')", Comment.Multiline), |
---|
116 | (r"'''\s*?$", Comment.Multiline, '#pop'), |
---|
117 | (r"[^']+?", Comment.Multiline) |
---|
118 | ], |
---|
119 | 'arbitrary-comment' : [ |
---|
120 | (r'\#/', Comment.Multiline, '#pop'), |
---|
121 | include('in-comment'), |
---|
122 | (r'\#(?!/)', Comment.Multiline), |
---|
123 | (r'(?<!\#) /', Comment.Multiline), |
---|
124 | (r'[^#]+?', Comment.Multiline) |
---|
125 | ], |
---|
126 | 'singleline-comment' : [ |
---|
127 | (r'\.(?:warning|error|require|args|compile\-only|no\-warnings|skip)\.\s+', Generic.Emph), |
---|
128 | (r'.*?$', Comment.Single, '#pop') |
---|
129 | ], |
---|
130 | 'in-comment' : [ |
---|
131 | include('hyperlinks'), |
---|
132 | include('action-items') |
---|
133 | ], |
---|
134 | 'hyperlinks' : [ |
---|
135 | (r'\b(?:http://)[^\s]+', Generic.Emph) |
---|
136 | ], |
---|
137 | 'action-items' : [ |
---|
138 | (r'^\s*(?:TODO|NOTE|HACK|to\-do)\b', Generic.Emph) |
---|
139 | ], |
---|
140 | 'method' : [ |
---|
141 | (r'(as) (\s+)', bygroups(Keyword, Text), 'typespecifier'), |
---|
142 | (r'\)\s+', Text, '#pop') |
---|
143 | ], |
---|
144 | 'string-interpolation': [ |
---|
145 | (r'(?<!\\) \[.*?\]', String.Interpol), |
---|
146 | (r'\\ \[.*?\]', String) |
---|
147 | ], |
---|
148 | 'char-escape' : [ |
---|
149 | (r'\\[\w]', String.Escape), |
---|
150 | ], |
---|
151 | 'doublequote-string' : [ |
---|
152 | include('string-interpolation'), |
---|
153 | include('char-escape'), |
---|
154 | (r'[^"]', String), |
---|
155 | (r'(?<!\\)"', String, '#pop'), |
---|
156 | ], |
---|
157 | 'singlequote-string' : [ |
---|
158 | include('string-interpolation'), |
---|
159 | include('char-escape'), |
---|
160 | (r"[^']", String), |
---|
161 | (r"(?<!\\)'", String, '#pop') |
---|
162 | ], |
---|
163 | 'typespecifier' : [ |
---|
164 | (r'(inout|out|vari) (\s+)', bygroups(Keyword, Text)), |
---|
165 | (r'([A-Za-z_][\w_.]+) (<) (of) (\s+)', bygroups(Name.Class, Punctuation, Keyword, Text), ('root', 'generics')), |
---|
166 | (r'([A-Za-z_][\w_.]+ [?]?) (\s*?)', bygroups(Name.Class, Text), '#pop'), |
---|
167 | (r'(,) (\s*)', bygroups(Punctuation, Text), '#pop'), |
---|
168 | (r'\s*$', Text, '#pop') |
---|
169 | ], |
---|
170 | 'typelist': [ |
---|
171 | (r'([a-zA-Z_][\w_]*) (\<) (of) (\s+)', bygroups(Name.Class, Punctuation, Keyword, Text), 'generics'), |
---|
172 | (r'(,) (\s*)', bygroups(Punctuation, Text)), |
---|
173 | (r'([a-zA-Z_][\w_.]*) (\[\])? (\s*) (?=,)', bygroups(Name.Class, Punctuation, Text)), |
---|
174 | ('(?!_)\n', Text, '#pop'), |
---|
175 | (r'([a-zA-Z_][\w_.]*) (\[\])? (\s*)', bygroups(Name.Class, Punctuation, Text), '#pop'), |
---|
176 | (r'$', Text, '#pop') |
---|
177 | ], |
---|
178 | 'initialization': [ |
---|
179 | (r'(?<!\.) ([A-Z][\w_.]+) ([(])', bygroups(Name.Class, Punctuation), '#push'), |
---|
180 | (r'(\s*) (as|to) (inout|out|vari)? (\s+) ([A-Za-z][\w_.]* \?? | !) (\s*)', |
---|
181 | bygroups(Text, Keyword, Keyword, Text, Name.Class, Text)), |
---|
182 | include('operators'), |
---|
183 | include('literals'), |
---|
184 | (r'(?<!\.) ([A-Z_][\w._]+) (<) (of) (\s+)', bygroups(Name.Class, Punctuation, Keyword, Text), 'generics'), |
---|
185 | (r'(\.|_) ([a-zA-Z_][\w._]+) (<) (of) (\s+)', bygroups(Punctuation, Name, Punctuation, Keyword, Text), 'generics'), |
---|
186 | (r'[\[\],\s=\-?:]+', Punctuation), |
---|
187 | (r'([>._]) ([a-zA-Z][\w_.]) ([(])', bygroups(Punctuation, Text, Punctuation), '#push'), |
---|
188 | (r'\(', Punctuation, '#push'), |
---|
189 | (r'[\w._]+', Text), |
---|
190 | (r'\)\s*', Punctuation, '#pop') |
---|
191 | ], |
---|
192 | 'generics': [ |
---|
193 | (r'([a-zA-Z_][\w._]*) (<) (of) (\s+)', bygroups(Name.Class, Punctuation, Keyword, Text), '#push'), |
---|
194 | (r'(,) (\s)*', bygroups(Punctuation, Text)), |
---|
195 | (r'([a-zA-Z_][\w_.]*[?]?) (\s*)', bygroups(Name.Class, Text)), |
---|
196 | (r'(>) ([?])? (\s*)', bygroups(Punctuation, Punctuation, Text), '#pop') |
---|
197 | ], |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | class CSharpLexer(RegexLexer): |
---|
203 | """ |
---|
204 | For `C# <http://msdn2.microsoft.com/en-us/vcsharp/default.aspx>`_ |
---|
205 | source code. |
---|
206 | |
---|
207 | Additional options accepted: |
---|
208 | |
---|
209 | `unicodelevel` |
---|
210 | Determines which Unicode characters this lexer allows for identifiers. |
---|
211 | The possible values are: |
---|
212 | |
---|
213 | * ``none`` -- only the ASCII letters and numbers are allowed. This |
---|
214 | is the fastest selection. |
---|
215 | * ``basic`` -- all Unicode characters from the specification except |
---|
216 | category ``Lo`` are allowed. |
---|
217 | * ``full`` -- all Unicode characters as specified in the C# specs |
---|
218 | are allowed. Note that this means a considerable slowdown since the |
---|
219 | ``Lo`` category has more than 40,000 characters in it! |
---|
220 | |
---|
221 | The default value is ``basic``. |
---|
222 | |
---|
223 | *New in Pygments 0.8.* |
---|
224 | """ |
---|
225 | |
---|
226 | name = 'C#' |
---|
227 | aliases = ['csharp', 'c#'] |
---|
228 | filenames = ['*.cs'] |
---|
229 | mimetypes = ['text/x-csharp'] # inferred |
---|
230 | |
---|
231 | flags = re.MULTILINE | re.DOTALL | re.UNICODE |
---|
232 | |
---|
233 | # for the range of allowed unicode characters in identifiers, |
---|
234 | # see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf |
---|
235 | |
---|
236 | levels = { |
---|
237 | 'none': '@?[_a-zA-Z][a-zA-Z0-9_]*', |
---|
238 | 'basic': ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' + |
---|
239 | '[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + |
---|
240 | uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'), |
---|
241 | 'full': ('@?(?:_|[^' + |
---|
242 | _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl')) + '])' |
---|
243 | + '[^' + _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', |
---|
244 | 'Nl', 'Nd', 'Pc', 'Cf', 'Mn', |
---|
245 | 'Mc')) + ']*'), |
---|
246 | } |
---|
247 | |
---|
248 | tokens = {} |
---|
249 | token_variants = True |
---|
250 | |
---|
251 | for levelname, cs_ident in levels.items(): |
---|
252 | tokens[levelname] = { |
---|
253 | 'root': [ |
---|
254 | # method names |
---|
255 | (r'^([ \t]*(?:' + cs_ident + r'(?:\[\])?\s+)+?)' # return type |
---|
256 | r'(' + cs_ident + ')' # method name |
---|
257 | r'(\s*)(\()', # signature start |
---|
258 | bygroups(using(this), Name.Function, Text, Punctuation)), |
---|
259 | (r'^\s*\[.*?\]', Name.Attribute), |
---|
260 | (r'[^\S\n]+', Text), |
---|
261 | (r'\\\n', Text), # line continuation |
---|
262 | (r'//.*?\n', Comment.Single), |
---|
263 | (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
---|
264 | (r'\n', Text), |
---|
265 | (r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation), |
---|
266 | (r'[{}]', Punctuation), |
---|
267 | (r'@"(\\\\|\\"|[^"])*"', String), |
---|
268 | (r'"(\\\\|\\"|[^"\n])*["\n]', String), |
---|
269 | (r"'\\.'|'[^\\]'", String.Char), |
---|
270 | (r"[0-9](\.[0-9]*)?([eE][+-][0-9]+)?" |
---|
271 | r"[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?", Number), |
---|
272 | (r'#[ \t]*(if|endif|else|elif|define|undef|' |
---|
273 | r'line|error|warning|region|endregion|pragma)\b.*?\n', |
---|
274 | Comment.Preproc), |
---|
275 | (r'\b(extern)(\s+)(alias)\b', bygroups(Keyword, Text, |
---|
276 | Keyword)), |
---|
277 | (r'(abstract|as|base|break|case|catch|' |
---|
278 | r'checked|const|continue|default|delegate|' |
---|
279 | r'do|else|enum|event|explicit|extern|false|finally|' |
---|
280 | r'fixed|for|foreach|goto|if|implicit|in|interface|' |
---|
281 | r'internal|is|lock|new|null|operator|' |
---|
282 | r'out|override|params|private|protected|public|readonly|' |
---|
283 | r'ref|return|sealed|sizeof|stackalloc|static|' |
---|
284 | r'switch|this|throw|true|try|typeof|' |
---|
285 | r'unchecked|unsafe|virtual|void|while|' |
---|
286 | r'get|set|new|partial|yield|add|remove|value)\b', Keyword), |
---|
287 | (r'(global)(::)', bygroups(Keyword, Punctuation)), |
---|
288 | (r'(bool|byte|char|decimal|double|float|int|long|object|sbyte|' |
---|
289 | r'short|string|uint|ulong|ushort)\b\??', Keyword.Type), |
---|
290 | (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'class'), |
---|
291 | (r'(namespace|using)(\s+)', bygroups(Keyword, Text), 'namespace'), |
---|
292 | (cs_ident, Name), |
---|
293 | ], |
---|
294 | 'class': [ |
---|
295 | (cs_ident, Name.Class, '#pop') |
---|
296 | ], |
---|
297 | 'namespace': [ |
---|
298 | (r'(?=\()', Text, '#pop'), # using (resource) |
---|
299 | ('(' + cs_ident + r'|\.)+', Name.Namespace, '#pop') |
---|
300 | ] |
---|
301 | } |
---|
302 | |
---|
303 | def __init__(self, **options): |
---|
304 | level = get_choice_opt(options, 'unicodelevel', self.tokens.keys(), 'basic') |
---|
305 | if level not in self._all_tokens: |
---|
306 | # compile the regexes now |
---|
307 | self._tokens = self.__class__.process_tokendef(level) |
---|
308 | else: |
---|
309 | self._tokens = self._all_tokens[level] |
---|
310 | |
---|
311 | RegexLexer.__init__(self, **options) |
---|
312 | |
---|
313 | |
---|
314 | class BooLexer(RegexLexer): |
---|
315 | """ |
---|
316 | For `Boo <http://boo.codehaus.org/>`_ source code. |
---|
317 | """ |
---|
318 | |
---|
319 | name = 'Boo' |
---|
320 | aliases = ['boo'] |
---|
321 | filenames = ['*.boo'] |
---|
322 | mimetypes = ['text/x-boo'] |
---|
323 | |
---|
324 | tokens = { |
---|
325 | 'root': [ |
---|
326 | (r'\s+', Text), |
---|
327 | (r'(#|//).*$', Comment.Single), |
---|
328 | (r'/[*]', Comment.Multiline, 'comment'), |
---|
329 | (r'[]{}:(),.;[]', Punctuation), |
---|
330 | (r'\\\n', Text), |
---|
331 | (r'\\', Text), |
---|
332 | (r'(in|is|and|or|not)\b', Operator.Word), |
---|
333 | (r'/(\\\\|\\/|[^/\s])/', String.Regex), |
---|
334 | (r'@/(\\\\|\\/|[^/])*/', String.Regex), |
---|
335 | (r'=~|!=|==|<<|>>|[-+/*%=<>&^|]', Operator), |
---|
336 | (r'(as|abstract|callable|constructor|destructor|do|import|' |
---|
337 | r'enum|event|final|get|interface|internal|of|override|' |
---|
338 | r'partial|private|protected|public|return|set|static|' |
---|
339 | r'struct|transient|virtual|yield|super|and|break|cast|' |
---|
340 | r'continue|elif|else|ensure|except|for|given|goto|if|in|' |
---|
341 | r'is|isa|not|or|otherwise|pass|raise|ref|try|unless|when|' |
---|
342 | r'while|from|as)\b', Keyword), |
---|
343 | (r'def(?=\s+\(.*?\))', Keyword), |
---|
344 | (r'(def)(\s+)', bygroups(Keyword, Text), 'funcname'), |
---|
345 | (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), |
---|
346 | (r'(namespace)(\s+)', bygroups(Keyword, Text), 'namespace'), |
---|
347 | (r'(?<!\.)(true|false|null|self|__eval__|__switch__|array|' |
---|
348 | r'assert|checked|enumerate|filter|getter|len|lock|map|' |
---|
349 | r'matrix|max|min|normalArrayIndexing|print|property|range|' |
---|
350 | r'rawArrayIndexing|required|typeof|unchecked|using|' |
---|
351 | r'yieldAll|zip)\b', Name.Builtin), |
---|
352 | ('"""(\\\\|\\"|.*?)"""', String.Double), |
---|
353 | ('"(\\\\|\\"|[^"]*?)"', String.Double), |
---|
354 | ("'(\\\\|\\'|[^']*?)'", String.Single), |
---|
355 | ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
---|
356 | (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float), |
---|
357 | (r'[0-9][0-9\.]*(m|ms|d|h|s)', Number), |
---|
358 | (r'0\d+', Number.Oct), |
---|
359 | (r'0x[a-fA-F0-9]+', Number.Hex), |
---|
360 | (r'\d+L', Number.Integer.Long), |
---|
361 | (r'\d+', Number.Integer), |
---|
362 | ], |
---|
363 | 'comment': [ |
---|
364 | ('/[*]', Comment.Multiline, '#push'), |
---|
365 | ('[*]/', Comment.Multiline, '#pop'), |
---|
366 | ('[^/*]', Comment.Multiline), |
---|
367 | ('[*/]', Comment.Multiline) |
---|
368 | ], |
---|
369 | 'funcname': [ |
---|
370 | ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop') |
---|
371 | ], |
---|
372 | 'classname': [ |
---|
373 | ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') |
---|
374 | ], |
---|
375 | 'namespace': [ |
---|
376 | ('[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop') |
---|
377 | ] |
---|
378 | } |
---|
379 | |
---|
380 | |
---|
381 | class VbNetLexer(RegexLexer): |
---|
382 | """ |
---|
383 | For |
---|
384 | `Visual Basic.NET <http://msdn2.microsoft.com/en-us/vbasic/default.aspx>`_ |
---|
385 | source code. |
---|
386 | """ |
---|
387 | |
---|
388 | name = 'VB.net' |
---|
389 | aliases = ['vb.net', 'vbnet'] |
---|
390 | filenames = ['*.vb', '*.bas'] |
---|
391 | mimetypes = ['text/x-vbnet', 'text/x-vba'] # (?) |
---|
392 | |
---|
393 | flags = re.MULTILINE | re.IGNORECASE |
---|
394 | tokens = { |
---|
395 | 'root': [ |
---|
396 | (r'^\s*<.*?>', Name.Attribute), |
---|
397 | (r'\s+', Text), |
---|
398 | (r'\n', Text), |
---|
399 | (r'rem\b.*?\n', Comment), |
---|
400 | (r"'.*?\n", Comment), |
---|
401 | (r'#If\s.*?\sThen|#ElseIf\s.*?\sThen|#End\s+If|#Const|' |
---|
402 | r'#ExternalSource.*?\n|#End\s+ExternalSource|' |
---|
403 | r'#Region.*?\n|#End\s+Region|#ExternalChecksum', |
---|
404 | Comment.Preproc), |
---|
405 | (r'[\(\){}!#,.:]', Punctuation), |
---|
406 | (r'Option\s+(Strict|Explicit|Compare)\s+' |
---|
407 | r'(On|Off|Binary|Text)', Keyword.Declaration), |
---|
408 | (r'(?<!\.)(AddHandler|Alias|' |
---|
409 | r'ByRef|ByVal|Call|Case|Catch|CBool|CByte|CChar|CDate|' |
---|
410 | r'CDec|CDbl|CInt|CLng|CObj|Const|Continue|CSByte|CShort|' |
---|
411 | r'CSng|CStr|CType|CUInt|CULng|CUShort|Declare|' |
---|
412 | r'Default|Delegate|Dim|DirectCast|Do|Each|Else|ElseIf|' |
---|
413 | r'End|EndIf|Enum|Erase|Error|Event|Exit|False|Finally|For|' |
---|
414 | r'Friend|Function|Get|Global|GoSub|GoTo|Handles|If|' |
---|
415 | r'Implements|Imports|Inherits|Interface|' |
---|
416 | r'Let|Lib|Loop|Me|Module|MustInherit|' |
---|
417 | r'MustOverride|MyBase|MyClass|Namespace|Narrowing|New|Next|' |
---|
418 | r'Not|Nothing|NotInheritable|NotOverridable|Of|On|' |
---|
419 | r'Operator|Option|Optional|Overloads|Overridable|' |
---|
420 | r'Overrides|ParamArray|Partial|Private|Property|Protected|' |
---|
421 | r'Public|RaiseEvent|ReadOnly|ReDim|RemoveHandler|Resume|' |
---|
422 | r'Return|Select|Set|Shadows|Shared|Single|' |
---|
423 | r'Static|Step|Stop|Structure|Sub|SyncLock|Then|' |
---|
424 | r'Throw|To|True|Try|TryCast|Wend|' |
---|
425 | r'Using|When|While|Widening|With|WithEvents|' |
---|
426 | r'WriteOnly)\b', Keyword), |
---|
427 | (r'(?<!\.)(Function|Sub|Property)(\s+)', |
---|
428 | bygroups(Keyword, Text), 'funcname'), |
---|
429 | (r'(?<!\.)(Class|Structure|Enum)(\s+)', |
---|
430 | bygroups(Keyword, Text), 'classname'), |
---|
431 | (r'(?<!\.)(Namespace|Imports)(\s+)', |
---|
432 | bygroups(Keyword, Text), 'namespace'), |
---|
433 | (r'(?<!\.)(Boolean|Byte|Char|Date|Decimal|Double|Integer|Long|' |
---|
434 | r'Object|SByte|Short|Single|String|Variant|UInteger|ULong|' |
---|
435 | r'UShort)\b', Keyword.Type), |
---|
436 | (r'(?<!\.)(AddressOf|And|AndAlso|As|GetType|In|Is|IsNot|Like|Mod|' |
---|
437 | r'Or|OrElse|TypeOf|Xor)\b', Operator.Word), |
---|
438 | (r'&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|' |
---|
439 | r'<=|>=|<>|[-&*/\\^+=<>]', |
---|
440 | Operator), |
---|
441 | ('"', String, 'string'), |
---|
442 | ('[a-zA-Z_][a-zA-Z0-9_]*[%&@!#$]?', Name), |
---|
443 | ('#.*?#', Literal.Date), |
---|
444 | (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float), |
---|
445 | (r'\d+([SILDFR]|US|UI|UL)?', Number.Integer), |
---|
446 | (r'&H[0-9a-f]+([SILDFR]|US|UI|UL)?', Number.Integer), |
---|
447 | (r'&O[0-7]+([SILDFR]|US|UI|UL)?', Number.Integer), |
---|
448 | (r'_\n', Text), # Line continuation |
---|
449 | ], |
---|
450 | 'string': [ |
---|
451 | (r'""', String), |
---|
452 | (r'"C?', String, '#pop'), |
---|
453 | (r'[^"]+', String), |
---|
454 | ], |
---|
455 | 'funcname': [ |
---|
456 | (r'[a-z_][a-z0-9_]*', Name.Function, '#pop') |
---|
457 | ], |
---|
458 | 'classname': [ |
---|
459 | (r'[a-z_][a-z0-9_]*', Name.Class, '#pop') |
---|
460 | ], |
---|
461 | 'namespace': [ |
---|
462 | (r'[a-z_][a-z0-9_.]*', Name.Namespace, '#pop') |
---|
463 | ], |
---|
464 | } |
---|
465 | |
---|
466 | class GenericAspxLexer(RegexLexer): |
---|
467 | """ |
---|
468 | Lexer for ASP.NET pages. |
---|
469 | """ |
---|
470 | |
---|
471 | name = 'aspx-gen' |
---|
472 | filenames = [] |
---|
473 | mimetypes = [] |
---|
474 | |
---|
475 | flags = re.DOTALL |
---|
476 | |
---|
477 | tokens = { |
---|
478 | 'root': [ |
---|
479 | (r'(<%[@=#]?)(.*?)(%>)', bygroups(Name.Tag, Other, Name.Tag)), |
---|
480 | (r'(<script.*?>)(.*?)(</script>)', bygroups(using(XmlLexer), |
---|
481 | Other, |
---|
482 | using(XmlLexer))), |
---|
483 | (r'(.+?)(?=<)', using(XmlLexer)), |
---|
484 | (r'.+', using(XmlLexer)), |
---|
485 | ], |
---|
486 | } |
---|
487 | |
---|
488 | #TODO support multiple languages within the same source file |
---|
489 | class CSharpAspxLexer(DelegatingLexer): |
---|
490 | """ |
---|
491 | Lexer for highligting C# within ASP.NET pages. |
---|
492 | """ |
---|
493 | |
---|
494 | name = 'aspx-cs' |
---|
495 | aliases = ['aspx-cs'] |
---|
496 | filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'] |
---|
497 | mimetypes = [] |
---|
498 | |
---|
499 | def __init__(self, **options): |
---|
500 | super(CSharpAspxLexer, self).__init__(CSharpLexer,GenericAspxLexer, |
---|
501 | **options) |
---|
502 | |
---|
503 | def analyse_text(text): |
---|
504 | if re.search(r'Page\s*Language="C#"', text, re.I) is not None: |
---|
505 | return 0.2 |
---|
506 | elif re.search(r'script[^>]+language=["\']C#', text, re.I) is not None: |
---|
507 | return 0.15 |
---|
508 | return 0.001 # TODO really only for when filename matched... |
---|
509 | |
---|
510 | class VbNetAspxLexer(DelegatingLexer): |
---|
511 | """ |
---|
512 | Lexer for highligting Visual Basic.net within ASP.NET pages. |
---|
513 | """ |
---|
514 | |
---|
515 | name = 'aspx-vb' |
---|
516 | aliases = ['aspx-vb'] |
---|
517 | filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'] |
---|
518 | mimetypes = [] |
---|
519 | |
---|
520 | def __init__(self, **options): |
---|
521 | super(VbNetAspxLexer, self).__init__(VbNetLexer,GenericAspxLexer, |
---|
522 | **options) |
---|
523 | |
---|
524 | def analyse_text(text): |
---|
525 | if re.search(r'Page\s*Language="Vb"', text, re.I) is not None: |
---|
526 | return 0.2 |
---|
527 | elif re.search(r'script[^>]+language=["\']vb', text, re.I) is not None: |
---|
528 | return 0.15 |
---|