eric6/ThirdParty/Pygments/pygments/lexers/javascript.py

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

eric ide

mercurial