|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.javascript |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for JavaScript and related languages. |
|
7 |
|
8 :copyright: Copyright 2006-2017 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, \ |
|
15 this, words, combined |
|
16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
|
17 Number, Punctuation, Other |
|
18 from pygments.util import get_bool_opt, iteritems |
|
19 import pygments.unistring as uni |
|
20 |
|
21 __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer', |
|
22 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer', |
|
23 'CoffeeScriptLexer', 'MaskLexer', 'EarlGreyLexer', 'JuttleLexer'] |
|
24 |
|
25 JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + |
|
26 ']|\\\\u[a-fA-F0-9]{4})') |
|
27 JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', |
|
28 'Mn', 'Mc', 'Nd', 'Pc') + |
|
29 u'\u200c\u200d]|\\\\u[a-fA-F0-9]{4})') |
|
30 JS_IDENT = JS_IDENT_START + '(?:' + JS_IDENT_PART + ')*' |
|
31 |
|
32 |
|
33 class JavascriptLexer(RegexLexer): |
|
34 """ |
|
35 For JavaScript source code. |
|
36 """ |
|
37 |
|
38 name = 'JavaScript' |
|
39 aliases = ['js', 'javascript'] |
|
40 filenames = ['*.js', '*.jsm'] |
|
41 mimetypes = ['application/javascript', 'application/x-javascript', |
|
42 'text/x-javascript', 'text/javascript'] |
|
43 |
|
44 flags = re.DOTALL | re.UNICODE | re.MULTILINE |
|
45 |
|
46 tokens = { |
|
47 'commentsandwhitespace': [ |
|
48 (r'\s+', Text), |
|
49 (r'<!--', Comment), |
|
50 (r'//.*?\n', Comment.Single), |
|
51 (r'/\*.*?\*/', Comment.Multiline) |
|
52 ], |
|
53 'slashstartsregex': [ |
|
54 include('commentsandwhitespace'), |
|
55 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
56 r'([gimuy]+\b|\B)', String.Regex, '#pop'), |
|
57 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
58 default('#pop') |
|
59 ], |
|
60 'badregex': [ |
|
61 (r'\n', Text, '#pop') |
|
62 ], |
|
63 'root': [ |
|
64 (r'\A#! ?/.*?\n', Comment.Hashbang), # recognized by node.js |
|
65 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
66 include('commentsandwhitespace'), |
|
67 (r'(\.\d+|[0-9]+\.[0-9]*)([eE][-+]?[0-9]+)?', Number.Float), |
|
68 (r'0[bB][01]+', Number.Bin), |
|
69 (r'0[oO][0-7]+', Number.Oct), |
|
70 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
71 (r'[0-9]+', Number.Integer), |
|
72 (r'\.\.\.|=>', Punctuation), |
|
73 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
74 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), |
|
75 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
76 (r'[})\].]', Punctuation), |
|
77 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
78 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|' |
|
79 r'this|of)\b', Keyword, 'slashstartsregex'), |
|
80 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
81 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
82 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
83 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
84 r'transient|volatile)\b', Keyword.Reserved), |
|
85 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
86 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
87 r'Number|Object|Packages|RegExp|String|Promise|Proxy|sun|decodeURI|' |
|
88 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
89 r'Error|eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|' |
|
90 r'document|this|window)\b', Name.Builtin), |
|
91 (JS_IDENT, Name.Other), |
|
92 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
93 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
94 (r'`', String.Backtick, 'interp'), |
|
95 ], |
|
96 'interp': [ |
|
97 (r'`', String.Backtick, '#pop'), |
|
98 (r'\\\\', String.Backtick), |
|
99 (r'\\`', String.Backtick), |
|
100 (r'\$\{', String.Interpol, 'interp-inside'), |
|
101 (r'\$', String.Backtick), |
|
102 (r'[^`\\$]+', String.Backtick), |
|
103 ], |
|
104 'interp-inside': [ |
|
105 # TODO: should this include single-line comments and allow nesting strings? |
|
106 (r'\}', String.Interpol, '#pop'), |
|
107 include('root'), |
|
108 ], |
|
109 # (\\\\|\\`|[^`])*`', String.Backtick), |
|
110 } |
|
111 |
|
112 |
|
113 class KalLexer(RegexLexer): |
|
114 """ |
|
115 For `Kal`_ source code. |
|
116 |
|
117 .. _Kal: http://rzimmerman.github.io/kal |
|
118 |
|
119 |
|
120 .. versionadded:: 2.0 |
|
121 """ |
|
122 |
|
123 name = 'Kal' |
|
124 aliases = ['kal'] |
|
125 filenames = ['*.kal'] |
|
126 mimetypes = ['text/kal', 'application/kal'] |
|
127 |
|
128 flags = re.DOTALL |
|
129 tokens = { |
|
130 'commentsandwhitespace': [ |
|
131 (r'\s+', Text), |
|
132 (r'###[^#].*?###', Comment.Multiline), |
|
133 (r'#(?!##[^#]).*?\n', Comment.Single), |
|
134 ], |
|
135 'functiondef': [ |
|
136 (r'[$a-zA-Z_][\w$]*\s*', Name.Function, '#pop'), |
|
137 include('commentsandwhitespace'), |
|
138 ], |
|
139 'classdef': [ |
|
140 (r'\binherits\s+from\b', Keyword), |
|
141 (r'[$a-zA-Z_][\w$]*\s*\n', Name.Class, '#pop'), |
|
142 (r'[$a-zA-Z_][\w$]*\s*', Name.Class), |
|
143 include('commentsandwhitespace'), |
|
144 ], |
|
145 'listcomprehension': [ |
|
146 (r'\]', Punctuation, '#pop'), |
|
147 (r'\b(property|value)\b', Keyword), |
|
148 include('root'), |
|
149 ], |
|
150 'waitfor': [ |
|
151 (r'\n', Punctuation, '#pop'), |
|
152 (r'\bfrom\b', Keyword), |
|
153 include('root'), |
|
154 ], |
|
155 'root': [ |
|
156 include('commentsandwhitespace'), |
|
157 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
158 r'([gim]+\b|\B)', String.Regex), |
|
159 (r'\?|:|_(?=\n)|==?|!=|-(?!>)|[<>+*/-]=?', |
|
160 Operator), |
|
161 (r'\b(and|or|isnt|is|not|but|bitwise|mod|\^|xor|exists|' |
|
162 r'doesnt\s+exist)\b', Operator.Word), |
|
163 (r'(?:\([^()]+\))?\s*>', Name.Function), |
|
164 (r'[{(]', Punctuation), |
|
165 (r'\[', Punctuation, 'listcomprehension'), |
|
166 (r'[})\].,]', Punctuation), |
|
167 (r'\b(function|method|task)\b', Keyword.Declaration, 'functiondef'), |
|
168 (r'\bclass\b', Keyword.Declaration, 'classdef'), |
|
169 (r'\b(safe\s+)?wait\s+for\b', Keyword, 'waitfor'), |
|
170 (r'\b(me|this)(\.[$a-zA-Z_][\w.$]*)?\b', Name.Variable.Instance), |
|
171 (r'(?<![.$])(for(\s+(parallel|series))?|in|of|while|until|' |
|
172 r'break|return|continue|' |
|
173 r'when|if|unless|else|otherwise|except\s+when|' |
|
174 r'throw|raise|fail\s+with|try|catch|finally|new|delete|' |
|
175 r'typeof|instanceof|super|run\s+in\s+parallel|' |
|
176 r'inherits\s+from)\b', Keyword), |
|
177 (r'(?<![.$])(true|false|yes|no|on|off|null|nothing|none|' |
|
178 r'NaN|Infinity|undefined)\b', |
|
179 Keyword.Constant), |
|
180 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
181 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
182 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
183 r'eval|isFinite|isNaN|isSafeInteger|parseFloat|parseInt|document|' |
|
184 r'window|' |
|
185 r'print)\b', |
|
186 Name.Builtin), |
|
187 (r'[$a-zA-Z_][\w.$]*\s*(:|[+\-*/]?\=)?\b', Name.Variable), |
|
188 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
189 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
190 (r'[0-9]+', Number.Integer), |
|
191 ('"""', String, 'tdqs'), |
|
192 ("'''", String, 'tsqs'), |
|
193 ('"', String, 'dqs'), |
|
194 ("'", String, 'sqs'), |
|
195 ], |
|
196 'strings': [ |
|
197 (r'[^#\\\'"]+', String), |
|
198 # note that all kal strings are multi-line. |
|
199 # hashmarks, quotes and backslashes must be parsed one at a time |
|
200 ], |
|
201 'interpoling_string': [ |
|
202 (r'\}', String.Interpol, "#pop"), |
|
203 include('root') |
|
204 ], |
|
205 'dqs': [ |
|
206 (r'"', String, '#pop'), |
|
207 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
208 (r'#\{', String.Interpol, "interpoling_string"), |
|
209 include('strings') |
|
210 ], |
|
211 'sqs': [ |
|
212 (r"'", String, '#pop'), |
|
213 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
214 include('strings') |
|
215 ], |
|
216 'tdqs': [ |
|
217 (r'"""', String, '#pop'), |
|
218 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
219 (r'#\{', String.Interpol, "interpoling_string"), |
|
220 include('strings'), |
|
221 ], |
|
222 'tsqs': [ |
|
223 (r"'''", String, '#pop'), |
|
224 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
225 include('strings') |
|
226 ], |
|
227 } |
|
228 |
|
229 |
|
230 class LiveScriptLexer(RegexLexer): |
|
231 """ |
|
232 For `LiveScript`_ source code. |
|
233 |
|
234 .. _LiveScript: http://gkz.github.com/LiveScript/ |
|
235 |
|
236 .. versionadded:: 1.6 |
|
237 """ |
|
238 |
|
239 name = 'LiveScript' |
|
240 aliases = ['live-script', 'livescript'] |
|
241 filenames = ['*.ls'] |
|
242 mimetypes = ['text/livescript'] |
|
243 |
|
244 flags = re.DOTALL |
|
245 tokens = { |
|
246 'commentsandwhitespace': [ |
|
247 (r'\s+', Text), |
|
248 (r'/\*.*?\*/', Comment.Multiline), |
|
249 (r'#.*?\n', Comment.Single), |
|
250 ], |
|
251 'multilineregex': [ |
|
252 include('commentsandwhitespace'), |
|
253 (r'//([gim]+\b|\B)', String.Regex, '#pop'), |
|
254 (r'/', String.Regex), |
|
255 (r'[^/#]+', String.Regex) |
|
256 ], |
|
257 'slashstartsregex': [ |
|
258 include('commentsandwhitespace'), |
|
259 (r'//', String.Regex, ('#pop', 'multilineregex')), |
|
260 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
261 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
262 default('#pop'), |
|
263 ], |
|
264 'root': [ |
|
265 # this next expr leads to infinite loops root -> slashstartsregex |
|
266 # (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
267 include('commentsandwhitespace'), |
|
268 (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' |
|
269 r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), |
|
270 (r'\+\+|&&|(?<![.$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' |
|
271 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' |
|
272 r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|' |
|
273 r'[+*`%&|^/])=?', |
|
274 Operator, 'slashstartsregex'), |
|
275 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
276 (r'[})\].]', Punctuation), |
|
277 (r'(?<![.$])(for|own|in|of|while|until|loop|break|' |
|
278 r'return|continue|switch|when|then|if|unless|else|' |
|
279 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' |
|
280 r'extends|this|class|by|const|var|to|til)\b', Keyword, |
|
281 'slashstartsregex'), |
|
282 (r'(?<![.$])(true|false|yes|no|on|off|' |
|
283 r'null|NaN|Infinity|undefined|void)\b', |
|
284 Keyword.Constant), |
|
285 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
286 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
287 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
288 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', |
|
289 Name.Builtin), |
|
290 (r'[$a-zA-Z_][\w.\-:$]*\s*[:=]\s', Name.Variable, |
|
291 'slashstartsregex'), |
|
292 (r'@[$a-zA-Z_][\w.\-:$]*\s*[:=]\s', Name.Variable.Instance, |
|
293 'slashstartsregex'), |
|
294 (r'@', Name.Other, 'slashstartsregex'), |
|
295 (r'@?[$a-zA-Z_][\w-]*', Name.Other, 'slashstartsregex'), |
|
296 (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float), |
|
297 (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer), |
|
298 ('"""', String, 'tdqs'), |
|
299 ("'''", String, 'tsqs'), |
|
300 ('"', String, 'dqs'), |
|
301 ("'", String, 'sqs'), |
|
302 (r'\\\S+', String), |
|
303 (r'<\[.*?\]>', String), |
|
304 ], |
|
305 'strings': [ |
|
306 (r'[^#\\\'"]+', String), |
|
307 # note that all coffee script strings are multi-line. |
|
308 # hashmarks, quotes and backslashes must be parsed one at a time |
|
309 ], |
|
310 'interpoling_string': [ |
|
311 (r'\}', String.Interpol, "#pop"), |
|
312 include('root') |
|
313 ], |
|
314 'dqs': [ |
|
315 (r'"', String, '#pop'), |
|
316 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
317 (r'#\{', String.Interpol, "interpoling_string"), |
|
318 (r'#', String), |
|
319 include('strings') |
|
320 ], |
|
321 'sqs': [ |
|
322 (r"'", String, '#pop'), |
|
323 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
324 include('strings') |
|
325 ], |
|
326 'tdqs': [ |
|
327 (r'"""', String, '#pop'), |
|
328 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
329 (r'#\{', String.Interpol, "interpoling_string"), |
|
330 (r'#', String), |
|
331 include('strings'), |
|
332 ], |
|
333 'tsqs': [ |
|
334 (r"'''", String, '#pop'), |
|
335 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
336 include('strings') |
|
337 ], |
|
338 } |
|
339 |
|
340 |
|
341 class DartLexer(RegexLexer): |
|
342 """ |
|
343 For `Dart <http://dartlang.org/>`_ source code. |
|
344 |
|
345 .. versionadded:: 1.5 |
|
346 """ |
|
347 |
|
348 name = 'Dart' |
|
349 aliases = ['dart'] |
|
350 filenames = ['*.dart'] |
|
351 mimetypes = ['text/x-dart'] |
|
352 |
|
353 flags = re.MULTILINE | re.DOTALL |
|
354 |
|
355 tokens = { |
|
356 'root': [ |
|
357 include('string_literal'), |
|
358 (r'#!(.*?)$', Comment.Preproc), |
|
359 (r'\b(import|export)\b', Keyword, 'import_decl'), |
|
360 (r'\b(library|source|part of|part)\b', Keyword), |
|
361 (r'[^\S\n]+', Text), |
|
362 (r'//.*?\n', Comment.Single), |
|
363 (r'/\*.*?\*/', Comment.Multiline), |
|
364 (r'\b(class)\b(\s+)', |
|
365 bygroups(Keyword.Declaration, Text), 'class'), |
|
366 (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|' |
|
367 r'if|in|is|new|return|super|switch|this|throw|try|while)\b', |
|
368 Keyword), |
|
369 (r'\b(abstract|async|await|const|extends|factory|final|get|' |
|
370 r'implements|native|operator|set|static|sync|typedef|var|with|' |
|
371 r'yield)\b', Keyword.Declaration), |
|
372 (r'\b(bool|double|dynamic|int|num|Object|String|void)\b', Keyword.Type), |
|
373 (r'\b(false|null|true)\b', Keyword.Constant), |
|
374 (r'[~!%^&*+=|?:<>/-]|as\b', Operator), |
|
375 (r'[a-zA-Z_$]\w*:', Name.Label), |
|
376 (r'[a-zA-Z_$]\w*', Name), |
|
377 (r'[(){}\[\],.;]', Punctuation), |
|
378 (r'0[xX][0-9a-fA-F]+', Number.Hex), |
|
379 # DIGIT+ (‘.’ DIGIT*)? EXPONENT? |
|
380 (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number), |
|
381 (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT? |
|
382 (r'\n', Text) |
|
383 # pseudo-keyword negate intentionally left out |
|
384 ], |
|
385 'class': [ |
|
386 (r'[a-zA-Z_$]\w*', Name.Class, '#pop') |
|
387 ], |
|
388 'import_decl': [ |
|
389 include('string_literal'), |
|
390 (r'\s+', Text), |
|
391 (r'\b(as|show|hide)\b', Keyword), |
|
392 (r'[a-zA-Z_$]\w*', Name), |
|
393 (r'\,', Punctuation), |
|
394 (r'\;', Punctuation, '#pop') |
|
395 ], |
|
396 'string_literal': [ |
|
397 # Raw strings. |
|
398 (r'r"""([\w\W]*?)"""', String.Double), |
|
399 (r"r'''([\w\W]*?)'''", String.Single), |
|
400 (r'r"(.*?)"', String.Double), |
|
401 (r"r'(.*?)'", String.Single), |
|
402 # Normal Strings. |
|
403 (r'"""', String.Double, 'string_double_multiline'), |
|
404 (r"'''", String.Single, 'string_single_multiline'), |
|
405 (r'"', String.Double, 'string_double'), |
|
406 (r"'", String.Single, 'string_single') |
|
407 ], |
|
408 'string_common': [ |
|
409 (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z'\"$\\])", |
|
410 String.Escape), |
|
411 (r'(\$)([a-zA-Z_]\w*)', bygroups(String.Interpol, Name)), |
|
412 (r'(\$\{)(.*?)(\})', |
|
413 bygroups(String.Interpol, using(this), String.Interpol)) |
|
414 ], |
|
415 'string_double': [ |
|
416 (r'"', String.Double, '#pop'), |
|
417 (r'[^"$\\\n]+', String.Double), |
|
418 include('string_common'), |
|
419 (r'\$+', String.Double) |
|
420 ], |
|
421 'string_double_multiline': [ |
|
422 (r'"""', String.Double, '#pop'), |
|
423 (r'[^"$\\]+', String.Double), |
|
424 include('string_common'), |
|
425 (r'(\$|\")+', String.Double) |
|
426 ], |
|
427 'string_single': [ |
|
428 (r"'", String.Single, '#pop'), |
|
429 (r"[^'$\\\n]+", String.Single), |
|
430 include('string_common'), |
|
431 (r'\$+', String.Single) |
|
432 ], |
|
433 'string_single_multiline': [ |
|
434 (r"'''", String.Single, '#pop'), |
|
435 (r'[^\'$\\]+', String.Single), |
|
436 include('string_common'), |
|
437 (r'(\$|\')+', String.Single) |
|
438 ] |
|
439 } |
|
440 |
|
441 |
|
442 class TypeScriptLexer(RegexLexer): |
|
443 """ |
|
444 For `TypeScript <http://typescriptlang.org/>`_ source code. |
|
445 |
|
446 .. versionadded:: 1.6 |
|
447 """ |
|
448 |
|
449 name = 'TypeScript' |
|
450 aliases = ['ts', 'typescript'] |
|
451 filenames = ['*.ts', '*.tsx'] |
|
452 mimetypes = ['text/x-typescript'] |
|
453 |
|
454 flags = re.DOTALL | re.MULTILINE |
|
455 |
|
456 tokens = { |
|
457 'commentsandwhitespace': [ |
|
458 (r'\s+', Text), |
|
459 (r'<!--', Comment), |
|
460 (r'//.*?\n', Comment.Single), |
|
461 (r'/\*.*?\*/', Comment.Multiline) |
|
462 ], |
|
463 'slashstartsregex': [ |
|
464 include('commentsandwhitespace'), |
|
465 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
466 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
467 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
468 default('#pop') |
|
469 ], |
|
470 'badregex': [ |
|
471 (r'\n', Text, '#pop') |
|
472 ], |
|
473 'root': [ |
|
474 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
475 include('commentsandwhitespace'), |
|
476 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
477 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), |
|
478 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
479 (r'[})\].]', Punctuation), |
|
480 (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' |
|
481 r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
482 r'this)\b', Keyword, 'slashstartsregex'), |
|
483 (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
484 (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' |
|
485 r'extends|final|float|goto|implements|import|int|interface|long|native|' |
|
486 r'package|private|protected|public|short|static|super|synchronized|throws|' |
|
487 r'transient|volatile)\b', Keyword.Reserved), |
|
488 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
489 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
490 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
491 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
492 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
493 r'window)\b', Name.Builtin), |
|
494 # Match stuff like: module name {...} |
|
495 (r'\b(module)(\s*)(\s*[\w?.$][\w?.$]*)(\s*)', |
|
496 bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'), |
|
497 # Match variable type keywords |
|
498 (r'\b(string|bool|number)\b', Keyword.Type), |
|
499 # Match stuff like: constructor |
|
500 (r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved), |
|
501 # Match stuff like: super(argument, list) |
|
502 (r'(super)(\s*)(\([\w,?.$\s]+\s*\))', |
|
503 bygroups(Keyword.Reserved, Text), 'slashstartsregex'), |
|
504 # Match stuff like: function() {...} |
|
505 (r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'), |
|
506 # Match stuff like: (function: return type) |
|
507 (r'([\w?.$][\w?.$]*)(\s*:\s*)([\w?.$][\w?.$]*)', |
|
508 bygroups(Name.Other, Text, Keyword.Type)), |
|
509 (r'[$a-zA-Z_]\w*', Name.Other), |
|
510 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
511 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
512 (r'[0-9]+', Number.Integer), |
|
513 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
514 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
515 (r'`', String.Backtick, 'interp'), |
|
516 # Match stuff like: Decorators |
|
517 (r'@\w+', Keyword.Declaration), |
|
518 ], |
|
519 |
|
520 # The 'interp*' rules match those in JavascriptLexer. Changes made |
|
521 # there should be reflected here as well. |
|
522 'interp': [ |
|
523 (r'`', String.Backtick, '#pop'), |
|
524 (r'\\\\', String.Backtick), |
|
525 (r'\\`', String.Backtick), |
|
526 (r'\$\{', String.Interpol, 'interp-inside'), |
|
527 (r'\$', String.Backtick), |
|
528 (r'[^`\\$]+', String.Backtick), |
|
529 ], |
|
530 'interp-inside': [ |
|
531 # TODO: should this include single-line comments and allow nesting strings? |
|
532 (r'\}', String.Interpol, '#pop'), |
|
533 include('root'), |
|
534 ], |
|
535 } |
|
536 |
|
537 def analyse_text(text): |
|
538 if re.search(r'^(import.+(from\s+)?["\']|' |
|
539 r'(export\s*)?(interface|class|function)\s+)', |
|
540 text, re.MULTILINE): |
|
541 return 1.0 |
|
542 |
|
543 |
|
544 class LassoLexer(RegexLexer): |
|
545 """ |
|
546 For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 |
|
547 syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in |
|
548 HTML, use the `LassoHtmlLexer`. |
|
549 |
|
550 Additional options accepted: |
|
551 |
|
552 `builtinshighlighting` |
|
553 If given and ``True``, highlight builtin types, traits, methods, and |
|
554 members (default: ``True``). |
|
555 `requiredelimiters` |
|
556 If given and ``True``, only highlight code between delimiters as Lasso |
|
557 (default: ``False``). |
|
558 |
|
559 .. versionadded:: 1.6 |
|
560 """ |
|
561 |
|
562 name = 'Lasso' |
|
563 aliases = ['lasso', 'lassoscript'] |
|
564 filenames = ['*.lasso', '*.lasso[89]'] |
|
565 alias_filenames = ['*.incl', '*.inc', '*.las'] |
|
566 mimetypes = ['text/x-lasso'] |
|
567 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE |
|
568 |
|
569 tokens = { |
|
570 'root': [ |
|
571 (r'^#![ \S]+lasso9\b', Comment.Preproc, 'lasso'), |
|
572 (r'(?=\[|<)', Other, 'delimiters'), |
|
573 (r'\s+', Other), |
|
574 default(('delimiters', 'lassofile')), |
|
575 ], |
|
576 'delimiters': [ |
|
577 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), |
|
578 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), |
|
579 (r'\[', Comment.Preproc, 'squarebrackets'), |
|
580 (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'), |
|
581 (r'<(!--.*?-->)?', Other), |
|
582 (r'[^[<]+', Other), |
|
583 ], |
|
584 'nosquarebrackets': [ |
|
585 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), |
|
586 (r'\[', Other), |
|
587 (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'), |
|
588 (r'<(!--.*?-->)?', Other), |
|
589 (r'[^[<]+', Other), |
|
590 ], |
|
591 'noprocess': [ |
|
592 (r'\[/noprocess\]', Comment.Preproc, '#pop'), |
|
593 (r'\[', Other), |
|
594 (r'[^[]', Other), |
|
595 ], |
|
596 'squarebrackets': [ |
|
597 (r'\]', Comment.Preproc, '#pop'), |
|
598 include('lasso'), |
|
599 ], |
|
600 'anglebrackets': [ |
|
601 (r'\?>', Comment.Preproc, '#pop'), |
|
602 include('lasso'), |
|
603 ], |
|
604 'lassofile': [ |
|
605 (r'\]|\?>', Comment.Preproc, '#pop'), |
|
606 include('lasso'), |
|
607 ], |
|
608 'whitespacecomments': [ |
|
609 (r'\s+', Text), |
|
610 (r'//.*?\n', Comment.Single), |
|
611 (r'/\*\*!.*?\*/', String.Doc), |
|
612 (r'/\*.*?\*/', Comment.Multiline), |
|
613 ], |
|
614 'lasso': [ |
|
615 # whitespace/comments |
|
616 include('whitespacecomments'), |
|
617 |
|
618 # literals |
|
619 (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), |
|
620 (r'0x[\da-f]+', Number.Hex), |
|
621 (r'\d+', Number.Integer), |
|
622 (r'(infinity|NaN)\b', Number), |
|
623 (r"'", String.Single, 'singlestring'), |
|
624 (r'"', String.Double, 'doublestring'), |
|
625 (r'`[^`]*`', String.Backtick), |
|
626 |
|
627 # names |
|
628 (r'\$[a-z_][\w.]*', Name.Variable), |
|
629 (r'#([a-z_][\w.]*|\d+\b)', Name.Variable.Instance), |
|
630 (r"(\.\s*)('[a-z_][\w.]*')", |
|
631 bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), |
|
632 (r"(self)(\s*->\s*)('[a-z_][\w.]*')", |
|
633 bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), |
|
634 (r'(\.\.?\s*)([a-z_][\w.]*(=(?!=))?)', |
|
635 bygroups(Name.Builtin.Pseudo, Name.Other.Member)), |
|
636 (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)', |
|
637 bygroups(Operator, Name.Other.Member)), |
|
638 (r'(?<!->)(self|inherited|currentcapture|givenblock)\b', |
|
639 Name.Builtin.Pseudo), |
|
640 (r'-(?!infinity)[a-z_][\w.]*', Name.Attribute), |
|
641 (r'::\s*[a-z_][\w.]*', Name.Label), |
|
642 (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' |
|
643 r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' |
|
644 r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' |
|
645 r'Error_InvalidDatabase|Error_InvalidPassword|' |
|
646 r'Error_InvalidUsername|Error_ModuleNotFound|' |
|
647 r'Error_NoError|Error_NoPermission|Error_OutOfMemory|' |
|
648 r'Error_ReqColumnMissing|Error_ReqFieldMissing|' |
|
649 r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|' |
|
650 r'Error_UpdateError)\b', Name.Exception), |
|
651 |
|
652 # definitions |
|
653 (r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b', |
|
654 bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)), |
|
655 (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%])', |
|
656 bygroups(Keyword.Declaration, Text, Name.Class, Operator, |
|
657 Name.Function), 'signature'), |
|
658 (r'(define)(\s+)([a-z_][\w.]*)', |
|
659 bygroups(Keyword.Declaration, Text, Name.Function), 'signature'), |
|
660 (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|[-+*/%])' |
|
661 r'(?=\s*\())', bygroups(Keyword, Text, Name.Function), |
|
662 'signature'), |
|
663 (r'(public|protected|private|provide)(\s+)([a-z_][\w.]*)', |
|
664 bygroups(Keyword, Text, Name.Function)), |
|
665 |
|
666 # keywords |
|
667 (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant), |
|
668 (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration), |
|
669 (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' |
|
670 r'null|boolean|bytes|keyword|list|locale|queue|set|stack|' |
|
671 r'staticarray)\b', Keyword.Type), |
|
672 (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)), |
|
673 (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)), |
|
674 (r'require\b', Keyword, 'requiresection'), |
|
675 (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)), |
|
676 (r'(/?)(Cache|Database_Names|Database_SchemaNames|' |
|
677 r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' |
|
678 r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' |
|
679 r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' |
|
680 r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|Link_FirstRecord|' |
|
681 r'Link_LastGroup|Link_LastRecord|Link_NextGroup|Link_NextRecord|' |
|
682 r'Link_PrevGroup|Link_PrevRecord|Log|Loop|Output_None|Portal|' |
|
683 r'Private|Protect|Records|Referer|Referrer|Repeating|ResultSet|' |
|
684 r'Rows|Search_Args|Search_Arguments|Select|Sort_Args|' |
|
685 r'Sort_Arguments|Thread_Atomic|Value_List|While|Abort|Case|Else|' |
|
686 r'Fail_If|Fail_IfNot|Fail|If_Empty|If_False|If_Null|If_True|' |
|
687 r'Loop_Abort|Loop_Continue|Loop_Count|Params|Params_Up|Return|' |
|
688 r'Return_Value|Run_Children|SOAP_DefineTag|SOAP_LastRequest|' |
|
689 r'SOAP_LastResponse|Tag_Name|ascending|average|by|define|' |
|
690 r'descending|do|equals|frozen|group|handle_failure|import|in|into|' |
|
691 r'join|let|match|max|min|on|order|parent|protected|provide|public|' |
|
692 r'require|returnhome|skip|split_thread|sum|take|thread|to|trait|' |
|
693 r'type|where|with|yield|yieldhome)\b', |
|
694 bygroups(Punctuation, Keyword)), |
|
695 |
|
696 # other |
|
697 (r',', Punctuation, 'commamember'), |
|
698 (r'(and|or|not)\b', Operator.Word), |
|
699 (r'([a-z_][\w.]*)(\s*::\s*[a-z_][\w.]*)?(\s*=(?!=))', |
|
700 bygroups(Name, Name.Label, Operator)), |
|
701 (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), |
|
702 (r'(=)(n?bw|n?ew|n?cn|lte?|gte?|n?eq|n?rx|ft)\b', |
|
703 bygroups(Operator, Operator.Word)), |
|
704 (r':=|[-+*/%=<>&|!?\\]+', Operator), |
|
705 (r'[{}():;,@^]', Punctuation), |
|
706 ], |
|
707 'singlestring': [ |
|
708 (r"'", String.Single, '#pop'), |
|
709 (r"[^'\\]+", String.Single), |
|
710 include('escape'), |
|
711 (r"\\", String.Single), |
|
712 ], |
|
713 'doublestring': [ |
|
714 (r'"', String.Double, '#pop'), |
|
715 (r'[^"\\]+', String.Double), |
|
716 include('escape'), |
|
717 (r'\\', String.Double), |
|
718 ], |
|
719 'escape': [ |
|
720 (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:\n\r]+:|' |
|
721 r'[abefnrtv?"\'\\]|$)', String.Escape), |
|
722 ], |
|
723 'signature': [ |
|
724 (r'=>', Operator, '#pop'), |
|
725 (r'\)', Punctuation, '#pop'), |
|
726 (r'[(,]', Punctuation, 'parameter'), |
|
727 include('lasso'), |
|
728 ], |
|
729 'parameter': [ |
|
730 (r'\)', Punctuation, '#pop'), |
|
731 (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'), |
|
732 (r'\.\.\.', Name.Builtin.Pseudo), |
|
733 include('lasso'), |
|
734 ], |
|
735 'requiresection': [ |
|
736 (r'(([a-z_][\w.]*=?|[-+*/%])(?=\s*\())', Name, 'requiresignature'), |
|
737 (r'(([a-z_][\w.]*=?|[-+*/%])(?=(\s*::\s*[\w.]+)?\s*,))', Name), |
|
738 (r'[a-z_][\w.]*=?|[-+*/%]', Name, '#pop'), |
|
739 (r'::\s*[a-z_][\w.]*', Name.Label), |
|
740 (r',', Punctuation), |
|
741 include('whitespacecomments'), |
|
742 ], |
|
743 'requiresignature': [ |
|
744 (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'), |
|
745 (r'\)', Punctuation, '#pop:2'), |
|
746 (r'-?[a-z_][\w.]*', Name.Attribute), |
|
747 (r'::\s*[a-z_][\w.]*', Name.Label), |
|
748 (r'\.\.\.', Name.Builtin.Pseudo), |
|
749 (r'[(,]', Punctuation), |
|
750 include('whitespacecomments'), |
|
751 ], |
|
752 'commamember': [ |
|
753 (r'(([a-z_][\w.]*=?|[-+*/%])' |
|
754 r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))', |
|
755 Name.Function, 'signature'), |
|
756 include('whitespacecomments'), |
|
757 default('#pop'), |
|
758 ], |
|
759 } |
|
760 |
|
761 def __init__(self, **options): |
|
762 self.builtinshighlighting = get_bool_opt( |
|
763 options, 'builtinshighlighting', True) |
|
764 self.requiredelimiters = get_bool_opt( |
|
765 options, 'requiredelimiters', False) |
|
766 |
|
767 self._builtins = set() |
|
768 self._members = set() |
|
769 if self.builtinshighlighting: |
|
770 from pygments.lexers._lasso_builtins import BUILTINS, MEMBERS |
|
771 for key, value in iteritems(BUILTINS): |
|
772 self._builtins.update(value) |
|
773 for key, value in iteritems(MEMBERS): |
|
774 self._members.update(value) |
|
775 RegexLexer.__init__(self, **options) |
|
776 |
|
777 def get_tokens_unprocessed(self, text): |
|
778 stack = ['root'] |
|
779 if self.requiredelimiters: |
|
780 stack.append('delimiters') |
|
781 for index, token, value in \ |
|
782 RegexLexer.get_tokens_unprocessed(self, text, stack): |
|
783 if (token is Name.Other and value.lower() in self._builtins or |
|
784 token is Name.Other.Member and |
|
785 value.lower().rstrip('=') in self._members): |
|
786 yield index, Name.Builtin, value |
|
787 continue |
|
788 yield index, token, value |
|
789 |
|
790 def analyse_text(text): |
|
791 rv = 0.0 |
|
792 if 'bin/lasso9' in text: |
|
793 rv += 0.8 |
|
794 if re.search(r'<\?lasso', text, re.I): |
|
795 rv += 0.4 |
|
796 if re.search(r'local\(', text, re.I): |
|
797 rv += 0.4 |
|
798 return rv |
|
799 |
|
800 |
|
801 class ObjectiveJLexer(RegexLexer): |
|
802 """ |
|
803 For Objective-J source code with preprocessor directives. |
|
804 |
|
805 .. versionadded:: 1.3 |
|
806 """ |
|
807 |
|
808 name = 'Objective-J' |
|
809 aliases = ['objective-j', 'objectivej', 'obj-j', 'objj'] |
|
810 filenames = ['*.j'] |
|
811 mimetypes = ['text/x-objective-j'] |
|
812 |
|
813 #: optional Comment or Whitespace |
|
814 _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)*' |
|
815 |
|
816 flags = re.DOTALL | re.MULTILINE |
|
817 |
|
818 tokens = { |
|
819 'root': [ |
|
820 include('whitespace'), |
|
821 |
|
822 # function definition |
|
823 (r'^(' + _ws + r'[+-]' + _ws + r')([(a-zA-Z_].*?[^(])(' + _ws + r'\{)', |
|
824 bygroups(using(this), using(this, state='function_signature'), |
|
825 using(this))), |
|
826 |
|
827 # class definition |
|
828 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text), |
|
829 'classname'), |
|
830 (r'(@class|@protocol)(\s*)', bygroups(Keyword, Text), |
|
831 'forward_classname'), |
|
832 (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)), |
|
833 |
|
834 include('statements'), |
|
835 ('[{()}]', Punctuation), |
|
836 (';', Punctuation), |
|
837 ], |
|
838 'whitespace': [ |
|
839 (r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")', |
|
840 bygroups(Comment.Preproc, Text, String.Double)), |
|
841 (r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)', |
|
842 bygroups(Comment.Preproc, Text, String.Double)), |
|
843 (r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")', |
|
844 bygroups(Comment.Preproc, Text, String.Double)), |
|
845 (r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)', |
|
846 bygroups(Comment.Preproc, Text, String.Double)), |
|
847 |
|
848 (r'#if\s+0', Comment.Preproc, 'if0'), |
|
849 (r'#', Comment.Preproc, 'macro'), |
|
850 |
|
851 (r'\n', Text), |
|
852 (r'\s+', Text), |
|
853 (r'\\\n', Text), # line continuation |
|
854 (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single), |
|
855 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
856 (r'<!--', Comment), |
|
857 ], |
|
858 'slashstartsregex': [ |
|
859 include('whitespace'), |
|
860 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
861 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
862 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
863 default('#pop'), |
|
864 ], |
|
865 'badregex': [ |
|
866 (r'\n', Text, '#pop'), |
|
867 ], |
|
868 'statements': [ |
|
869 (r'(L|@)?"', String, 'string'), |
|
870 (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", |
|
871 String.Char), |
|
872 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
873 (r"'(\\\\|\\'|[^'])*'", String.Single), |
|
874 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), |
|
875 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
876 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), |
|
877 (r'0[0-7]+[Ll]?', Number.Oct), |
|
878 (r'\d+[Ll]?', Number.Integer), |
|
879 |
|
880 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), |
|
881 |
|
882 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
883 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', |
|
884 Operator, 'slashstartsregex'), |
|
885 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
886 (r'[})\].]', Punctuation), |
|
887 |
|
888 (r'(for|in|while|do|break|return|continue|switch|case|default|if|' |
|
889 r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|' |
|
890 r'prototype|__proto__)\b', Keyword, 'slashstartsregex'), |
|
891 |
|
892 (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'), |
|
893 |
|
894 (r'(@selector|@private|@protected|@public|@encode|' |
|
895 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' |
|
896 r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword), |
|
897 |
|
898 (r'(int|long|float|short|double|char|unsigned|signed|void|' |
|
899 r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b', |
|
900 Keyword.Type), |
|
901 |
|
902 (r'(self|super)\b', Name.Builtin), |
|
903 |
|
904 (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant), |
|
905 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), |
|
906 (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|' |
|
907 r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|' |
|
908 r'SQRT2)\b', Keyword.Constant), |
|
909 |
|
910 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
911 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
912 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
913 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' |
|
914 r'window)\b', Name.Builtin), |
|
915 |
|
916 (r'([$a-zA-Z_]\w*)(' + _ws + r')(?=\()', |
|
917 bygroups(Name.Function, using(this))), |
|
918 |
|
919 (r'[$a-zA-Z_]\w*', Name), |
|
920 ], |
|
921 'classname': [ |
|
922 # interface definition that inherits |
|
923 (r'([a-zA-Z_]\w*)(' + _ws + r':' + _ws + |
|
924 r')([a-zA-Z_]\w*)?', |
|
925 bygroups(Name.Class, using(this), Name.Class), '#pop'), |
|
926 # interface definition for a category |
|
927 (r'([a-zA-Z_]\w*)(' + _ws + r'\()([a-zA-Z_]\w*)(\))', |
|
928 bygroups(Name.Class, using(this), Name.Label, Text), '#pop'), |
|
929 # simple interface / implementation |
|
930 (r'([a-zA-Z_]\w*)', Name.Class, '#pop'), |
|
931 ], |
|
932 'forward_classname': [ |
|
933 (r'([a-zA-Z_]\w*)(\s*,\s*)', |
|
934 bygroups(Name.Class, Text), '#push'), |
|
935 (r'([a-zA-Z_]\w*)(\s*;?)', |
|
936 bygroups(Name.Class, Text), '#pop'), |
|
937 ], |
|
938 'function_signature': [ |
|
939 include('whitespace'), |
|
940 |
|
941 # start of a selector w/ parameters |
|
942 (r'(\(' + _ws + r')' # open paren |
|
943 r'([a-zA-Z_]\w+)' # return type |
|
944 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
945 r'([$a-zA-Z_]\w+' + _ws + r':)', # function name |
|
946 bygroups(using(this), Keyword.Type, using(this), |
|
947 Name.Function), 'function_parameters'), |
|
948 |
|
949 # no-param function |
|
950 (r'(\(' + _ws + r')' # open paren |
|
951 r'([a-zA-Z_]\w+)' # return type |
|
952 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
953 r'([$a-zA-Z_]\w+)', # function name |
|
954 bygroups(using(this), Keyword.Type, using(this), |
|
955 Name.Function), "#pop"), |
|
956 |
|
957 # no return type given, start of a selector w/ parameters |
|
958 (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name |
|
959 bygroups(Name.Function), 'function_parameters'), |
|
960 |
|
961 # no return type given, no-param function |
|
962 (r'([$a-zA-Z_]\w+)', # function name |
|
963 bygroups(Name.Function), "#pop"), |
|
964 |
|
965 default('#pop'), |
|
966 ], |
|
967 'function_parameters': [ |
|
968 include('whitespace'), |
|
969 |
|
970 # parameters |
|
971 (r'(\(' + _ws + ')' # open paren |
|
972 r'([^)]+)' # type |
|
973 r'(' + _ws + r'\)' + _ws + r')' # close paren |
|
974 r'([$a-zA-Z_]\w+)', # param name |
|
975 bygroups(using(this), Keyword.Type, using(this), Text)), |
|
976 |
|
977 # one piece of a selector name |
|
978 (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name |
|
979 Name.Function), |
|
980 |
|
981 # smallest possible selector piece |
|
982 (r'(:)', Name.Function), |
|
983 |
|
984 # var args |
|
985 (r'(,' + _ws + r'\.\.\.)', using(this)), |
|
986 |
|
987 # param name |
|
988 (r'([$a-zA-Z_]\w+)', Text), |
|
989 ], |
|
990 'expression': [ |
|
991 (r'([$a-zA-Z_]\w*)(\()', bygroups(Name.Function, |
|
992 Punctuation)), |
|
993 (r'(\))', Punctuation, "#pop"), |
|
994 ], |
|
995 'string': [ |
|
996 (r'"', String, '#pop'), |
|
997 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
998 (r'[^\\"\n]+', String), # all other characters |
|
999 (r'\\\n', String), # line continuation |
|
1000 (r'\\', String), # stray backslash |
|
1001 ], |
|
1002 'macro': [ |
|
1003 (r'[^/\n]+', Comment.Preproc), |
|
1004 (r'/[*](.|\n)*?[*]/', Comment.Multiline), |
|
1005 (r'//.*?\n', Comment.Single, '#pop'), |
|
1006 (r'/', Comment.Preproc), |
|
1007 (r'(?<=\\)\n', Comment.Preproc), |
|
1008 (r'\n', Comment.Preproc, '#pop'), |
|
1009 ], |
|
1010 'if0': [ |
|
1011 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), |
|
1012 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), |
|
1013 (r'.*?\n', Comment), |
|
1014 ] |
|
1015 } |
|
1016 |
|
1017 def analyse_text(text): |
|
1018 if re.search(r'^\s*@import\s+[<"]', text, re.MULTILINE): |
|
1019 # special directive found in most Objective-J files |
|
1020 return True |
|
1021 return False |
|
1022 |
|
1023 |
|
1024 class CoffeeScriptLexer(RegexLexer): |
|
1025 """ |
|
1026 For `CoffeeScript`_ source code. |
|
1027 |
|
1028 .. _CoffeeScript: http://coffeescript.org |
|
1029 |
|
1030 .. versionadded:: 1.3 |
|
1031 """ |
|
1032 |
|
1033 name = 'CoffeeScript' |
|
1034 aliases = ['coffee-script', 'coffeescript', 'coffee'] |
|
1035 filenames = ['*.coffee'] |
|
1036 mimetypes = ['text/coffeescript'] |
|
1037 |
|
1038 |
|
1039 _operator_re = ( |
|
1040 r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' |
|
1041 r'\|\||\\(?=\n)|' |
|
1042 r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?') |
|
1043 |
|
1044 flags = re.DOTALL |
|
1045 tokens = { |
|
1046 'commentsandwhitespace': [ |
|
1047 (r'\s+', Text), |
|
1048 (r'###[^#].*?###', Comment.Multiline), |
|
1049 (r'#(?!##[^#]).*?\n', Comment.Single), |
|
1050 ], |
|
1051 'multilineregex': [ |
|
1052 (r'[^/#]+', String.Regex), |
|
1053 (r'///([gim]+\b|\B)', String.Regex, '#pop'), |
|
1054 (r'#\{', String.Interpol, 'interpoling_string'), |
|
1055 (r'[/#]', String.Regex), |
|
1056 ], |
|
1057 'slashstartsregex': [ |
|
1058 include('commentsandwhitespace'), |
|
1059 (r'///', String.Regex, ('#pop', 'multilineregex')), |
|
1060 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
1061 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
1062 # This isn't really guarding against mishighlighting well-formed |
|
1063 # code, just the ability to infinite-loop between root and |
|
1064 # slashstartsregex. |
|
1065 (r'/', Operator), |
|
1066 default('#pop'), |
|
1067 ], |
|
1068 'root': [ |
|
1069 include('commentsandwhitespace'), |
|
1070 (r'^(?=\s|/)', Text, 'slashstartsregex'), |
|
1071 (_operator_re, Operator, 'slashstartsregex'), |
|
1072 (r'(?:\([^()]*\))?\s*[=-]>', Name.Function, 'slashstartsregex'), |
|
1073 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
1074 (r'[})\].]', Punctuation), |
|
1075 (r'(?<![.$])(for|own|in|of|while|until|' |
|
1076 r'loop|break|return|continue|' |
|
1077 r'switch|when|then|if|unless|else|' |
|
1078 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' |
|
1079 r'extends|this|class|by)\b', Keyword, 'slashstartsregex'), |
|
1080 (r'(?<![.$])(true|false|yes|no|on|off|null|' |
|
1081 r'NaN|Infinity|undefined)\b', |
|
1082 Keyword.Constant), |
|
1083 (r'(Array|Boolean|Date|Error|Function|Math|netscape|' |
|
1084 r'Number|Object|Packages|RegExp|String|sun|decodeURI|' |
|
1085 r'decodeURIComponent|encodeURI|encodeURIComponent|' |
|
1086 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b', |
|
1087 Name.Builtin), |
|
1088 (r'[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable, |
|
1089 'slashstartsregex'), |
|
1090 (r'@[$a-zA-Z_][\w.:$]*\s*[:=]\s', Name.Variable.Instance, |
|
1091 'slashstartsregex'), |
|
1092 (r'@', Name.Other, 'slashstartsregex'), |
|
1093 (r'@?[$a-zA-Z_][\w$]*', Name.Other), |
|
1094 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
1095 (r'0x[0-9a-fA-F]+', Number.Hex), |
|
1096 (r'[0-9]+', Number.Integer), |
|
1097 ('"""', String, 'tdqs'), |
|
1098 ("'''", String, 'tsqs'), |
|
1099 ('"', String, 'dqs'), |
|
1100 ("'", String, 'sqs'), |
|
1101 ], |
|
1102 'strings': [ |
|
1103 (r'[^#\\\'"]+', String), |
|
1104 # note that all coffee script strings are multi-line. |
|
1105 # hashmarks, quotes and backslashes must be parsed one at a time |
|
1106 ], |
|
1107 'interpoling_string': [ |
|
1108 (r'\}', String.Interpol, "#pop"), |
|
1109 include('root') |
|
1110 ], |
|
1111 'dqs': [ |
|
1112 (r'"', String, '#pop'), |
|
1113 (r'\\.|\'', String), # double-quoted string don't need ' escapes |
|
1114 (r'#\{', String.Interpol, "interpoling_string"), |
|
1115 (r'#', String), |
|
1116 include('strings') |
|
1117 ], |
|
1118 'sqs': [ |
|
1119 (r"'", String, '#pop'), |
|
1120 (r'#|\\.|"', String), # single quoted strings don't need " escapses |
|
1121 include('strings') |
|
1122 ], |
|
1123 'tdqs': [ |
|
1124 (r'"""', String, '#pop'), |
|
1125 (r'\\.|\'|"', String), # no need to escape quotes in triple-string |
|
1126 (r'#\{', String.Interpol, "interpoling_string"), |
|
1127 (r'#', String), |
|
1128 include('strings'), |
|
1129 ], |
|
1130 'tsqs': [ |
|
1131 (r"'''", String, '#pop'), |
|
1132 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings |
|
1133 include('strings') |
|
1134 ], |
|
1135 } |
|
1136 |
|
1137 |
|
1138 class MaskLexer(RegexLexer): |
|
1139 """ |
|
1140 For `Mask <http://github.com/atmajs/MaskJS>`__ markup. |
|
1141 |
|
1142 .. versionadded:: 2.0 |
|
1143 """ |
|
1144 name = 'Mask' |
|
1145 aliases = ['mask'] |
|
1146 filenames = ['*.mask'] |
|
1147 mimetypes = ['text/x-mask'] |
|
1148 |
|
1149 flags = re.MULTILINE | re.IGNORECASE | re.DOTALL |
|
1150 tokens = { |
|
1151 'root': [ |
|
1152 (r'\s+', Text), |
|
1153 (r'//.*?\n', Comment.Single), |
|
1154 (r'/\*.*?\*/', Comment.Multiline), |
|
1155 (r'[{};>]', Punctuation), |
|
1156 (r"'''", String, 'string-trpl-single'), |
|
1157 (r'"""', String, 'string-trpl-double'), |
|
1158 (r"'", String, 'string-single'), |
|
1159 (r'"', String, 'string-double'), |
|
1160 (r'([\w-]+)', Name.Tag, 'node'), |
|
1161 (r'([^.#;{>\s]+)', Name.Class, 'node'), |
|
1162 (r'(#[\w-]+)', Name.Function, 'node'), |
|
1163 (r'(\.[\w-]+)', Name.Variable.Class, 'node') |
|
1164 ], |
|
1165 'string-base': [ |
|
1166 (r'\\.', String.Escape), |
|
1167 (r'~\[', String.Interpol, 'interpolation'), |
|
1168 (r'.', String.Single), |
|
1169 ], |
|
1170 'string-single': [ |
|
1171 (r"'", String.Single, '#pop'), |
|
1172 include('string-base') |
|
1173 ], |
|
1174 'string-double': [ |
|
1175 (r'"', String.Single, '#pop'), |
|
1176 include('string-base') |
|
1177 ], |
|
1178 'string-trpl-single': [ |
|
1179 (r"'''", String.Single, '#pop'), |
|
1180 include('string-base') |
|
1181 ], |
|
1182 'string-trpl-double': [ |
|
1183 (r'"""', String.Single, '#pop'), |
|
1184 include('string-base') |
|
1185 ], |
|
1186 'interpolation': [ |
|
1187 (r'\]', String.Interpol, '#pop'), |
|
1188 (r'\s*:', String.Interpol, 'expression'), |
|
1189 (r'\s*\w+:', Name.Other), |
|
1190 (r'[^\]]+', String.Interpol) |
|
1191 ], |
|
1192 'expression': [ |
|
1193 (r'[^\]]+', using(JavascriptLexer), '#pop') |
|
1194 ], |
|
1195 'node': [ |
|
1196 (r'\s+', Text), |
|
1197 (r'\.', Name.Variable.Class, 'node-class'), |
|
1198 (r'\#', Name.Function, 'node-id'), |
|
1199 (r'style[ \t]*=', Name.Attribute, 'node-attr-style-value'), |
|
1200 (r'[\w:-]+[ \t]*=', Name.Attribute, 'node-attr-value'), |
|
1201 (r'[\w:-]+', Name.Attribute), |
|
1202 (r'[>{;]', Punctuation, '#pop') |
|
1203 ], |
|
1204 'node-class': [ |
|
1205 (r'[\w-]+', Name.Variable.Class), |
|
1206 (r'~\[', String.Interpol, 'interpolation'), |
|
1207 default('#pop') |
|
1208 ], |
|
1209 'node-id': [ |
|
1210 (r'[\w-]+', Name.Function), |
|
1211 (r'~\[', String.Interpol, 'interpolation'), |
|
1212 default('#pop') |
|
1213 ], |
|
1214 'node-attr-value': [ |
|
1215 (r'\s+', Text), |
|
1216 (r'\w+', Name.Variable, '#pop'), |
|
1217 (r"'", String, 'string-single-pop2'), |
|
1218 (r'"', String, 'string-double-pop2'), |
|
1219 default('#pop') |
|
1220 ], |
|
1221 'node-attr-style-value': [ |
|
1222 (r'\s+', Text), |
|
1223 (r"'", String.Single, 'css-single-end'), |
|
1224 (r'"', String.Single, 'css-double-end'), |
|
1225 include('node-attr-value') |
|
1226 ], |
|
1227 'css-base': [ |
|
1228 (r'\s+', Text), |
|
1229 (r";", Punctuation), |
|
1230 (r"[\w\-]+\s*:", Name.Builtin) |
|
1231 ], |
|
1232 'css-single-end': [ |
|
1233 include('css-base'), |
|
1234 (r"'", String.Single, '#pop:2'), |
|
1235 (r"[^;']+", Name.Entity) |
|
1236 ], |
|
1237 'css-double-end': [ |
|
1238 include('css-base'), |
|
1239 (r'"', String.Single, '#pop:2'), |
|
1240 (r'[^;"]+', Name.Entity) |
|
1241 ], |
|
1242 'string-single-pop2': [ |
|
1243 (r"'", String.Single, '#pop:2'), |
|
1244 include('string-base') |
|
1245 ], |
|
1246 'string-double-pop2': [ |
|
1247 (r'"', String.Single, '#pop:2'), |
|
1248 include('string-base') |
|
1249 ], |
|
1250 } |
|
1251 |
|
1252 |
|
1253 class EarlGreyLexer(RegexLexer): |
|
1254 """ |
|
1255 For `Earl-Grey`_ source code. |
|
1256 |
|
1257 .. _Earl-Grey: https://breuleux.github.io/earl-grey/ |
|
1258 |
|
1259 .. versionadded: 2.1 |
|
1260 """ |
|
1261 |
|
1262 name = 'Earl Grey' |
|
1263 aliases = ['earl-grey', 'earlgrey', 'eg'] |
|
1264 filenames = ['*.eg'] |
|
1265 mimetypes = ['text/x-earl-grey'] |
|
1266 |
|
1267 tokens = { |
|
1268 'root': [ |
|
1269 (r'\n', Text), |
|
1270 include('control'), |
|
1271 (r'[^\S\n]+', Text), |
|
1272 (r';;.*\n', Comment), |
|
1273 (r'[\[\]{}:(),;]', Punctuation), |
|
1274 (r'\\\n', Text), |
|
1275 (r'\\', Text), |
|
1276 include('errors'), |
|
1277 (words(( |
|
1278 'with', 'where', 'when', 'and', 'not', 'or', 'in', |
|
1279 'as', 'of', 'is'), |
|
1280 prefix=r'(?<=\s|\[)', suffix=r'(?![\w$\-])'), |
|
1281 Operator.Word), |
|
1282 (r'[*@]?->', Name.Function), |
|
1283 (r'[+\-*/~^<>%&|?!@#.]*=', Operator.Word), |
|
1284 (r'\.{2,3}', Operator.Word), # Range Operator |
|
1285 (r'([+*/~^<>&|?!]+)|([#\-](?=\s))|@@+(?=\s)|=+', Operator), |
|
1286 (r'(?<![\w$\-])(var|let)(?:[^\w$])', Keyword.Declaration), |
|
1287 include('keywords'), |
|
1288 include('builtins'), |
|
1289 include('assignment'), |
|
1290 (r'''(?x) |
|
1291 (?:()([a-zA-Z$_](?:[\w$\-]*[\w$])?)| |
|
1292 (?<=[\s{\[(])(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?)) |
|
1293 (?=.*%)''', |
|
1294 bygroups(Punctuation, Name.Tag, Punctuation, Name.Class.Start), 'dbs'), |
|
1295 (r'[rR]?`', String.Backtick, 'bt'), |
|
1296 (r'[rR]?```', String.Backtick, 'tbt'), |
|
1297 (r'(?<=[\s\[{(,;])\.([a-zA-Z$_](?:[\w$\-]*[\w$])?)' |
|
1298 r'(?=[\s\]}),;])', String.Symbol), |
|
1299 include('nested'), |
|
1300 (r'(?:[rR]|[rR]\.[gmi]{1,3})?"', String, combined('stringescape', 'dqs')), |
|
1301 (r'(?:[rR]|[rR]\.[gmi]{1,3})?\'', String, combined('stringescape', 'sqs')), |
|
1302 (r'"""', String, combined('stringescape', 'tdqs')), |
|
1303 include('tuple'), |
|
1304 include('import_paths'), |
|
1305 include('name'), |
|
1306 include('numbers'), |
|
1307 ], |
|
1308 'dbs': [ |
|
1309 (r'(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?)(?=[.\[\s])', |
|
1310 bygroups(Punctuation, Name.Class.DBS)), |
|
1311 (r'(\[)([\^#][a-zA-Z$_](?:[\w$\-]*[\w$])?)(\])', |
|
1312 bygroups(Punctuation, Name.Entity.DBS, Punctuation)), |
|
1313 (r'\s+', Text), |
|
1314 (r'%', Operator.DBS, '#pop'), |
|
1315 ], |
|
1316 'import_paths': [ |
|
1317 (r'(?<=[\s:;,])(\.{1,3}(?:[\w\-]*/)*)(\w(?:[\w\-]*\w)*)(?=[\s;,])', |
|
1318 bygroups(Text.Whitespace, Text)), |
|
1319 ], |
|
1320 'assignment': [ |
|
1321 (r'(\.)?([a-zA-Z$_](?:[\w$\-]*[\w$])?)' |
|
1322 r'(?=\s+[+\-*/~^<>%&|?!@#.]*\=\s)', |
|
1323 bygroups(Punctuation, Name.Variable)) |
|
1324 ], |
|
1325 'errors': [ |
|
1326 (words(('Error', 'TypeError', 'ReferenceError'), |
|
1327 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'), |
|
1328 Name.Exception), |
|
1329 (r'''(?x) |
|
1330 (?<![\w$]) |
|
1331 E\.[\w$](?:[\w$\-]*[\w$])? |
|
1332 (?:\.[\w$](?:[\w$\-]*[\w$])?)* |
|
1333 (?=[({\[?!\s])''', |
|
1334 Name.Exception), |
|
1335 ], |
|
1336 'control': [ |
|
1337 (r'''(?x) |
|
1338 ([a-zA-Z$_](?:[\w$-]*[\w$])?) |
|
1339 (?!\n)\s+ |
|
1340 (?!and|as|each\*|each|in|is|mod|of|or|when|where|with) |
|
1341 (?=(?:[+\-*/~^<>%&|?!@#.])?[a-zA-Z$_](?:[\w$-]*[\w$])?)''', |
|
1342 Keyword.Control), |
|
1343 (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(?!\n)\s+(?=[\'"\d{\[(])', |
|
1344 Keyword.Control), |
|
1345 (r'''(?x) |
|
1346 (?: |
|
1347 (?<=[%=])| |
|
1348 (?<=[=\-]>)| |
|
1349 (?<=with|each|with)| |
|
1350 (?<=each\*|where) |
|
1351 )(\s+) |
|
1352 ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''', |
|
1353 bygroups(Text, Keyword.Control, Punctuation)), |
|
1354 (r'''(?x) |
|
1355 (?<![+\-*/~^<>%&|?!@#.])(\s+) |
|
1356 ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''', |
|
1357 bygroups(Text, Keyword.Control, Punctuation)), |
|
1358 ], |
|
1359 'nested': [ |
|
1360 (r'''(?x) |
|
1361 (?<=[\w$\]})])(\.) |
|
1362 ([a-zA-Z$_](?:[\w$-]*[\w$])?) |
|
1363 (?=\s+with(?:\s|\n))''', |
|
1364 bygroups(Punctuation, Name.Function)), |
|
1365 (r'''(?x) |
|
1366 (?<!\s)(\.) |
|
1367 ([a-zA-Z$_](?:[\w$-]*[\w$])?) |
|
1368 (?=[}\]).,;:\s])''', |
|
1369 bygroups(Punctuation, Name.Field)), |
|
1370 (r'''(?x) |
|
1371 (?<=[\w$\]})])(\.) |
|
1372 ([a-zA-Z$_](?:[\w$-]*[\w$])?) |
|
1373 (?=[\[{(:])''', |
|
1374 bygroups(Punctuation, Name.Function)), |
|
1375 ], |
|
1376 'keywords': [ |
|
1377 (words(( |
|
1378 'each', 'each*', 'mod', 'await', 'break', 'chain', |
|
1379 'continue', 'elif', 'expr-value', 'if', 'match', |
|
1380 'return', 'yield', 'pass', 'else', 'require', 'var', |
|
1381 'let', 'async', 'method', 'gen'), |
|
1382 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'), |
|
1383 Keyword.Pseudo), |
|
1384 (words(('this', 'self', '@'), |
|
1385 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'), |
|
1386 Keyword.Constant), |
|
1387 (words(( |
|
1388 'Function', 'Object', 'Array', 'String', 'Number', |
|
1389 'Boolean', 'ErrorFactory', 'ENode', 'Promise'), |
|
1390 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'), |
|
1391 Keyword.Type), |
|
1392 ], |
|
1393 'builtins': [ |
|
1394 (words(( |
|
1395 'send', 'object', 'keys', 'items', 'enumerate', 'zip', |
|
1396 'product', 'neighbours', 'predicate', 'equal', |
|
1397 'nequal', 'contains', 'repr', 'clone', 'range', |
|
1398 'getChecker', 'get-checker', 'getProperty', 'get-property', |
|
1399 'getProjector', 'get-projector', 'consume', 'take', |
|
1400 'promisify', 'spawn', 'constructor'), |
|
1401 prefix=r'(?<![\w\-#.])', suffix=r'(?![\w\-.])'), |
|
1402 Name.Builtin), |
|
1403 (words(( |
|
1404 'true', 'false', 'null', 'undefined'), |
|
1405 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'), |
|
1406 Name.Constant), |
|
1407 ], |
|
1408 'name': [ |
|
1409 (r'@([a-zA-Z$_](?:[\w$-]*[\w$])?)', Name.Variable.Instance), |
|
1410 (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(\+\+|\-\-)?', |
|
1411 bygroups(Name.Symbol, Operator.Word)) |
|
1412 ], |
|
1413 'tuple': [ |
|
1414 (r'#[a-zA-Z_][\w\-]*(?=[\s{(,;])', Name.Namespace) |
|
1415 ], |
|
1416 'interpoling_string': [ |
|
1417 (r'\}', String.Interpol, '#pop'), |
|
1418 include('root') |
|
1419 ], |
|
1420 'stringescape': [ |
|
1421 (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|' |
|
1422 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) |
|
1423 ], |
|
1424 'strings': [ |
|
1425 (r'[^\\\'"]', String), |
|
1426 (r'[\'"\\]', String), |
|
1427 (r'\n', String) # All strings are multiline in EG |
|
1428 ], |
|
1429 'dqs': [ |
|
1430 (r'"', String, '#pop'), |
|
1431 (r'\\\\|\\"|\\\n', String.Escape), |
|
1432 include('strings') |
|
1433 ], |
|
1434 'sqs': [ |
|
1435 (r"'", String, '#pop'), |
|
1436 (r"\\\\|\\'|\\\n", String.Escape), |
|
1437 (r'\{', String.Interpol, 'interpoling_string'), |
|
1438 include('strings') |
|
1439 ], |
|
1440 'tdqs': [ |
|
1441 (r'"""', String, '#pop'), |
|
1442 include('strings'), |
|
1443 ], |
|
1444 'bt': [ |
|
1445 (r'`', String.Backtick, '#pop'), |
|
1446 (r'(?<!`)\n', String.Backtick), |
|
1447 (r'\^=?', String.Escape), |
|
1448 (r'.+', String.Backtick), |
|
1449 ], |
|
1450 'tbt': [ |
|
1451 (r'```', String.Backtick, '#pop'), |
|
1452 (r'\n', String.Backtick), |
|
1453 (r'\^=?', String.Escape), |
|
1454 (r'[^`]+', String.Backtick), |
|
1455 ], |
|
1456 'numbers': [ |
|
1457 (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float), |
|
1458 (r'\d+[eE][+-]?[0-9]+', Number.Float), |
|
1459 (r'8r[0-7]+', Number.Oct), |
|
1460 (r'2r[01]+', Number.Bin), |
|
1461 (r'16r[a-fA-F0-9]+', Number.Hex), |
|
1462 (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?', Number.Radix), |
|
1463 (r'\d+', Number.Integer) |
|
1464 ], |
|
1465 } |
|
1466 |
|
1467 class JuttleLexer(RegexLexer): |
|
1468 """ |
|
1469 For `Juttle`_ source code. |
|
1470 |
|
1471 .. _Juttle: https://github.com/juttle/juttle |
|
1472 |
|
1473 """ |
|
1474 |
|
1475 name = 'Juttle' |
|
1476 aliases = ['juttle', 'juttle'] |
|
1477 filenames = ['*.juttle'] |
|
1478 mimetypes = ['application/juttle', 'application/x-juttle', |
|
1479 'text/x-juttle', 'text/juttle'] |
|
1480 |
|
1481 flags = re.DOTALL | re.UNICODE | re.MULTILINE |
|
1482 |
|
1483 tokens = { |
|
1484 'commentsandwhitespace': [ |
|
1485 (r'\s+', Text), |
|
1486 (r'//.*?\n', Comment.Single), |
|
1487 (r'/\*.*?\*/', Comment.Multiline) |
|
1488 ], |
|
1489 'slashstartsregex': [ |
|
1490 include('commentsandwhitespace'), |
|
1491 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' |
|
1492 r'([gim]+\b|\B)', String.Regex, '#pop'), |
|
1493 (r'(?=/)', Text, ('#pop', 'badregex')), |
|
1494 default('#pop') |
|
1495 ], |
|
1496 'badregex': [ |
|
1497 (r'\n', Text, '#pop') |
|
1498 ], |
|
1499 'root': [ |
|
1500 (r'^(?=\s|/)', Text, 'slashstartsregex'), |
|
1501 include('commentsandwhitespace'), |
|
1502 (r':\d{2}:\d{2}:\d{2}(\.\d*)?:', String.Moment), |
|
1503 (r':(now|beginning|end|forever|yesterday|today|tomorrow|' |
|
1504 r'(\d+(\.\d*)?|\.\d+)(ms|[smhdwMy])?):', String.Moment), |
|
1505 (r':\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d*)?)?' |
|
1506 r'(Z|[+-]\d{2}:\d{2}|[+-]\d{4})?:', String.Moment), |
|
1507 (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?' |
|
1508 r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|day|week|month|year)[s]?)' |
|
1509 r'|[ ]+(ago|from[ ]+now))*:', String.Moment), |
|
1510 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' |
|
1511 r'(==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), |
|
1512 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), |
|
1513 (r'[})\].]', Punctuation), |
|
1514 (r'(import|return|continue|if|else)\b', Keyword, 'slashstartsregex'), |
|
1515 (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration, 'slashstartsregex'), |
|
1516 (r'(batch|emit|filter|head|join|keep|pace|pass|put|read|reduce|remove|' |
|
1517 r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b', Keyword.Reserved), |
|
1518 (r'(true|false|null|Infinity)\b', Keyword.Constant), |
|
1519 (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b', Name.Builtin), |
|
1520 (JS_IDENT, Name.Other), |
|
1521 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), |
|
1522 (r'[0-9]+', Number.Integer), |
|
1523 (r'"(\\\\|\\"|[^"])*"', String.Double), |
|
1524 (r"'(\\\\|\\'|[^'])*'", String.Single) |
|
1525 ] |
|
1526 |
|
1527 } |