|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.javascript |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for JavaScript and related languages. |
|
7 |
|
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 import re |
|
13 |
|
14 from pygments.lexer import RegexLexer, include, bygroups, default, using, this |
|
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
16 Number, Punctuation, Other |
|
17 from pygments.util import get_bool_opt, iteritems |
|
18 import pygments.unistring as uni |
|
19 |
|
20 __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer', |
|
21 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer', |
|
22 'CoffeeScriptLexer', 'MaskLexer'] |
|
23 |
|
24 JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + |
|
25 ']|\\\\u[a-fA-F0-9]{4})') |
|
26 JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', |
|
27 'Mn', 'Mc', 'Nd', 'Pc') + |
|
28 u'\u200c\u200d]|\\\\u[a-fA-F0-9]{4})') |
|
29 JS_IDENT = JS_IDENT_START + '(?:' + JS_IDENT_PART + ')*' |
|
30 |
|
31 |
|
32 class JavascriptLexer(RegexLexer): |
|
33 """ |
|
34 For JavaScript source code. |
|
35 """ |
|
36 |
|
37 name = 'JavaScript' |
|
38 aliases = ['js', 'javascript'] |
|
39 filenames = ['*.js', ] |
|
40 mimetypes = ['application/javascript', 'application/x-javascript', |
|
41 'text/x-javascript', 'text/javascript', ] |
|
42 |
|
43 flags = re.DOTALL | re.UNICODE | re.MULTILINE |
|
44 |
|
45 tokens = { |
|
46 'commentsandwhitespace': [ |
|
47 (r'\s+', Text), |
|
48 (r'<!--', Comment), |
|
49 (r'//.*?\n', Comment.Single), |
|
50 (r'/\*.*?\*/', Comment.Multiline) |
|
51 ], |
|
52 'slashstartsregex': [ |
|
53 include('commentsandwhitespace'), |
|
54 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
55 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
56 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
57 default('#pop') |
|
58 ], |
|
59 'badregex': [ |
|
60 (r'\n', Text, '#pop') |
|
61 ], |
|
62 'root': [ |
|
63 (r'\A#! ?/.*?\n', Comment), # shebang lines are recognized by node.js |
|
64 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
65 include('commentsandwhitespace'), |
|
66 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
67 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), |
|
68 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
69 (r'[})\].]', Punctuation), |
|
70 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
71 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|' |
|
72 r'this)\b', Keyword, 'slashstartsregex'), |
|
73 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
74 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
75 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
76 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
77 r'transient|volatile)\b', Keyword.Reserved), |
|
78 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
79 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
80 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
81 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
82 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
83 r'window)\b', Name.Builtin), |
|
84 (JS_IDENT, Name.Other), |
|
85 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
86 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
87 (r'[0-9]+', Number.Integer), |
|
88 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
89 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
90 ] |
|
91 } |
|
92 |
|
93 |
|
94 class KalLexer(RegexLexer): |
|
95 """ |
|
96 For `Kal`_ source code. |
|
97 |
|
98 .. _Kal: http://rzimmerman.github.io/kal |
|
99 |
|
100 |
|
101 .. versionadded:: 2.0 |
|
102 """ |
|
103 |
|
104 name = 'Kal' |
|
105 aliases = ['kal'] |
|
106 filenames = ['*.kal'] |
|
107 mimetypes = ['text/kal', 'application/kal'] |
|
108 |
|
109 flags = re.DOTALL |
|
110 tokens = { |
|
111 'commentsandwhitespace': [ |
|
112 (r'\s+', Text), |
|
113 (r'###[^#].*?###', Comment.Multiline), |
|
114 (r'#(?!##[^#]).*?\n', Comment.Single), |
|
115 ], |
|
116 'functiondef': [ |
|
117 (r'[$a-zA-Z_][\w$]*\s*', Name.Function, '#pop'), |
|
118 include('commentsandwhitespace'), |
|
119 ], |
|
120 'classdef': [ |
|
121 (r'\binherits\s+from\b', Keyword), |
|
122 (r'[$a-zA-Z_][\w$]*\s*\n', Name.Class, '#pop'), |
|
123 (r'[$a-zA-Z_][\w$]*\s*', Name.Class), |
|
124 include('commentsandwhitespace'), |
|
125 ], |
|
126 'listcomprehension': [ |
|
127 (r'\]', Punctuation, '#pop'), |
|
128 (r'\b(property|value)\b', Keyword), |
|
129 include('root'), |
|
130 ], |
|
131 'waitfor': [ |
|
132 (r'\n', Punctuation, '#pop'), |
|
133 (r'\bfrom\b', Keyword), |
|
134 include('root'), |
|
135 ], |
|
136 'root': [ |
|
137 include('commentsandwhitespace'), |
|
138 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
139 r'([gim]+\b|\B)', String.Regex), |
|
140 (r'\?|:|_(?=\n)|==?|!=|-(?!>)|[<>+*/-]=?', |
|
141 Operator), |
|
142 (r'\b(and|or|isnt|is|not|but|bitwise|mod|\^|xor|exists|' |
|
143 r'doesnt\s+exist)\b', Operator.Word), |
|
144 (r'(?:\([^()]+\))?\s*>', Name.Function), |
|
145 (r'[{(]', Punctuation), |
|
146 (r'\[', Punctuation, 'listcomprehension'), |
|
147 (r'[})\].,]', Punctuation), |
|
148 (r'\b(function|method|task)\b', Keyword.Declaration, 'functiondef'), |
|
149 (r'\bclass\b', Keyword.Declaration, 'classdef'), |
|
150 (r'\b(safe\s+)?wait\s+for\b', Keyword, 'waitfor'), |
|
151 (r'\b(me|this)(\.[$a-zA-Z_][\w.$]*)?\b', Name.Variable.Instance), |
|
152 (r'(?<![.$])(for(\s+(parallel|series))?|in|of|while|until|' |
|
153 r'break|return|continue|' |
|
154 r'when|if|unless|else|otherwise|except\s+when|' |
|
155 r'throw|raise|fail\s+with|try|catch|finally|new|delete|' |
|
156 r'typeof|instanceof|super|run\s+in\s+parallel|' |
|
157 r'inherits\s+from)\b', Keyword), |
|
158 (r'(?<![.$])(true|false|yes|no|on|off|null|nothing|none|' |
|
159 r'NaN|Infinity|undefined)\b', |
|
160 Keyword.Constant), |
|
161 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
162 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
163 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
164 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|' |
|
165 r'print)\b', |
|
166 Name.Builtin), |
|
167 (r'[$a-zA-Z_][\w.$]*\s*(:|[+\-*/]?\=)?\b', Name.Variable), |
|
168 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
169 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
170 (r'[0-9]+', Number.Integer), |
|
171 ('"""', String, 'tdqs'), |
|
172 ("'''", String, 'tsqs'), |
|
173 ('"', String, 'dqs'), |
|
174 ("'", String, 'sqs'), |
|
175 ], |
|
176 'strings': [ |
|
177 (r'[^#\\\'"]+', String), |
|
178 # note that all kal strings are multi-line. |
|
179 # hashmarks, quotes and backslashes must be parsed one at a time |
|
180 ], |
|
181 'interpoling_string': [ |
|
182 (r'\}', String.Interpol, "#pop"), |
|
183 include('root') |
|
184 ], |
|
185 'dqs': [ |
|
186 (r'"', String, '#pop'), |
|
187 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
188 (r'#\{', String.Interpol, "interpoling_string"), |
|
189 include('strings') |
|
190 ], |
|
191 'sqs': [ |
|
192 (r"'", String, '#pop'), |
|
193 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
194 include('strings') |
|
195 ], |
|
196 'tdqs': [ |
|
197 (r'"""', String, '#pop'), |
|
198 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
199 (r'#\{', String.Interpol, "interpoling_string"), |
|
200 include('strings'), |
|
201 ], |
|
202 'tsqs': [ |
|
203 (r"'''", String, '#pop'), |
|
204 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
205 include('strings') |
|
206 ], |
|
207 } |
|
208 |
|
209 |
|
210 class LiveScriptLexer(RegexLexer): |
|
211 """ |
|
212 For `LiveScript`_ source code. |
|
213 |
|
214 .. _LiveScript: http://gkz.github.com/LiveScript/ |
|
215 |
|
216 .. versionadded:: 1.6 |
|
217 """ |
|
218 |
|
219 name = 'LiveScript' |
|
220 aliases = ['live-script', 'livescript'] |
|
221 filenames = ['*.ls'] |
|
222 mimetypes = ['text/livescript'] |
|
223 |
|
224 flags = re.DOTALL |
|
225 tokens = { |
|
226 'commentsandwhitespace': [ |
|
227 (r'\s+', Text), |
|
228 (r'/\*.*?\*/', Comment.Multiline), |
|
229 (r'#.*?\n', Comment.Single), |
|
230 ], |
|
231 'multilineregex': [ |
|
232 include('commentsandwhitespace'), |
|
233 (r'//([gim]+\b|\B)', String.Regex, '#pop'), |
|
234 (r'/', String.Regex), |
|
235 (r'[^/#]+', String.Regex) |
|
236 ], |
|
237 'slashstartsregex': [ |
|
238 include('commentsandwhitespace'), |
|
239 (r'//', String.Regex, ('#pop', 'multilineregex')), |
|
240 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
241 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
242 default('#pop'), |
|
243 ], |
|
244 'root': [ |
|
245 # this next expr leads to infinite loops root -> slashstartsregex |
|
246 # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
247 include('commentsandwhitespace'), |
|
248 (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' |
|
249 r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), |
|
250 (r'\+\+|&&|(?<![.$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' |
|
251 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' |
|
252 r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|' |
|
253 r'[+*`%&|^/])=?', |
|
254 Operator, 'slashstartsregex'), |
|
255 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
256 (r'[})\].]', Punctuation), |
|
257 (r'(?<![.$])(for|own|in|of|while|until|loop|break|' |
|
258 r'return|continue|switch|when|then|if|unless|else|' |
|
259 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' |
|
260 r'extends|this|class|by|const|var|to|til)\b', Keyword, |
|
261 'slashstartsregex'), |
|
262 (r'(?<![.$])(true|false|yes|no|on|off|' |
|
263 r'null|NaN|Infinity|undefined|void)\b', |
|
264 Keyword.Constant), |
|
265 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
266 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
267 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
268 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', |
|
269 Name.Builtin), |
|
270 (r'[$a-zA-Z_][\w.\-:$]*\s*[:=]\s', Name.Variable, |
|
271 'slashstartsregex'), |
|
272 (r'@[$a-zA-Z_][\w.\-:$]*\s*[:=]\s', Name.Variable.Instance, |
|
273 'slashstartsregex'), |
|
274 (r'@', Name.Other, 'slashstartsregex'), |
|
275 (r'@?[$a-zA-Z_][\w-]*', Name.Other, 'slashstartsregex'), |
|
276 (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float), |
|
277 (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer), |
|
278 ('"""', String, 'tdqs'), |
|
279 ("'''", String, 'tsqs'), |
|
280 ('"', String, 'dqs'), |
|
281 ("'", String, 'sqs'), |
|
282 (r'\\\S+', String), |
|
283 (r'<\[.*?\]>', String), |
|
284 ], |
|
285 'strings': [ |
|
286 (r'[^#\\\'"]+', String), |
|
287 # note that all coffee script strings are multi-line. |
|
288 # hashmarks, quotes and backslashes must be parsed one at a time |
|
289 ], |
|
290 'interpoling_string': [ |
|
291 (r'\}', String.Interpol, "#pop"), |
|
292 include('root') |
|
293 ], |
|
294 'dqs': [ |
|
295 (r'"', String, '#pop'), |
|
296 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
297 (r'#\{', String.Interpol, "interpoling_string"), |
|
298 (r'#', String), |
|
299 include('strings') |
|
300 ], |
|
301 'sqs': [ |
|
302 (r"'", String, '#pop'), |
|
303 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
304 include('strings') |
|
305 ], |
|
306 'tdqs': [ |
|
307 (r'"""', String, '#pop'), |
|
308 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
309 (r'#\{', String.Interpol, "interpoling_string"), |
|
310 (r'#', String), |
|
311 include('strings'), |
|
312 ], |
|
313 'tsqs': [ |
|
314 (r"'''", String, '#pop'), |
|
315 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
316 include('strings') |
|
317 ], |
|
318 } |
|
319 |
|
320 |
|
321 class DartLexer(RegexLexer): |
|
322 """ |
|
323 For `Dart <http://dartlang.org/>`_ source code. |
|
324 |
|
325 .. versionadded:: 1.5 |
|
326 """ |
|
327 |
|
328 name = 'Dart' |
|
329 aliases = ['dart'] |
|
330 filenames = ['*.dart'] |
|
331 mimetypes = ['text/x-dart'] |
|
332 |
|
333 flags = re.MULTILINE | re.DOTALL |
|
334 |
|
335 tokens = { |
|
336 'root': [ |
|
337 include('string_literal'), |
|
338 (r'#!(.*?)$', Comment.Preproc), |
|
339 (r'\b(import|export)\b', Keyword, 'import_decl'), |
|
340 (r'\b(library|source|part of|part)\b', Keyword), |
|
341 (r'[^\S\n]+', Text), |
|
342 (r'//.*?\n', Comment.Single), |
|
343 (r'/\*.*?\*/', Comment.Multiline), |
|
344 (r'\b(class)\b(\s+)', |
|
345 bygroups(Keyword.Declaration, Text), 'class'), |
|
346 (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|' |
|
347 r'if|in|is|new|return|super|switch|this|throw|try|while)\b', |
|
348 Keyword), |
|
349 (r'\b(abstract|const|extends|factory|final|get|implements|' |
|
350 r'native|operator|set|static|typedef|var)\b', Keyword.Declaration), |
|
351 (r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type), |
|
352 (r'\b(false|null|true)\b', Keyword.Constant), |
|
353 (r'[~!%^&*+=|?:<>/-]|as\b', Operator), |
|
354 (r'[a-zA-Z_$]\w*:', Name.Label), |
|
355 (r'[a-zA-Z_$]\w*', Name), |
|
356 (r'[(){}\[\],.;]', Punctuation), |
|
357 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
358 # DIGIT+ (‘.’ DIGIT*)? EXPONENT? |
|
359 (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number), |
|
360 (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT? |
|
361 (r'\n', Text) |
|
362 # pseudo-keyword negate intentionally left out |
|
363 ], |
|
364 'class': [ |
|
365 (r'[a-zA-Z_$]\w*', Name.Class, '#pop') |
|
366 ], |
|
367 'import_decl': [ |
|
368 include('string_literal'), |
|
369 (r'\s+', Text), |
|
370 (r'\b(as|show|hide)\b', Keyword), |
|
371 (r'[a-zA-Z_$]\w*', Name), |
|
372 (r'\,', Punctuation), |
|
373 (r'\;', Punctuation, '#pop') |
|
374 ], |
|
375 'string_literal': [ |
|
376 # Raw strings. |
|
377 (r'r"""([\w\W]*?)"""', String.Double), |
|
378 (r"r'''([\w\W]*?)'''", String.Single), |
|
379 (r'r"(.*?)"', String.Double), |
|
380 (r"r'(.*?)'", String.Single), |
|
381 # Normal Strings. |
|
382 (r'"""', String.Double, 'string_double_multiline'), |
|
383 (r"'''", String.Single, 'string_single_multiline'), |
|
384 (r'"', String.Double, 'string_double'), |
|
385 (r"'", String.Single, 'string_single') |
|
386 ], |
|
387 'string_common': [ |
|
388 (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z'\"$\\])", |
|
389 String.Escape), |
|
390 (r'(\$)([a-zA-Z_]\w*)', bygroups(String.Interpol, Name)), |
|
391 (r'(\$\{)(.*?)(\})', |
|
392 bygroups(String.Interpol, using(this), String.Interpol)) |
|
393 ], |
|
394 'string_double': [ |
|
395 (r'"', String.Double, '#pop'), |
|
396 (r'[^"$\\\n]+', String.Double), |
|
397 include('string_common'), |
|
398 (r'\$+', String.Double) |
|
399 ], |
|
400 'string_double_multiline': [ |
|
401 (r'"""', String.Double, '#pop'), |
|
402 (r'[^"$\\]+', String.Double), |
|
403 include('string_common'), |
|
404 (r'(\$|\")+', String.Double) |
|
405 ], |
|
406 'string_single': [ |
|
407 (r"'", String.Single, '#pop'), |
|
408 (r"[^'$\\\n]+", String.Single), |
|
409 include('string_common'), |
|
410 (r'\$+', String.Single) |
|
411 ], |
|
412 'string_single_multiline': [ |
|
413 (r"'''", String.Single, '#pop'), |
|
414 (r'[^\'$\\]+', String.Single), |
|
415 include('string_common'), |
|
416 (r'(\$|\')+', String.Single) |
|
417 ] |
|
418 } |
|
419 |
|
420 |
|
421 class TypeScriptLexer(RegexLexer): |
|
422 """ |
|
423 For `TypeScript <http://typescriptlang.org/>`_ source code. |
|
424 |
|
425 .. versionadded:: 1.6 |
|
426 """ |
|
427 |
|
428 name = 'TypeScript' |
|
429 aliases = ['ts'] |
|
430 filenames = ['*.ts'] |
|
431 mimetypes = ['text/x-typescript'] |
|
432 |
|
433 flags = re.DOTALL | re.MULTILINE |
|
434 |
|
435 tokens = { |
|
436 'commentsandwhitespace': [ |
|
437 (r'\s+', Text), |
|
438 (r'<!--', Comment), |
|
439 (r'//.*?\n', Comment.Single), |
|
440 (r'/\*.*?\*/', Comment.Multiline) |
|
441 ], |
|
442 'slashstartsregex': [ |
|
443 include('commentsandwhitespace'), |
|
444 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
445 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
446 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
447 default('#pop') |
|
448 ], |
|
449 'badregex': [ |
|
450 (r'\n', Text, '#pop') |
|
451 ], |
|
452 'root': [ |
|
453 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
454 include('commentsandwhitespace'), |
|
455 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
456 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), |
|
457 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
458 (r'[})\].]', Punctuation), |
|
459 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
460 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
461 r'this)\b', Keyword, 'slashstartsregex'), |
|
462 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
463 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
464 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
465 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
466 r'transient|volatile)\b', Keyword.Reserved), |
|
467 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
468 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
469 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
470 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
471 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
472 r'window)\b', Name.Builtin), |
|
473 # Match stuff like: module name {...} |
|
474 (r'\b(module)(\s*)(\s*[\w?.$][\w?.$]*)(\s*)', |
|
475 bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'), |
|
476 # Match variable type keywords |
|
477 (r'\b(string|bool|number)\b', Keyword.Type), |
|
478 # Match stuff like: constructor |
|
479 (r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved), |
|
480 # Match stuff like: super(argument, list) |
|
481 (r'(super)(\s*)(\([\w,?.$\s]+\s*\))', |
|
482 bygroups(Keyword.Reserved, Text), 'slashstartsregex'), |
|
483 # Match stuff like: function() {...} |
|
484 (r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'), |
|
485 # Match stuff like: (function: return type) |
|
486 (r'([\w?.$][\w?.$]*)(\s*:\s*)([\w?.$][\w?.$]*)', |
|
487 bygroups(Name.Other, Text, Keyword.Type)), |
|
488 (r'[$a-zA-Z_]\w*', Name.Other), |
|
489 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
490 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
491 (r'[0-9]+', Number.Integer), |
|
492 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
493 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
494 ] |
|
495 } |
|
496 |
|
497 |
|
498 class LassoLexer(RegexLexer): |
|
499 """ |
|
500 For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 |
|
501 syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in |
|
502 HTML, use the `LassoHtmlLexer`. |
|
503 |
|
504 Additional options accepted: |
|
505 |
|
506 `builtinshighlighting` |
|
507 If given and ``True``, highlight builtin types, traits, methods, and |
|
508 members (default: ``True``). |
|
509 `requiredelimiters` |
|
510 If given and ``True``, only highlight code between delimiters as Lasso |
|
511 (default: ``False``). |
|
512 |
|
513 .. versionadded:: 1.6 |
|
514 """ |
|
515 |
|
516 name = 'Lasso' |
|
517 aliases = ['lasso', 'lassoscript'] |
|
518 filenames = ['*.lasso', '*.lasso[89]'] |
|
519 alias_filenames = ['*.incl', '*.inc', '*.las'] |
|
520 mimetypes = ['text/x-lasso'] |
|
521 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE |
|
522 |
|
523 tokens = { |
|
524 'root': [ |
|
525 (r'^#!.+lasso9\b', Comment.Preproc, 'lasso'), |
|
526 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), |
|
527 (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')), |
|
528 (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')), |
|
529 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, |
|
530 ('delimiters', 'anglebrackets')), |
|
531 (r'<(!--.*?-->)?', Other, 'delimiters'), |
|
532 (r'\s+', Other), |
|
533 default(('delimiters', 'lassofile')), |
|
534 ], |
|
535 'delimiters': [ |
|
536 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), |
|
537 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), |
|
538 (r'\[', Comment.Preproc, 'squarebrackets'), |
|
539 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), |
|
540 (r'<(!--.*?-->)?', Other), |
|
541 (r'[^[<]+', Other), |
|
542 ], |
|
543 'nosquarebrackets': [ |
|
544 (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), |
|
545 (r'<', Other), |
|
546 (r'[^<]+', Other), |
|
547 ], |
|
548 'noprocess': [ |
|
549 (r'\[/noprocess\]', Comment.Preproc, '#pop'), |
|
550 (r'\[', Other), |
|
551 (r'[^[]', Other), |
|
552 ], |
|
553 'squarebrackets': [ |
|
554 (r'\]', Comment.Preproc, '#pop'), |
|
555 include('lasso'), |
|
556 ], |
|
557 'anglebrackets': [ |
|
558 (r'\?>', Comment.Preproc, '#pop'), |
|
559 include('lasso'), |
|
560 ], |
|
561 'lassofile': [ |
|
562 (r'\]|\?>', Comment.Preproc, '#pop'), |
|
563 include('lasso'), |
|
564 ], |
|
565 'whitespacecomments': [ |
|
566 (r'\s+', Text), |
|
567 (r'//.*?\n', Comment.Single), |
|
568 (r'/\*\*!.*?\*/', String.Doc), |
|
569 (r'/\*.*?\*/', Comment.Multiline), |
|
570 ], |
|
571 'lasso': [ |
|
572 # whitespace/comments |
|
573 include('whitespacecomments'), |
|
574 |
|
575 # literals |
|
576 (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), |
|
577 (r'0x[\da-f]+', Number.Hex), |
|
578 (r'\d+', Number.Integer), |
|
579 (r'([+-]?)(infinity|NaN)\b', bygroups(Operator, Number)), |
|
580 (r"'", String.Single, 'singlestring'), |
|
581 (r'"', String.Double, 'doublestring'), |
|
582 (r'`[^`]*`', String.Backtick), |
|
583 |
|
584 # names |
|
585 (r'\$[a-z_][\w.]*', Name.Variable), |
|
586 (r'#([a-z_][\w.]*|\d+)', Name.Variable.Instance), |
|
587 (r"(\.)('[a-z_][\w.]*')", |
|
588 bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), |
|
589 (r"(self)(\s*->\s*)('[a-z_][\w.]*')", |
|
590 bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), |
|
591 (r'(\.\.?)([a-z_][\w.]*(=(?!=))?)', |
|
592 bygroups(Name.Builtin.Pseudo, Name.Other.Member)), |
|
593 (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)', |
|
594 bygroups(Operator, Name.Other.Member)), |
|
595 (r'(self|inherited)\b', Name.Builtin.Pseudo), |
|
596 (r'-[a-z_][\w.]*', Name.Attribute), |
|
597 (r'::\s*[a-z_][\w.]*', Name.Label), |
|
598 (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' |
|
599 r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' |
|
600 r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' |
|
601 r'Error_InvalidDatabase|Error_InvalidPassword|' |
|
602 r'Error_InvalidUsername|Error_ModuleNotFound|' |
|
603 r'Error_NoError|Error_NoPermission|Error_OutOfMemory|' |
|
604 r'Error_ReqColumnMissing|Error_ReqFieldMissing|' |
|
605 r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|' |
|
606 r'Error_UpdateError)\b', Name.Exception), |
|
607 |
|
608 # definitions |
|
609 (r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b', |
|
610 bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)), |
|
611 (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%])', |
|
612 bygroups(Keyword.Declaration, Text, Name.Class, Operator, |
|
613 Name.Function), 'signature'), |
|
614 (r'(define)(\s+)([a-z_][\w.]*)', |
|
615 bygroups(Keyword.Declaration, Text, Name.Function), 'signature'), |
|
616 (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|[-+*/%])' |
|
617 r'(?=\s*\())', bygroups(Keyword, Text, Name.Function), |
|
618 'signature'), |
|
619 (r'(public|protected|private|provide)(\s+)([a-z_][\w.]*)', |
|
620 bygroups(Keyword, Text, Name.Function)), |
|
621 |
|
622 # keywords |
|
623 (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant), |
|
624 (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration), |
|
625 (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' |
|
626 r'null|bytes|list|queue|set|stack|staticarray|tie)\b', Keyword.Type), |
|
627 (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)), |
|
628 (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)), |
|
629 (r'require\b', Keyword, 'requiresection'), |
|
630 (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)), |
|
631 (r'(/?)(Cache|Database_Names|Database_SchemaNames|' |
|
632 r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' |
|
633 r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' |
|
634 r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' |
|
635 r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|' |
|
636 r'Link_FirstRecord|Link_LastGroup|Link_LastRecord|Link_NextGroup|' |
|
637 r'Link_NextRecord|Link_PrevGroup|Link_PrevRecord|Log|Loop|' |
|
638 r'NoProcess|Output_None|Portal|Private|Protect|Records|Referer|' |
|
639 r'Referrer|Repeating|ResultSet|Rows|Search_Args|Search_Arguments|' |
|
640 r'Select|Sort_Args|Sort_Arguments|Thread_Atomic|Value_List|While|' |
|
641 r'Abort|Case|Else|If_Empty|If_False|If_Null|If_True|Loop_Abort|' |
|
642 r'Loop_Continue|Loop_Count|Params|Params_Up|Return|Return_Value|' |
|
643 r'Run_Children|SOAP_DefineTag|SOAP_LastRequest|SOAP_LastResponse|' |
|
644 r'Tag_Name|ascending|average|by|define|descending|do|equals|' |
|
645 r'frozen|group|handle_failure|import|in|into|join|let|match|max|' |
|
646 r'min|on|order|parent|protected|provide|public|require|returnhome|' |
|
647 r'skip|split_thread|sum|take|thread|to|trait|type|where|with|' |
|
648 r'yield|yieldhome)\b', |
|
649 bygroups(Punctuation, Keyword)), |
|
650 |
|
651 # other |
|
652 (r',', Punctuation, 'commamember'), |
|
653 (r'(and|or|not)\b', Operator.Word), |
|
654 (r'([a-z_][\w.]*)(\s*::\s*[a-z_][\w.]*)?(\s*=(?!=))', |
|
655 bygroups(Name, Name.Label, Operator)), |
|
656 (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), |
|
657 (r'(=)(n?bw|n?ew|n?cn|lte?|gte?|n?eq|n?rx|ft)\b', |
|
658 bygroups(Operator, Operator.Word)), |
|
659 (r':=|[-+*/%=<>&|!?\\]+', Operator), |
|
660 (r'[{}():;,@^]', Punctuation), |
|
661 ], |
|
662 'singlestring': [ |
|
663 (r"'", String.Single, '#pop'), |
|
664 (r"[^'\\]+", String.Single), |
|
665 include('escape'), |
|
666 (r"\\", String.Single), |
|
667 ], |
|
668 'doublestring': [ |
|
669 (r'"', String.Double, '#pop'), |
|
670 (r'[^"\\]+', String.Double), |
|
671 include('escape'), |
|
672 (r'\\', String.Double), |
|
673 ], |
|
674 'escape': [ |
|
675 (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|' |
|
676 r'[abefnrtv?"\'\\]|$)', String.Escape), |
|
677 ], |
|
678 'signature': [ |
|
679 (r'=>', Operator, '#pop'), |
|
680 (r'\)', Punctuation, '#pop'), |
|
681 (r'[(,]', Punctuation, 'parameter'), |
|
682 include('lasso'), |
|
683 ], |
|
684 'parameter': [ |
|
685 (r'\)', Punctuation, '#pop'), |
|
686 (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'), |
|
687 (r'\.\.\.', Name.Builtin.Pseudo), |
|
688 include('lasso'), |
|
689 ], |
|
690 'requiresection': [ |
|
691 (r'(([a-z_][\w.]*=?|[-+*/%])(?=\s*\())', Name, 'requiresignature'), |
|
692 (r'(([a-z_][\w.]*=?|[-+*/%])(?=(\s*::\s*[\w.]+)?\s*,))', Name), |
|
693 (r'[a-z_][\w.]*=?|[-+*/%]', Name, '#pop'), |
|
694 (r'::\s*[a-z_][\w.]*', Name.Label), |
|
695 (r',', Punctuation), |
|
696 include('whitespacecomments'), |
|
697 ], |
|
698 'requiresignature': [ |
|
699 (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'), |
|
700 (r'\)', Punctuation, '#pop:2'), |
|
701 (r'-?[a-z_][\w.]*', Name.Attribute), |
|
702 (r'::\s*[a-z_][\w.]*', Name.Label), |
|
703 (r'\.\.\.', Name.Builtin.Pseudo), |
|
704 (r'[(,]', Punctuation), |
|
705 include('whitespacecomments'), |
|
706 ], |
|
707 'commamember': [ |
|
708 (r'(([a-z_][\w.]*=?|[-+*/%])' |
|
709 r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))', |
|
710 Name.Function, 'signature'), |
|
711 include('whitespacecomments'), |
|
712 default('#pop'), |
|
713 ], |
|
714 } |
|
715 |
|
716 def __init__(self, **options): |
|
717 self.builtinshighlighting = get_bool_opt( |
|
718 options, 'builtinshighlighting', True) |
|
719 self.requiredelimiters = get_bool_opt( |
|
720 options, 'requiredelimiters', False) |
|
721 |
|
722 self._builtins = set() |
|
723 self._members = set() |
|
724 if self.builtinshighlighting: |
|
725 from pygments.lexers._lasso_builtins import BUILTINS, MEMBERS |
|
726 for key, value in iteritems(BUILTINS): |
|
727 self._builtins.update(value) |
|
728 for key, value in iteritems(MEMBERS): |
|
729 self._members.update(value) |
|
730 RegexLexer.__init__(self, **options) |
|
731 |
|
732 def get_tokens_unprocessed(self, text): |
|
733 stack = ['root'] |
|
734 if self.requiredelimiters: |
|
735 stack.append('delimiters') |
|
736 for index, token, value in \ |
|
737 RegexLexer.get_tokens_unprocessed(self, text, stack): |
|
738 if (token is Name.Other and value.lower() in self._builtins or |
|
739 token is Name.Other.Member and |
|
740 value.lower().rstrip('=') in self._members): |
|
741 yield index, Name.Builtin, value |
|
742 continue |
|
743 yield index, token, value |
|
744 |
|
745 def analyse_text(text): |
|
746 rv = 0.0 |
|
747 if 'bin/lasso9' in text: |
|
748 rv += 0.8 |
|
749 if re.search(r'<\?lasso', text, re.I): |
|
750 rv += 0.4 |
|
751 if re.search(r'local\(', text, re.I): |
|
752 rv += 0.4 |
|
753 return rv |
|
754 |
|
755 |
|
756 class ObjectiveJLexer(RegexLexer): |
|
757 """ |
|
758 For Objective-J source code with preprocessor directives. |
|
759 |
|
760 .. versionadded:: 1.3 |
|
761 """ |
|
762 |
|
763 name = 'Objective-J' |
|
764 aliases = ['objective-j', 'objectivej', 'obj-j', 'objj'] |
|
765 filenames = ['*.j'] |
|
766 mimetypes = ['text/x-objective-j'] |
|
767 |
|
768 #: optional Comment or Whitespace |
|
769 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*' |
|
770 |
|
771 flags = re.DOTALL | re.MULTILINE |
|
772 |
|
773 tokens = { |
|
774 'root': [ |
|
775 include('whitespace'), |
|
776 |
|
777 # function definition |
|
778 (r'^(' + _ws + r'[+-]' + _ws + r')([(a-zA-Z_].*?[^(])(' + _ws + r'\{)', |
|
779 bygroups(using(this), using(this, state='function_signature'), |
|
780 using(this))), |
|
781 |
|
782 # class definition |
|
783 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), |
|
784 'classname'), |
|
785 (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text), |
|
786 'forward_classname'), |
|
787 (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)), |
|
788 |
|
789 include('statements'), |
|
790 ('[{()}]', Punctuation), |
|
791 (';', Punctuation), |
|
792 ], |
|
793 'whitespace': [ |
|
794 (r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")', |
|
795 bygroups(Comment.Preproc, Text, String.Double)), |
|
796 (r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)', |
|
797 bygroups(Comment.Preproc, Text, String.Double)), |
|
798 (r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")', |
|
799 bygroups(Comment.Preproc, Text, String.Double)), |
|
800 (r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)', |
|
801 bygroups(Comment.Preproc, Text, String.Double)), |
|
802 |
|
803 (r'#if\s+0', Comment.Preproc, 'if0'), |
|
804 (r'#', Comment.Preproc, 'macro'), |
|
805 |
|
806 (r'\n', Text), |
|
807 (r'\s+', Text), |
|
808 (r'\\\n', Text), # line continuation |
|
809 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), |
|
810 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
811 (r'<!--', Comment), |
|
812 ], |
|
813 'slashstartsregex': [ |
|
814 include('whitespace'), |
|
815 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
816 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
817 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
818 default('#pop'), |
|
819 ], |
|
820 'badregex': [ |
|
821 (r'\n', Text, '#pop'), |
|
822 ], |
|
823 'statements': [ |
|
824 (r'(L|@)?"', String, 'string'), |
|
825 (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", |
|
826 String.Char), |
|
827 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
828 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
829 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), |
|
830 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
831 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), |
|
832 (r'0[0-7]+[Ll]?', Number.Oct), |
|
833 (r'\d+[Ll]?', Number.Integer), |
|
834 |
|
835 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
836 |
|
837 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
838 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', |
|
839 Operator, 'slashstartsregex'), |
|
840 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
841 (r'[})\].]', Punctuation), |
|
842 |
|
843 (r'(for|in|while|do|break|return|continue|switch|case|default|if|' |
|
844 r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
845 r'prototype|__proto__)\b', Keyword, 'slashstartsregex'), |
|
846 |
|
847 (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
848 |
|
849 (r'(@selector|@private|@protected|@public|@encode|' |
|
850 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' |
|
851 r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword), |
|
852 |
|
853 (r'(int|long|float|short|double|char|unsigned|signed|void|' |
|
854 r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b', |
|
855 Keyword.Type), |
|
856 |
|
857 (r'(self|super)\b', Name.Builtin), |
|
858 |
|
859 (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant), |
|
860 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
861 (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|' |
|
862 r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|' |
|
863 r'SQRT2)\b', Keyword.Constant), |
|
864 |
|
865 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
866 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
867 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
868 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
869 r'window)\b', Name.Builtin), |
|
870 |
|
871 (r'([$a-zA-Z_]\w*)(' + _ws + r')(?=\()', |
|
872 bygroups(Name.Function, using(this))), |
|
873 |
|
874 (r'[$a-zA-Z_]\w*', Name), |
|
875 ], |
|
876 'classname': [ |
|
877 # interface definition that inherits |
|
878 (r'([a-zA-Z_]\w*)(' + _ws + r':' + _ws + |
|
879 r')([a-zA-Z_]\w*)?', |
|
880 bygroups(Name.Class, using(this), Name.Class), '#pop'), |
|
881 # interface definition for a category |
|
882 (r'([a-zA-Z_]\w*)(' + _ws + r'\()([a-zA-Z_]\w*)(\))', |
|
883 bygroups(Name.Class, using(this), Name.Label, Text), '#pop'), |
|
884 # simple interface / implementation |
|
885 (r'([a-zA-Z_]\w*)', Name.Class, '#pop'), |
|
886 ], |
|
887 'forward_classname': [ |
|
888 (r'([a-zA-Z_]\w*)(\s*,\s*)', |
|
889 bygroups(Name.Class, Text), '#push'), |
|
890 (r'([a-zA-Z_]\w*)(\s*;?)', |
|
891 bygroups(Name.Class, Text), '#pop'), |
|
892 ], |
|
893 'function_signature': [ |
|
894 include('whitespace'), |
|
895 |
|
896 # start of a selector w/ parameters |
|
897 (r'(\(' + _ws + r')' # open paren |
|
898 r'([a-zA-Z_]\w+)' # return type |
|
899 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
900 r'([$a-zA-Z_]\w+' + _ws + r':)', # function name |
|
901 bygroups(using(this), Keyword.Type, using(this), |
|
902 Name.Function), 'function_parameters'), |
|
903 |
|
904 # no-param function |
|
905 (r'(\(' + _ws + r')' # open paren |
|
906 r'([a-zA-Z_]\w+)' # return type |
|
907 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
908 r'([$a-zA-Z_]\w+)', # function name |
|
909 bygroups(using(this), Keyword.Type, using(this), |
|
910 Name.Function), "#pop"), |
|
911 |
|
912 # no return type given, start of a selector w/ parameters |
|
913 (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name |
|
914 bygroups(Name.Function), 'function_parameters'), |
|
915 |
|
916 # no return type given, no-param function |
|
917 (r'([$a-zA-Z_]\w+)', # function name |
|
918 bygroups(Name.Function), "#pop"), |
|
919 |
|
920 default('#pop'), |
|
921 ], |
|
922 'function_parameters': [ |
|
923 include('whitespace'), |
|
924 |
|
925 # parameters |
|
926 (r'(\(' + _ws + ')' # open paren |
|
927 r'([^)]+)' # type |
|
928 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
929 r'([$a-zA-Z_]\w+)', # param name |
|
930 bygroups(using(this), Keyword.Type, using(this), Text)), |
|
931 |
|
932 # one piece of a selector name |
|
933 (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name |
|
934 Name.Function), |
|
935 |
|
936 # smallest possible selector piece |
|
937 (r'(:)', Name.Function), |
|
938 |
|
939 # var args |
|
940 (r'(,' + _ws + r'\.\.\.)', using(this)), |
|
941 |
|
942 # param name |
|
943 (r'([$a-zA-Z_]\w+)', Text), |
|
944 ], |
|
945 'expression': [ |
|
946 (r'([$a-zA-Z_]\w*)(\()', bygroups(Name.Function, |
|
947 Punctuation)), |
|
948 (r'(\))', Punctuation, "#pop"), |
|
949 ], |
|
950 'string': [ |
|
951 (r'"', String, '#pop'), |
|
952 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
953 (r'[^\\"\n]+', String), # all other characters |
|
954 (r'\\\n', String), # line continuation |
|
955 (r'\\', String), # stray backslash |
|
956 ], |
|
957 'macro': [ |
|
958 (r'[^/\n]+', Comment.Preproc), |
|
959 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
|
960 (r'//.*?\n', Comment.Single, '#pop'), |
|
961 (r'/', Comment.Preproc), |
|
962 (r'(?<=\\)\n', Comment.Preproc), |
|
963 (r'\n', Comment.Preproc, '#pop'), |
|
964 ], |
|
965 'if0': [ |
|
966 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), |
|
967 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), |
|
968 (r'.*?\n', Comment), |
|
969 ] |
|
970 } |
|
971 |
|
972 def analyse_text(text): |
|
973 if re.search('^\s*@import\s+[<"]', text, re.MULTILINE): |
|
974 # special directive found in most Objective-J files |
|
975 return True |
|
976 return False |
|
977 |
|
978 |
|
979 class CoffeeScriptLexer(RegexLexer): |
|
980 """ |
|
981 For `CoffeeScript`_ source code. |
|
982 |
|
983 .. _CoffeeScript: http://coffeescript.org |
|
984 |
|
985 .. versionadded:: 1.3 |
|
986 """ |
|
987 |
|
988 name = 'CoffeeScript' |
|
989 aliases = ['coffee-script', 'coffeescript', 'coffee'] |
|
990 filenames = ['*.coffee'] |
|
991 mimetypes = ['text/coffeescript'] |
|
992 |
|
993 flags = re.DOTALL |
|
994 tokens = { |
|
995 'commentsandwhitespace': [ |
|
996 (r'\s+', Text), |
|
997 (r'###[^#].*?###', Comment.Multiline), |
|
998 (r'#(?!##[^#]).*?\n', Comment.Single), |
|
999 ], |
|
1000 'multilineregex': [ |
|
1001 (r'[^/#]+', String.Regex), |
|
1002 (r'///([gim]+\b|\B)', String.Regex, '#pop'), |
|
1003 (r'#\{', String.Interpol, 'interpoling_string'), |
|
1004 (r'[/#]', String.Regex), |
|
1005 ], |
|
1006 'slashstartsregex': [ |
|
1007 include('commentsandwhitespace'), |
|
1008 (r'///', String.Regex, ('#pop', 'multilineregex')), |
|
1009 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
1010 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
1011 default('#pop'), |
|
1012 ], |
|
1013 'root': [ |
|
1014 # this next expr leads to infinite loops root -> slashstartsregex |
|
1015 # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
1016 include('commentsandwhitespace'), |
|
1017 (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' |
|
1018 r'\|\||\\(?=\n)|' |
|
1019 r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&|^/])=?', |
|
1020 Operator, 'slashstartsregex'), |
|
1021 (r'(?:\([^()]*\))?\s*[=-]>', Name.Function), |
|
1022 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
1023 (r'[})\].]', Punctuation), |
|
1024 (r'(?<![.$])(for|own|in|of|while|until|' |
|
1025 r'loop|break|return|continue|' |
|
1026 r'switch|when|then|if|unless|else|' |
|
1027 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' |
|
1028 r'extends|this|class|by)\b', Keyword, 'slashstartsregex'), |
|
1029 (r'(?<![.$])(true|false|yes|no|on|off|null|' |
|
1030 r'NaN|Infinity|undefined)\b', |
|
1031 Keyword.Constant), |
|
1032 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
1033 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
1034 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
1035 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', |
|
1036 Name.Builtin), |
|
1037 (r'[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable, |
|
1038 'slashstartsregex'), |
|
1039 (r'@[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable.Instance, |
|
1040 'slashstartsregex'), |
|
1041 (r'@', Name.Other, 'slashstartsregex'), |
|
1042 (r'@?[$a-zA-Z_][\w$]*', Name.Other, 'slashstartsregex'), |
|
1043 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
1044 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
1045 (r'[0-9]+', Number.Integer), |
|
1046 ('"""', String, 'tdqs'), |
|
1047 ("'''", String, 'tsqs'), |
|
1048 ('"', String, 'dqs'), |
|
1049 ("'", String, 'sqs'), |
|
1050 ], |
|
1051 'strings': [ |
|
1052 (r'[^#\\\'"]+', String), |
|
1053 # note that all coffee script strings are multi-line. |
|
1054 # hashmarks, quotes and backslashes must be parsed one at a time |
|
1055 ], |
|
1056 'interpoling_string': [ |
|
1057 (r'\}', String.Interpol, "#pop"), |
|
1058 include('root') |
|
1059 ], |
|
1060 'dqs': [ |
|
1061 (r'"', String, '#pop'), |
|
1062 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
1063 (r'#\{', String.Interpol, "interpoling_string"), |
|
1064 (r'#', String), |
|
1065 include('strings') |
|
1066 ], |
|
1067 'sqs': [ |
|
1068 (r"'", String, '#pop'), |
|
1069 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
1070 include('strings') |
|
1071 ], |
|
1072 'tdqs': [ |
|
1073 (r'"""', String, '#pop'), |
|
1074 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
1075 (r'#\{', String.Interpol, "interpoling_string"), |
|
1076 (r'#', String), |
|
1077 include('strings'), |
|
1078 ], |
|
1079 'tsqs': [ |
|
1080 (r"'''", String, '#pop'), |
|
1081 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
1082 include('strings') |
|
1083 ], |
|
1084 } |
|
1085 |
|
1086 |
|
1087 class MaskLexer(RegexLexer): |
|
1088 """ |
|
1089 For `Mask <http://github.com/atmajs/MaskJS>`__ markup. |
|
1090 |
|
1091 .. versionadded:: 2.0 |
|
1092 """ |
|
1093 name = 'Mask' |
|
1094 aliases = ['mask'] |
|
1095 filenames = ['*.mask'] |
|
1096 mimetypes = ['text/x-mask'] |
|
1097 |
|
1098 flags = re.MULTILINE | re.IGNORECASE | re.DOTALL |
|
1099 tokens = { |
|
1100 'root': [ |
|
1101 (r'\s+', Text), |
|
1102 (r'//.*?\n', Comment.Single), |
|
1103 (r'/\*.*?\*/', Comment.Multiline), |
|
1104 (r'[{};>]', Punctuation), |
|
1105 (r"'''", String, 'string-trpl-single'), |
|
1106 (r'"""', String, 'string-trpl-double'), |
|
1107 (r"'", String, 'string-single'), |
|
1108 (r'"', String, 'string-double'), |
|
1109 (r'([\w-]+)', Name.Tag, 'node'), |
|
1110 (r'([^.#;{>\s]+)', Name.Class, 'node'), |
|
1111 (r'(#[\w-]+)', Name.Function, 'node'), |
|
1112 (r'(\.[\w-]+)', Name.Variable.Class, 'node') |
|
1113 ], |
|
1114 'string-base': [ |
|
1115 (r'\\.', String.Escape), |
|
1116 (r'~\[', String.Interpol, 'interpolation'), |
|
1117 (r'.', String.Single), |
|
1118 ], |
|
1119 'string-single': [ |
|
1120 (r"'", String.Single, '#pop'), |
|
1121 include('string-base') |
|
1122 ], |
|
1123 'string-double': [ |
|
1124 (r'"', String.Single, '#pop'), |
|
1125 include('string-base') |
|
1126 ], |
|
1127 'string-trpl-single': [ |
|
1128 (r"'''", String.Single, '#pop'), |
|
1129 include('string-base') |
|
1130 ], |
|
1131 'string-trpl-double': [ |
|
1132 (r'"""', String.Single, '#pop'), |
|
1133 include('string-base') |
|
1134 ], |
|
1135 'interpolation': [ |
|
1136 (r'\]', String.Interpol, '#pop'), |
|
1137 (r'\s*:', String.Interpol, 'expression'), |
|
1138 (r'\s*\w+:', Name.Other), |
|
1139 (r'[^\]]+', String.Interpol) |
|
1140 ], |
|
1141 'expression': [ |
|
1142 (r'[^\]]+', using(JavascriptLexer), '#pop') |
|
1143 ], |
|
1144 'node': [ |
|
1145 (r'\s+', Text), |
|
1146 (r'\.', Name.Variable.Class, 'node-class'), |
|
1147 (r'\#', Name.Function, 'node-id'), |
|
1148 (r'style[ \t]*=', Name.Attribute, 'node-attr-style-value'), |
|
1149 (r'[\w:-]+[ \t]*=', Name.Attribute, 'node-attr-value'), |
|
1150 (r'[\w:-]+', Name.Attribute), |
|
1151 (r'[>{;]', Punctuation, '#pop') |
|
1152 ], |
|
1153 'node-class': [ |
|
1154 (r'[\w-]+', Name.Variable.Class), |
|
1155 (r'~\[', String.Interpol, 'interpolation'), |
|
1156 default('#pop') |
|
1157 ], |
|
1158 'node-id': [ |
|
1159 (r'[\w-]+', Name.Function), |
|
1160 (r'~\[', String.Interpol, 'interpolation'), |
|
1161 default('#pop') |
|
1162 ], |
|
1163 'node-attr-value': [ |
|
1164 (r'\s+', Text), |
|
1165 (r'\w+', Name.Variable, '#pop'), |
|
1166 (r"'", String, 'string-single-pop2'), |
|
1167 (r'"', String, 'string-double-pop2'), |
|
1168 default('#pop') |
|
1169 ], |
|
1170 'node-attr-style-value': [ |
|
1171 (r'\s+', Text), |
|
1172 (r"'", String.Single, 'css-single-end'), |
|
1173 (r'"', String.Single, 'css-double-end'), |
|
1174 include('node-attr-value') |
|
1175 ], |
|
1176 'css-base': [ |
|
1177 (r'\s+', Text), |
|
1178 (r";", Punctuation), |
|
1179 (r"[\w\-]+\s*:", Name.Builtin) |
|
1180 ], |
|
1181 'css-single-end': [ |
|
1182 include('css-base'), |
|
1183 (r"'", String.Single, '#pop:2'), |
|
1184 (r"[^;']+", Name.Entity) |
|
1185 ], |
|
1186 'css-double-end': [ |
|
1187 include('css-base'), |
|
1188 (r'"', String.Single, '#pop:2'), |
|
1189 (r'[^;"]+', Name.Entity) |
|
1190 ], |
|
1191 'string-single-pop2': [ |
|
1192 (r"'", String.Single, '#pop:2'), |
|
1193 include('string-base') |
|
1194 ], |
|
1195 'string-double-pop2': [ |
|
1196 (r'"', String.Single, '#pop:2'), |
|
1197 include('string-base') |
|
1198 ], |
|
1199 } |