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