Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/javascript.py: 81%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

172 statements  

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 (words(( 

253 'in', 'of', 'while', 'until', 'break', 'return', 'continue', 

254 'when', 'if', 'unless', 'else', 'otherwise', 'throw', 'raise', 

255 'try', 'catch', 'finally', 'new', 'delete', 'typeof', 

256 'instanceof', 'super'), prefix=r'(?<![.$])', suffix=r'\b'), 

257 Keyword), 

258 (words(( 

259 'true', 'false', 'yes', 'no', 'on', 'off', 'null', 'nothing', 

260 'none', 'NaN', 'Infinity', 'undefined'), prefix=r'(?<![.$])', 

261 suffix=r'\b'), Keyword.Constant), 

262 (words(( 

263 'Array', 'Boolean', 'Date', 'Error', 'Function', 'Math', 

264 'Number', 'Object', 'RegExp', 'String', 'decodeURI', 

265 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'eval', 

266 'isFinite', 'isNaN', 'isSafeInteger', 'parseFloat', 'parseInt', 

267 'document', 'window', 'globalThis', 'Symbol', 'print'), 

268 suffix=r'\b'), Name.Builtin), 

269 (r'([$a-zA-Z_][\w.$]*)(\s*)(:|[+\-*/]?\=)?\b', 

270 bygroups(Name.Variable, Whitespace, Operator)), 

271 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

272 (r'0x[0-9a-fA-F]+', Number.Hex), 

273 (r'[0-9]+', Number.Integer), 

274 ('"""', String, 'tdqs'), 

275 ("'''", String, 'tsqs'), 

276 ('"', String, 'dqs'), 

277 ("'", String, 'sqs'), 

278 ], 

279 'strings': [ 

280 (r'[^#\\\'"]+', String), 

281 # note that all kal strings are multi-line. 

282 # hashmarks, quotes and backslashes must be parsed one at a time 

283 ], 

284 'interpoling_string': [ 

285 (r'\}', String.Interpol, "#pop"), 

286 include('root') 

287 ], 

288 'dqs': [ 

289 (r'"', String, '#pop'), 

290 (r'\\.|\'', String), # double-quoted string don't need ' escapes 

291 (r'#\{', String.Interpol, "interpoling_string"), 

292 include('strings') 

293 ], 

294 'sqs': [ 

295 (r"'", String, '#pop'), 

296 (r'#|\\.|"', String), # single quoted strings don't need " escapses 

297 include('strings') 

298 ], 

299 'tdqs': [ 

300 (r'"""', String, '#pop'), 

301 (r'\\.|\'|"', String), # no need to escape quotes in triple-string 

302 (r'#\{', String.Interpol, "interpoling_string"), 

303 include('strings'), 

304 ], 

305 'tsqs': [ 

306 (r"'''", String, '#pop'), 

307 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings 

308 include('strings') 

309 ], 

310 } 

311 

312 

313class LiveScriptLexer(RegexLexer): 

314 """ 

315 For LiveScript source code. 

316 """ 

317 

318 name = 'LiveScript' 

319 url = 'https://livescript.net/' 

320 aliases = ['livescript', 'live-script'] 

321 filenames = ['*.ls'] 

322 mimetypes = ['text/livescript'] 

323 version_added = '1.6' 

324 

325 flags = re.DOTALL 

326 tokens = { 

327 'commentsandwhitespace': [ 

328 (r'\s+', Whitespace), 

329 (r'/\*.*?\*/', Comment.Multiline), 

330 (r'(#.*?)(\n)', bygroups(Comment.Single, Whitespace)), 

331 ], 

332 'multilineregex': [ 

333 include('commentsandwhitespace'), 

334 (r'//([gimuysd]+\b|\B)', String.Regex, '#pop'), 

335 (r'/', String.Regex), 

336 (r'[^/#]+', String.Regex) 

337 ], 

338 'slashstartsregex': [ 

339 include('commentsandwhitespace'), 

340 (r'//', String.Regex, ('#pop', 'multilineregex')), 

341 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 

342 r'([gimuysd]+\b|\B)', String.Regex, '#pop'), 

343 (r'/', Operator, '#pop'), 

344 default('#pop'), 

345 ], 

346 'root': [ 

347 (r'\A(?=\s|/)', Text, 'slashstartsregex'), 

348 include('commentsandwhitespace'), 

349 (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' 

350 r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), 

351 (r'\+\+|&&|(?<![.$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' 

352 r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' 

353 r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|' 

354 r'[+*`%&|^/])=?', 

355 Operator, 'slashstartsregex'), 

356 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 

357 (r'[})\].]', Punctuation), 

358 (r'(?<![.$])(for|own|in|of|while|until|loop|break|' 

359 r'return|continue|switch|when|then|if|unless|else|' 

360 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' 

361 r'extends|this|class|by|const|var|to|til)\b', Keyword, 

362 'slashstartsregex'), 

363 (r'(?<![.$])(true|false|yes|no|on|off|' 

364 r'null|NaN|Infinity|undefined|void)\b', 

365 Keyword.Constant), 

366 (r'(Array|Boolean|Date|Error|Function|Math|' 

367 r'Number|Object|RegExp|String|decodeURI|' 

368 r'decodeURIComponent|encodeURI|encodeURIComponent|' 

369 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|' 

370 r'globalThis|Symbol|Symbol|BigInt)\b', Name.Builtin), 

371 (r'([$a-zA-Z_][\w.\-:$]*)(\s*)([:=])(\s+)', 

372 bygroups(Name.Variable, Whitespace, Operator, Whitespace), 

373 'slashstartsregex'), 

374 (r'(@[$a-zA-Z_][\w.\-:$]*)(\s*)([:=])(\s+)', 

375 bygroups(Name.Variable.Instance, Whitespace, Operator, 

376 Whitespace), 

377 'slashstartsregex'), 

378 (r'@', Name.Other, 'slashstartsregex'), 

379 (r'@?[$a-zA-Z_][\w-]*', Name.Other, 'slashstartsregex'), 

380 (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float), 

381 (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer), 

382 ('"""', String, 'tdqs'), 

383 ("'''", String, 'tsqs'), 

384 ('"', String, 'dqs'), 

385 ("'", String, 'sqs'), 

386 (r'\\\S+', String), 

387 (r'<\[.*?\]>', String), 

388 ], 

389 'strings': [ 

390 (r'[^#\\\'"]+', String), 

391 # note that all coffee script strings are multi-line. 

392 # hashmarks, quotes and backslashes must be parsed one at a time 

393 ], 

394 'interpoling_string': [ 

395 (r'\}', String.Interpol, "#pop"), 

396 include('root') 

397 ], 

398 'dqs': [ 

399 (r'"', String, '#pop'), 

400 (r'\\.|\'', String), # double-quoted string don't need ' escapes 

401 (r'#\{', String.Interpol, "interpoling_string"), 

402 (r'#', String), 

403 include('strings') 

404 ], 

405 'sqs': [ 

406 (r"'", String, '#pop'), 

407 (r'#|\\.|"', String), # single quoted strings don't need " escapses 

408 include('strings') 

409 ], 

410 'tdqs': [ 

411 (r'"""', String, '#pop'), 

412 (r'\\.|\'|"', String), # no need to escape quotes in triple-string 

413 (r'#\{', String.Interpol, "interpoling_string"), 

414 (r'#', String), 

415 include('strings'), 

416 ], 

417 'tsqs': [ 

418 (r"'''", String, '#pop'), 

419 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings 

420 include('strings') 

421 ], 

422 } 

423 

424 

425class DartLexer(RegexLexer): 

426 """ 

427 For Dart source code. 

428 """ 

429 

430 name = 'Dart' 

431 url = 'http://dart.dev/' 

432 aliases = ['dart'] 

433 filenames = ['*.dart'] 

434 mimetypes = ['text/x-dart'] 

435 version_added = '1.5' 

436 

437 flags = re.MULTILINE | re.DOTALL 

438 

439 tokens = { 

440 'root': [ 

441 include('string_literal'), 

442 (r'#!(.*?)$', Comment.Preproc), 

443 (r'\b(import|export)\b', Keyword, 'import_decl'), 

444 (r'\b(library|source|part of|part)\b', Keyword), 

445 (r'[^\S\n]+', Whitespace), 

446 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)), 

447 (r'/\*.*?\*/', Comment.Multiline), 

448 (r'\b(class|extension|mixin)\b(\s+)', 

449 bygroups(Keyword.Declaration, Whitespace), 'class'), 

450 (r'\b(as|assert|break|case|catch|const|continue|default|do|else|finally|' 

451 r'for|if|in|is|new|rethrow|return|super|switch|this|throw|try|while)\b', 

452 Keyword), 

453 (r'\b(abstract|async|await|const|covariant|extends|external|factory|final|' 

454 r'get|implements|late|native|on|operator|required|set|static|sync|typedef|' 

455 r'var|with|yield)\b', Keyword.Declaration), 

456 (r'\b(bool|double|dynamic|int|num|Function|Never|Null|Object|String|void)\b', 

457 Keyword.Type), 

458 (r'\b(false|null|true)\b', Keyword.Constant), 

459 (r'[~!%^&*+=|?:<>/-]|as\b', Operator), 

460 (r'@[a-zA-Z_$]\w*', Name.Decorator), 

461 (r'[a-zA-Z_$]\w*:', Name.Label), 

462 (r'[a-zA-Z_$]\w*', Name), 

463 (r'[(){}\[\],.;]', Punctuation), 

464 (r'0[xX][0-9a-fA-F]+', Number.Hex), 

465 # DIGIT+ (‘.’ DIGIT*)? EXPONENT? 

466 (r'\d+(\.\d*)?([eE][+-]?\d+)?', Number), 

467 (r'\.\d+([eE][+-]?\d+)?', Number), # ‘.’ DIGIT+ EXPONENT? 

468 (r'\n', Whitespace) 

469 # pseudo-keyword negate intentionally left out 

470 ], 

471 'class': [ 

472 (r'[a-zA-Z_$]\w*', Name.Class, '#pop') 

473 ], 

474 'import_decl': [ 

475 include('string_literal'), 

476 (r'\s+', Whitespace), 

477 (r'\b(as|deferred|show|hide)\b', Keyword), 

478 (r'[a-zA-Z_$]\w*', Name), 

479 (r'\,', Punctuation), 

480 (r'\;', Punctuation, '#pop') 

481 ], 

482 'string_literal': [ 

483 # Raw strings. 

484 (r'r"""([\w\W]*?)"""', String.Double), 

485 (r"r'''([\w\W]*?)'''", String.Single), 

486 (r'r"(.*?)"', String.Double), 

487 (r"r'(.*?)'", String.Single), 

488 # Normal Strings. 

489 (r'"""', String.Double, 'string_double_multiline'), 

490 (r"'''", String.Single, 'string_single_multiline'), 

491 (r'"', String.Double, 'string_double'), 

492 (r"'", String.Single, 'string_single') 

493 ], 

494 'string_common': [ 

495 (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z'\"$\\])", 

496 String.Escape), 

497 (r'(\$)([a-zA-Z_]\w*)', bygroups(String.Interpol, Name)), 

498 (r'(\$\{)(.*?)(\})', 

499 bygroups(String.Interpol, using(this), String.Interpol)) 

500 ], 

501 'string_double': [ 

502 (r'"', String.Double, '#pop'), 

503 (r'[^"$\\\n]+', String.Double), 

504 include('string_common'), 

505 (r'\$+', String.Double) 

506 ], 

507 'string_double_multiline': [ 

508 (r'"""', String.Double, '#pop'), 

509 (r'[^"$\\]+', String.Double), 

510 include('string_common'), 

511 (r'(\$|\")+', String.Double) 

512 ], 

513 'string_single': [ 

514 (r"'", String.Single, '#pop'), 

515 (r"[^'$\\\n]+", String.Single), 

516 include('string_common'), 

517 (r'\$+', String.Single) 

518 ], 

519 'string_single_multiline': [ 

520 (r"'''", String.Single, '#pop'), 

521 (r'[^\'$\\]+', String.Single), 

522 include('string_common'), 

523 (r'(\$|\')+', String.Single) 

524 ] 

525 } 

526 

527 

528class LassoLexer(RegexLexer): 

529 """ 

530 For Lasso source code, covering both Lasso 9 

531 syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in 

532 HTML, use the `LassoHtmlLexer`. 

533 

534 Additional options accepted: 

535 

536 `builtinshighlighting` 

537 If given and ``True``, highlight builtin types, traits, methods, and 

538 members (default: ``True``). 

539 `requiredelimiters` 

540 If given and ``True``, only highlight code between delimiters as Lasso 

541 (default: ``False``). 

542 """ 

543 

544 name = 'Lasso' 

545 aliases = ['lasso', 'lassoscript'] 

546 filenames = ['*.lasso', '*.lasso[89]'] 

547 version_added = '1.6' 

548 alias_filenames = ['*.incl', '*.inc', '*.las'] 

549 mimetypes = ['text/x-lasso'] 

550 url = 'https://www.lassosoft.com' 

551 

552 flags = re.IGNORECASE | re.DOTALL | re.MULTILINE 

553 

554 tokens = { 

555 'root': [ 

556 (r'^#![ \S]+lasso9\b', Comment.Preproc, 'lasso'), 

557 (r'(?=\[|<)', Other, 'delimiters'), 

558 (r'\s+', Whitespace), 

559 default(('delimiters', 'lassofile')), 

560 ], 

561 'delimiters': [ 

562 (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), 

563 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), 

564 (r'\[', Comment.Preproc, 'squarebrackets'), 

565 (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'), 

566 (r'<(!--.*?-->)?', Other), 

567 (r'[^[<]+', Other), 

568 ], 

569 'nosquarebrackets': [ 

570 (r'\[noprocess\]', Comment.Preproc, 'noprocess'), 

571 (r'\[', Other), 

572 (r'<\?(lasso(script)?|=)', Comment.Preproc, 'anglebrackets'), 

573 (r'<(!--.*?-->)?', Other), 

574 (r'[^[<]+', Other), 

575 ], 

576 'noprocess': [ 

577 (r'\[/noprocess\]', Comment.Preproc, '#pop'), 

578 (r'\[', Other), 

579 (r'[^[]', Other), 

580 ], 

581 'squarebrackets': [ 

582 (r'\]', Comment.Preproc, '#pop'), 

583 include('lasso'), 

584 ], 

585 'anglebrackets': [ 

586 (r'\?>', Comment.Preproc, '#pop'), 

587 include('lasso'), 

588 ], 

589 'lassofile': [ 

590 (r'\]|\?>', Comment.Preproc, '#pop'), 

591 include('lasso'), 

592 ], 

593 'whitespacecomments': [ 

594 (r'\s+', Whitespace), 

595 (r'(//.*?)(\s*)$', bygroups(Comment.Single, Whitespace)), 

596 (r'/\*\*!.*?\*/', String.Doc), 

597 (r'/\*.*?\*/', Comment.Multiline), 

598 ], 

599 'lasso': [ 

600 # whitespace/comments 

601 include('whitespacecomments'), 

602 

603 # literals 

604 (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), 

605 (r'0x[\da-f]+', Number.Hex), 

606 (r'\d+', Number.Integer), 

607 (r'(infinity|NaN)\b', Number), 

608 (r"'", String.Single, 'singlestring'), 

609 (r'"', String.Double, 'doublestring'), 

610 (r'`[^`]*`', String.Backtick), 

611 

612 # names 

613 (r'\$[a-z_][\w.]*', Name.Variable), 

614 (r'#([a-z_][\w.]*|\d+\b)', Name.Variable.Instance), 

615 (r"(\.)(\s*)('[a-z_][\w.]*')", 

616 bygroups(Name.Builtin.Pseudo, Whitespace, Name.Variable.Class)), 

617 (r"(self)(\s*)(->)(\s*)('[a-z_][\w.]*')", 

618 bygroups(Name.Builtin.Pseudo, Whitespace, Operator, Whitespace, 

619 Name.Variable.Class)), 

620 (r'(\.\.?)(\s*)([a-z_][\w.]*(=(?!=))?)', 

621 bygroups(Name.Builtin.Pseudo, Whitespace, Name.Other.Member)), 

622 (r'(->\\?|&)(\s*)([a-z_][\w.]*(=(?!=))?)', 

623 bygroups(Operator, Whitespace, Name.Other.Member)), 

624 (r'(?<!->)(self|inherited|currentcapture|givenblock)\b', 

625 Name.Builtin.Pseudo), 

626 (r'-(?!infinity)[a-z_][\w.]*', Name.Attribute), 

627 (r'(::)(\s*)([a-z_][\w.]*)', 

628 bygroups(Punctuation, Whitespace, Name.Label)), 

629 (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' 

630 r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' 

631 r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' 

632 r'Error_InvalidDatabase|Error_InvalidPassword|' 

633 r'Error_InvalidUsername|Error_ModuleNotFound|' 

634 r'Error_NoError|Error_NoPermission|Error_OutOfMemory|' 

635 r'Error_ReqColumnMissing|Error_ReqFieldMissing|' 

636 r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|' 

637 r'Error_UpdateError)\b', Name.Exception), 

638 

639 # definitions 

640 (r'(define)(\s+)([a-z_][\w.]*)(\s*)(=>)(\s*)(type|trait|thread)\b', 

641 bygroups(Keyword.Declaration, Whitespace, Name.Class, 

642 Whitespace, Operator, Whitespace, Keyword)), 

643 (r'(define)(\s+)([a-z_][\w.]*)(\s*)(->)(\s*)([a-z_][\w.]*=?|[-+*/%])', 

644 bygroups(Keyword.Declaration, Whitespace, Name.Class, 

645 Whitespace, Operator, Whitespace, Name.Function), 

646 'signature'), 

647 (r'(define)(\s+)([a-z_][\w.]*)', 

648 bygroups(Keyword.Declaration, Whitespace, Name.Function), 'signature'), 

649 (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|[-+*/%])' 

650 r'(?=\s*\())', bygroups(Keyword, Whitespace, Name.Function), 

651 'signature'), 

652 (r'(public|protected|private|provide)(\s+)([a-z_][\w.]*)', 

653 bygroups(Keyword, Whitespace, Name.Function)), 

654 

655 # keywords 

656 (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant), 

657 (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration), 

658 (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' 

659 r'null|boolean|bytes|keyword|list|locale|queue|set|stack|' 

660 r'staticarray)\b', Keyword.Type), 

661 (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Whitespace, Keyword)), 

662 (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Whitespace, Name)), 

663 (r'require\b', Keyword, 'requiresection'), 

664 (r'(/?)(Namespace_Using)\b', bygroups(Punctuation, Keyword.Namespace)), 

665 (r'(/?)(Cache|Database_Names|Database_SchemaNames|' 

666 r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' 

667 r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' 

668 r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' 

669 r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|Link_FirstRecord|' 

670 r'Link_LastGroup|Link_LastRecord|Link_NextGroup|Link_NextRecord|' 

671 r'Link_PrevGroup|Link_PrevRecord|Log|Loop|Output_None|Portal|' 

672 r'Private|Protect|Records|Referer|Referrer|Repeating|ResultSet|' 

673 r'Rows|Search_Args|Search_Arguments|Select|Sort_Args|' 

674 r'Sort_Arguments|Thread_Atomic|Value_List|While|Abort|Case|Else|' 

675 r'Fail_If|Fail_IfNot|Fail|If_Empty|If_False|If_Null|If_True|' 

676 r'Loop_Abort|Loop_Continue|Loop_Count|Params|Params_Up|Return|' 

677 r'Return_Value|Run_Children|SOAP_DefineTag|SOAP_LastRequest|' 

678 r'SOAP_LastResponse|Tag_Name|ascending|average|by|define|' 

679 r'descending|do|equals|frozen|group|handle_failure|import|in|into|' 

680 r'join|let|match|max|min|on|order|parent|protected|provide|public|' 

681 r'require|returnhome|skip|split_thread|sum|take|thread|to|trait|' 

682 r'type|where|with|yield|yieldhome)\b', 

683 bygroups(Punctuation, Keyword)), 

684 

685 # other 

686 (r',', Punctuation, 'commamember'), 

687 (r'(and|or|not)\b', Operator.Word), 

688 (r'([a-z_][\w.]*)(\s*)(::)(\s*)([a-z_][\w.]*)?(\s*=(?!=))', 

689 bygroups(Name, Whitespace, Punctuation, Whitespace, Name.Label, 

690 Operator)), 

691 (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), 

692 (r'(=)(n?bw|n?ew|n?cn|lte?|gte?|n?eq|n?rx|ft)\b', 

693 bygroups(Operator, Operator.Word)), 

694 (r':=|[-+*/%=<>&|!?\\]+', Operator), 

695 (r'[{}():;,@^]', Punctuation), 

696 ], 

697 'singlestring': [ 

698 (r"'", String.Single, '#pop'), 

699 (r"[^'\\]+", String.Single), 

700 include('escape'), 

701 (r"\\", String.Single), 

702 ], 

703 'doublestring': [ 

704 (r'"', String.Double, '#pop'), 

705 (r'[^"\\]+', String.Double), 

706 include('escape'), 

707 (r'\\', String.Double), 

708 ], 

709 'escape': [ 

710 (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:\n\r]+:|' 

711 r'[abefnrtv?"\'\\]|$)', String.Escape), 

712 ], 

713 'signature': [ 

714 (r'=>', Operator, '#pop'), 

715 (r'\)', Punctuation, '#pop'), 

716 (r'[(,]', Punctuation, 'parameter'), 

717 include('lasso'), 

718 ], 

719 'parameter': [ 

720 (r'\)', Punctuation, '#pop'), 

721 (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'), 

722 (r'\.\.\.', Name.Builtin.Pseudo), 

723 include('lasso'), 

724 ], 

725 'requiresection': [ 

726 (r'(([a-z_][\w.]*=?|[-+*/%])(?=\s*\())', Name, 'requiresignature'), 

727 (r'(([a-z_][\w.]*=?|[-+*/%])(?=(\s*::\s*[\w.]+)?\s*,))', Name), 

728 (r'[a-z_][\w.]*=?|[-+*/%]', Name, '#pop'), 

729 (r'(::)(\s*)([a-z_][\w.]*)', 

730 bygroups(Punctuation, Whitespace, Name.Label)), 

731 (r',', Punctuation), 

732 include('whitespacecomments'), 

733 ], 

734 'requiresignature': [ 

735 (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'), 

736 (r'\)', Punctuation, '#pop:2'), 

737 (r'-?[a-z_][\w.]*', Name.Attribute), 

738 (r'(::)(\s*)([a-z_][\w.]*)', 

739 bygroups(Punctuation, Whitespace, Name.Label)), 

740 (r'\.\.\.', Name.Builtin.Pseudo), 

741 (r'[(,]', Punctuation), 

742 include('whitespacecomments'), 

743 ], 

744 'commamember': [ 

745 (r'(([a-z_][\w.]*=?|[-+*/%])' 

746 r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))', 

747 Name.Function, 'signature'), 

748 include('whitespacecomments'), 

749 default('#pop'), 

750 ], 

751 } 

752 

753 def __init__(self, **options): 

754 self.builtinshighlighting = get_bool_opt( 

755 options, 'builtinshighlighting', True) 

756 self.requiredelimiters = get_bool_opt( 

757 options, 'requiredelimiters', False) 

758 

759 self._builtins = set() 

760 self._members = set() 

761 if self.builtinshighlighting: 

762 from pygments.lexers._lasso_builtins import BUILTINS, MEMBERS 

763 for key, value in BUILTINS.items(): 

764 self._builtins.update(value) 

765 for key, value in MEMBERS.items(): 

766 self._members.update(value) 

767 RegexLexer.__init__(self, **options) 

768 

769 def get_tokens_unprocessed(self, text): 

770 stack = ['root'] 

771 if self.requiredelimiters: 

772 stack.append('delimiters') 

773 for index, token, value in \ 

774 RegexLexer.get_tokens_unprocessed(self, text, stack): 

775 if (token is Name.Other and value.lower() in self._builtins or 

776 token is Name.Other.Member and 

777 value.lower().rstrip('=') in self._members): 

778 yield index, Name.Builtin, value 

779 continue 

780 yield index, token, value 

781 

782 def analyse_text(text): 

783 rv = 0.0 

784 if 'bin/lasso9' in text: 

785 rv += 0.8 

786 if re.search(r'<\?lasso', text, re.I): 

787 rv += 0.4 

788 if re.search(r'local\(', text, re.I): 

789 rv += 0.4 

790 return rv 

791 

792 

793class ObjectiveJLexer(RegexLexer): 

794 """ 

795 For Objective-J source code with preprocessor directives. 

796 """ 

797 

798 name = 'Objective-J' 

799 aliases = ['objective-j', 'objectivej', 'obj-j', 'objj'] 

800 filenames = ['*.j'] 

801 mimetypes = ['text/x-objective-j'] 

802 url = 'https://www.cappuccino.dev/learn/objective-j.html' 

803 version_added = '1.3' 

804 

805 #: optional Comment or Whitespace 

806 _ws = r'(?:\s|//[^\n]*\n|/[*](?:[^*]|[*][^/])*[*]/)*' 

807 

808 flags = re.DOTALL | re.MULTILINE 

809 

810 tokens = { 

811 'root': [ 

812 include('whitespace'), 

813 

814 # function definition 

815 (r'^(' + _ws + r'[+-]' + _ws + r')([(a-zA-Z_].*?[^(])(' + _ws + r'\{)', 

816 bygroups(using(this), using(this, state='function_signature'), 

817 using(this))), 

818 

819 # class definition 

820 (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Whitespace), 

821 'classname'), 

822 (r'(@class|@protocol)(\s*)', bygroups(Keyword, Whitespace), 

823 'forward_classname'), 

824 (r'(\s*)(@end)(\s*)', bygroups(Whitespace, Keyword, Whitespace)), 

825 

826 include('statements'), 

827 ('[{()}]', Punctuation), 

828 (';', Punctuation), 

829 ], 

830 'whitespace': [ 

831 (r'(@import)(\s+)("(?:\\\\|\\"|[^"])*")', 

832 bygroups(Comment.Preproc, Whitespace, String.Double)), 

833 (r'(@import)(\s+)(<(?:\\\\|\\>|[^>])*>)', 

834 bygroups(Comment.Preproc, Whitespace, String.Double)), 

835 (r'(#(?:include|import))(\s+)("(?:\\\\|\\"|[^"])*")', 

836 bygroups(Comment.Preproc, Whitespace, String.Double)), 

837 (r'(#(?:include|import))(\s+)(<(?:\\\\|\\>|[^>])*>)', 

838 bygroups(Comment.Preproc, Whitespace, String.Double)), 

839 

840 (r'#if\s+0', Comment.Preproc, 'if0'), 

841 (r'#', Comment.Preproc, 'macro'), 

842 

843 (r'\s+', Whitespace), 

844 (r'(\\)(\n)', 

845 bygroups(String.Escape, Whitespace)), # line continuation 

846 (r'//(\n|[\s\S]*?[^\\]\n)', Comment.Single), 

847 (r'/(\\\n)?[*][\s\S]*?[*](\\\n)?/', Comment.Multiline), 

848 (r'<!--', Comment), 

849 ], 

850 'slashstartsregex': [ 

851 include('whitespace'), 

852 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 

853 r'([gim]+\b|\B)', String.Regex, '#pop'), 

854 (r'(?=/)', Text, ('#pop', 'badregex')), 

855 default('#pop'), 

856 ], 

857 'badregex': [ 

858 (r'\n', Whitespace, '#pop'), 

859 ], 

860 'statements': [ 

861 (r'[L@]?"', String, 'string'), 

862 (r"[L@]?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", 

863 String.Char), 

864 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), 

865 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single), 

866 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), 

867 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), 

868 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), 

869 (r'0[0-7]+[Ll]?', Number.Oct), 

870 (r'\d+[Ll]?', Number.Integer), 

871 

872 (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), 

873 

874 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' 

875 r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', 

876 Operator, 'slashstartsregex'), 

877 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 

878 (r'[})\].]', Punctuation), 

879 

880 (r'(for|in|while|do|break|return|continue|switch|case|default|if|' 

881 r'else|throw|try|catch|finally|new|delete|typeof|instanceof|void|' 

882 r'prototype|__proto__)\b', Keyword, 'slashstartsregex'), 

883 

884 (r'(var|with|function)\b', Keyword.Declaration, 'slashstartsregex'), 

885 

886 (r'(@selector|@private|@protected|@public|@encode|' 

887 r'@synchronized|@try|@throw|@catch|@finally|@end|@property|' 

888 r'@synthesize|@dynamic|@for|@accessors|new)\b', Keyword), 

889 

890 (r'(int|long|float|short|double|char|unsigned|signed|void|' 

891 r'id|BOOL|bool|boolean|IBOutlet|IBAction|SEL|@outlet|@action)\b', 

892 Keyword.Type), 

893 

894 (r'(self|super)\b', Name.Builtin), 

895 

896 (r'(TRUE|YES|FALSE|NO|Nil|nil|NULL)\b', Keyword.Constant), 

897 (r'(true|false|null|NaN|Infinity|undefined)\b', Keyword.Constant), 

898 (r'(ABS|ASIN|ACOS|ATAN|ATAN2|SIN|COS|TAN|EXP|POW|CEIL|FLOOR|ROUND|' 

899 r'MIN|MAX|RAND|SQRT|E|LN2|LN10|LOG2E|LOG10E|PI|PI2|PI_2|SQRT1_2|' 

900 r'SQRT2)\b', Keyword.Constant), 

901 

902 (r'(Array|Boolean|Date|Error|Function|Math|' 

903 r'Number|Object|RegExp|String|decodeURI|' 

904 r'decodeURIComponent|encodeURI|encodeURIComponent|' 

905 r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' 

906 r'window|globalThis|Symbol)\b', Name.Builtin), 

907 

908 (r'([$a-zA-Z_]\w*)(' + _ws + r')(?=\()', 

909 bygroups(Name.Function, using(this))), 

910 

911 (r'[$a-zA-Z_]\w*', Name), 

912 ], 

913 'classname': [ 

914 # interface definition that inherits 

915 (r'([a-zA-Z_]\w*)(' + _ws + r':' + _ws + 

916 r')([a-zA-Z_]\w*)?', 

917 bygroups(Name.Class, using(this), Name.Class), '#pop'), 

918 # interface definition for a category 

919 (r'([a-zA-Z_]\w*)(' + _ws + r'\()([a-zA-Z_]\w*)(\))', 

920 bygroups(Name.Class, using(this), Name.Label, Text), '#pop'), 

921 # simple interface / implementation 

922 (r'([a-zA-Z_]\w*)', Name.Class, '#pop'), 

923 ], 

924 'forward_classname': [ 

925 (r'([a-zA-Z_]\w*)(\s*)(,)(\s*)', 

926 bygroups(Name.Class, Whitespace, Text, Whitespace), '#push'), 

927 (r'([a-zA-Z_]\w*)(\s*)(;?)', 

928 bygroups(Name.Class, Whitespace, Text), '#pop'), 

929 ], 

930 'function_signature': [ 

931 include('whitespace'), 

932 

933 # start of a selector w/ parameters 

934 (r'(\(' + _ws + r')' # open paren 

935 r'([a-zA-Z_]\w+)' # return type 

936 r'(' + _ws + r'\)' + _ws + r')' # close paren 

937 r'([$a-zA-Z_]\w+' + _ws + r':)', # function name 

938 bygroups(using(this), Keyword.Type, using(this), 

939 Name.Function), 'function_parameters'), 

940 

941 # no-param function 

942 (r'(\(' + _ws + r')' # open paren 

943 r'([a-zA-Z_]\w+)' # return type 

944 r'(' + _ws + r'\)' + _ws + r')' # close paren 

945 r'([$a-zA-Z_]\w+)', # function name 

946 bygroups(using(this), Keyword.Type, using(this), 

947 Name.Function), "#pop"), 

948 

949 # no return type given, start of a selector w/ parameters 

950 (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name 

951 bygroups(Name.Function), 'function_parameters'), 

952 

953 # no return type given, no-param function 

954 (r'([$a-zA-Z_]\w+)', # function name 

955 bygroups(Name.Function), "#pop"), 

956 

957 default('#pop'), 

958 ], 

959 'function_parameters': [ 

960 include('whitespace'), 

961 

962 # parameters 

963 (r'(\(' + _ws + ')' # open paren 

964 r'([^)]+)' # type 

965 r'(' + _ws + r'\)' + _ws + r')' # close paren 

966 r'([$a-zA-Z_]\w+)', # param name 

967 bygroups(using(this), Keyword.Type, using(this), Text)), 

968 

969 # one piece of a selector name 

970 (r'([$a-zA-Z_]\w+' + _ws + r':)', # function name 

971 Name.Function), 

972 

973 # smallest possible selector piece 

974 (r'(:)', Name.Function), 

975 

976 # var args 

977 (r'(,' + _ws + r'\.\.\.)', using(this)), 

978 

979 # param name 

980 (r'([$a-zA-Z_]\w+)', Text), 

981 ], 

982 'expression': [ 

983 (r'([$a-zA-Z_]\w*)(\()', bygroups(Name.Function, 

984 Punctuation)), 

985 (r'(\))', Punctuation, "#pop"), 

986 ], 

987 'string': [ 

988 (r'"', String, '#pop'), 

989 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), 

990 (r'[^\\"\n]+', String), # all other characters 

991 (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), # line continuation 

992 (r'\\', String), # stray backslash 

993 ], 

994 'macro': [ 

995 (r'[^/\n]+', Comment.Preproc), 

996 (r'/[*][\s\S]*?[*]/', Comment.Multiline), 

997 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace), '#pop'), 

998 (r'/', Comment.Preproc), 

999 (r'(?<=\\)\n', Whitespace), 

1000 (r'\n', Whitespace, '#pop'), 

1001 ], 

1002 'if0': [ 

1003 (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'), 

1004 (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'), 

1005 (r'(.*?)(\n)', bygroups(Comment, Whitespace)), 

1006 ] 

1007 } 

1008 

1009 def analyse_text(text): 

1010 if re.search(r'^\s*@import\s+[<"]', text, re.MULTILINE): 

1011 # special directive found in most Objective-J files 

1012 return True 

1013 return False 

1014 

1015 

1016class CoffeeScriptLexer(RegexLexer): 

1017 """ 

1018 For CoffeeScript source code. 

1019 """ 

1020 

1021 name = 'CoffeeScript' 

1022 url = 'http://coffeescript.org' 

1023 aliases = ['coffeescript', 'coffee-script', 'coffee'] 

1024 filenames = ['*.coffee'] 

1025 mimetypes = ['text/coffeescript'] 

1026 version_added = '1.3' 

1027 

1028 _operator_re = ( 

1029 r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' 

1030 r'\|\||\\(?=\n)|' 

1031 r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&|\^/])=?') 

1032 

1033 flags = re.DOTALL 

1034 tokens = { 

1035 'commentsandwhitespace': [ 

1036 (r'\s+', Whitespace), 

1037 (r'###[^#].*?###', Comment.Multiline), 

1038 (r'(#(?!##[^#]).*?)(\n)', bygroups(Comment.Single, Whitespace)), 

1039 ], 

1040 'multilineregex': [ 

1041 (r'[^/#]+', String.Regex), 

1042 (r'///([gimuysd]+\b|\B)', String.Regex, '#pop'), 

1043 (r'#\{', String.Interpol, 'interpoling_string'), 

1044 (r'[/#]', String.Regex), 

1045 ], 

1046 'slashstartsregex': [ 

1047 include('commentsandwhitespace'), 

1048 (r'///', String.Regex, ('#pop', 'multilineregex')), 

1049 (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 

1050 r'([gimuysd]+\b|\B)', String.Regex, '#pop'), 

1051 # This isn't really guarding against mishighlighting well-formed 

1052 # code, just the ability to infinite-loop between root and 

1053 # slashstartsregex. 

1054 (r'/', Operator, '#pop'), 

1055 default('#pop'), 

1056 ], 

1057 'root': [ 

1058 include('commentsandwhitespace'), 

1059 (r'\A(?=\s|/)', Text, 'slashstartsregex'), 

1060 (_operator_re, Operator, 'slashstartsregex'), 

1061 (r'(?:\([^()]*\))?\s*[=-]>', Name.Function, 'slashstartsregex'), 

1062 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 

1063 (r'[})\].]', Punctuation), 

1064 (r'(?<![.$])(for|own|in|of|while|until|' 

1065 r'loop|break|return|continue|' 

1066 r'switch|when|then|if|unless|else|' 

1067 r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' 

1068 r'extends|this|class|by)\b', Keyword, 'slashstartsregex'), 

1069 (r'(?<![.$])(true|false|yes|no|on|off|null|' 

1070 r'NaN|Infinity|undefined)\b', 

1071 Keyword.Constant), 

1072 (r'(Array|Boolean|Date|Error|Function|Math|' 

1073 r'Number|Object|RegExp|String|decodeURI|' 

1074 r'decodeURIComponent|encodeURI|encodeURIComponent|' 

1075 r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|globalThis|Symbol)\b', 

1076 Name.Builtin), 

1077 (r'([$a-zA-Z_][\w.:$]*)(\s*)([:=])(\s+)', 

1078 bygroups(Name.Variable, Whitespace, Operator, Whitespace), 

1079 'slashstartsregex'), 

1080 (r'(@[$a-zA-Z_][\w.:$]*)(\s*)([:=])(\s+)', 

1081 bygroups(Name.Variable.Instance, Whitespace, Operator, Whitespace), 

1082 'slashstartsregex'), 

1083 (r'@', Name.Other, 'slashstartsregex'), 

1084 (r'@?[$a-zA-Z_][\w$]*', Name.Other), 

1085 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

1086 (r'0x[0-9a-fA-F]+', Number.Hex), 

1087 (r'[0-9]+', Number.Integer), 

1088 ('"""', String, 'tdqs'), 

1089 ("'''", String, 'tsqs'), 

1090 ('"', String, 'dqs'), 

1091 ("'", String, 'sqs'), 

1092 ], 

1093 'strings': [ 

1094 (r'[^#\\\'"]+', String), 

1095 # note that all coffee script strings are multi-line. 

1096 # hashmarks, quotes and backslashes must be parsed one at a time 

1097 ], 

1098 'interpoling_string': [ 

1099 (r'\}', String.Interpol, "#pop"), 

1100 include('root') 

1101 ], 

1102 'dqs': [ 

1103 (r'"', String, '#pop'), 

1104 (r'\\.|\'', String), # double-quoted string don't need ' escapes 

1105 (r'#\{', String.Interpol, "interpoling_string"), 

1106 (r'#', String), 

1107 include('strings') 

1108 ], 

1109 'sqs': [ 

1110 (r"'", String, '#pop'), 

1111 (r'#|\\.|"', String), # single quoted strings don't need " escapses 

1112 include('strings') 

1113 ], 

1114 'tdqs': [ 

1115 (r'"""', String, '#pop'), 

1116 (r'\\.|\'|"', String), # no need to escape quotes in triple-string 

1117 (r'#\{', String.Interpol, "interpoling_string"), 

1118 (r'#', String), 

1119 include('strings'), 

1120 ], 

1121 'tsqs': [ 

1122 (r"'''", String, '#pop'), 

1123 (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings 

1124 include('strings') 

1125 ], 

1126 } 

1127 

1128 

1129class MaskLexer(RegexLexer): 

1130 """ 

1131 For Mask markup. 

1132 """ 

1133 name = 'Mask' 

1134 url = 'https://github.com/atmajs/MaskJS' 

1135 aliases = ['mask'] 

1136 filenames = ['*.mask'] 

1137 mimetypes = ['text/x-mask'] 

1138 version_added = '2.0' 

1139 

1140 flags = re.MULTILINE | re.IGNORECASE | re.DOTALL 

1141 tokens = { 

1142 'root': [ 

1143 (r'\s+', Whitespace), 

1144 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)), 

1145 (r'/\*.*?\*/', Comment.Multiline), 

1146 (r'[{};>]', Punctuation), 

1147 (r"'''", String, 'string-trpl-single'), 

1148 (r'"""', String, 'string-trpl-double'), 

1149 (r"'", String, 'string-single'), 

1150 (r'"', String, 'string-double'), 

1151 (r'([\w-]+)', Name.Tag, 'node'), 

1152 (r'([^.#;{>\s]+)', Name.Class, 'node'), 

1153 (r'(#[\w-]+)', Name.Function, 'node'), 

1154 (r'(\.[\w-]+)', Name.Variable.Class, 'node') 

1155 ], 

1156 'string-base': [ 

1157 (r'\\.', String.Escape), 

1158 (r'~\[', String.Interpol, 'interpolation'), 

1159 (r'.', String.Single), 

1160 ], 

1161 'string-single': [ 

1162 (r"'", String.Single, '#pop'), 

1163 include('string-base') 

1164 ], 

1165 'string-double': [ 

1166 (r'"', String.Single, '#pop'), 

1167 include('string-base') 

1168 ], 

1169 'string-trpl-single': [ 

1170 (r"'''", String.Single, '#pop'), 

1171 include('string-base') 

1172 ], 

1173 'string-trpl-double': [ 

1174 (r'"""', String.Single, '#pop'), 

1175 include('string-base') 

1176 ], 

1177 'interpolation': [ 

1178 (r'\]', String.Interpol, '#pop'), 

1179 (r'(\s*)(:)', bygroups(Whitespace, String.Interpol), 'expression'), 

1180 (r'(\s*)(\w+)(:)', bygroups(Whitespace, Name.Other, Punctuation)), 

1181 (r'[^\]]+', String.Interpol) 

1182 ], 

1183 'expression': [ 

1184 (r'[^\]]+', using(JavascriptLexer), '#pop') 

1185 ], 

1186 'node': [ 

1187 (r'\s+', Whitespace), 

1188 (r'\.', Name.Variable.Class, 'node-class'), 

1189 (r'\#', Name.Function, 'node-id'), 

1190 (r'(style)([ \t]*)(=)', 

1191 bygroups(Name.Attribute, Whitespace, Operator), 

1192 'node-attr-style-value'), 

1193 (r'([\w:-]+)([ \t]*)(=)', 

1194 bygroups(Name.Attribute, Whitespace, Operator), 

1195 'node-attr-value'), 

1196 (r'[\w:-]+', Name.Attribute), 

1197 (r'[>{;]', Punctuation, '#pop') 

1198 ], 

1199 'node-class': [ 

1200 (r'[\w-]+', Name.Variable.Class), 

1201 (r'~\[', String.Interpol, 'interpolation'), 

1202 default('#pop') 

1203 ], 

1204 'node-id': [ 

1205 (r'[\w-]+', Name.Function), 

1206 (r'~\[', String.Interpol, 'interpolation'), 

1207 default('#pop') 

1208 ], 

1209 'node-attr-value': [ 

1210 (r'\s+', Whitespace), 

1211 (r'\w+', Name.Variable, '#pop'), 

1212 (r"'", String, 'string-single-pop2'), 

1213 (r'"', String, 'string-double-pop2'), 

1214 default('#pop') 

1215 ], 

1216 'node-attr-style-value': [ 

1217 (r'\s+', Whitespace), 

1218 (r"'", String.Single, 'css-single-end'), 

1219 (r'"', String.Single, 'css-double-end'), 

1220 include('node-attr-value') 

1221 ], 

1222 'css-base': [ 

1223 (r'\s+', Whitespace), 

1224 (r";", Punctuation), 

1225 (r"[\w\-]+\s*:", Name.Builtin) 

1226 ], 

1227 'css-single-end': [ 

1228 include('css-base'), 

1229 (r"'", String.Single, '#pop:2'), 

1230 (r"[^;']+", Name.Entity) 

1231 ], 

1232 'css-double-end': [ 

1233 include('css-base'), 

1234 (r'"', String.Single, '#pop:2'), 

1235 (r'[^;"]+', Name.Entity) 

1236 ], 

1237 'string-single-pop2': [ 

1238 (r"'", String.Single, '#pop:2'), 

1239 include('string-base') 

1240 ], 

1241 'string-double-pop2': [ 

1242 (r'"', String.Single, '#pop:2'), 

1243 include('string-base') 

1244 ], 

1245 } 

1246 

1247 

1248class EarlGreyLexer(RegexLexer): 

1249 """ 

1250 For Earl-Grey source code. 

1251 

1252 .. versionadded: 2.1 

1253 """ 

1254 

1255 name = 'Earl Grey' 

1256 aliases = ['earl-grey', 'earlgrey', 'eg'] 

1257 filenames = ['*.eg'] 

1258 mimetypes = ['text/x-earl-grey'] 

1259 url = 'https://github.com/breuleux/earl-grey' 

1260 version_added = '' 

1261 

1262 tokens = { 

1263 'root': [ 

1264 (r'\n', Whitespace), 

1265 include('control'), 

1266 (r'[^\S\n]+', Text), 

1267 (r'(;;.*)(\n)', bygroups(Comment, Whitespace)), 

1268 (r'[\[\]{}:(),;]', Punctuation), 

1269 (r'(\\)(\n)', bygroups(String.Escape, Whitespace)), 

1270 (r'\\', Text), 

1271 include('errors'), 

1272 (words(( 

1273 'with', 'where', 'when', 'and', 'not', 'or', 'in', 

1274 'as', 'of', 'is'), 

1275 prefix=r'(?<=\s|\[)', suffix=r'(?![\w$\-])'), 

1276 Operator.Word), 

1277 (r'[*@]?->', Name.Function), 

1278 (r'[+\-*/~^<>%&|?!@#.]*=', Operator.Word), 

1279 (r'\.{2,3}', Operator.Word), # Range Operator 

1280 (r'([+*/~^<>&|?!]+)|([#\-](?=\s))|@@+(?=\s)|=+', Operator), 

1281 (r'(?<![\w$\-])(var|let)(?:[^\w$])', Keyword.Declaration), 

1282 include('keywords'), 

1283 include('builtins'), 

1284 include('assignment'), 

1285 (r'''(?x) 

1286 (?:()([a-zA-Z$_](?:[\w$\-]*[\w$])?)| 

1287 (?<=[\s{\[(])(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?)) 

1288 (?=.*%)''', 

1289 bygroups(Punctuation, Name.Tag, Punctuation, Name.Class.Start), 'dbs'), 

1290 (r'[rR]?`', String.Backtick, 'bt'), 

1291 (r'[rR]?```', String.Backtick, 'tbt'), 

1292 (r'(?<=[\s\[{(,;])\.([a-zA-Z$_](?:[\w$\-]*[\w$])?)' 

1293 r'(?=[\s\]}),;])', String.Symbol), 

1294 include('nested'), 

1295 (r'(?:[rR]|[rR]\.[gmi]{1,3})?"', String, combined('stringescape', 'dqs')), 

1296 (r'(?:[rR]|[rR]\.[gmi]{1,3})?\'', String, combined('stringescape', 'sqs')), 

1297 (r'"""', String, combined('stringescape', 'tdqs')), 

1298 include('tuple'), 

1299 include('import_paths'), 

1300 include('name'), 

1301 include('numbers'), 

1302 ], 

1303 'dbs': [ 

1304 (r'(\.)([a-zA-Z$_](?:[\w$\-]*[\w$])?)(?=[.\[\s])', 

1305 bygroups(Punctuation, Name.Class.DBS)), 

1306 (r'(\[)([\^#][a-zA-Z$_](?:[\w$\-]*[\w$])?)(\])', 

1307 bygroups(Punctuation, Name.Entity.DBS, Punctuation)), 

1308 (r'\s+', Whitespace), 

1309 (r'%', Operator.DBS, '#pop'), 

1310 ], 

1311 'import_paths': [ 

1312 (r'(?<=[\s:;,])(\.{1,3}(?:[\w\-]*/)*)(\w(?:[\w\-]*\w)*)(?=[\s;,])', 

1313 bygroups(Text.Whitespace, Text)), 

1314 ], 

1315 'assignment': [ 

1316 (r'(\.)?([a-zA-Z$_](?:[\w$\-]*[\w$])?)' 

1317 r'(?=\s+[+\-*/~^<>%&|?!@#.]*\=\s)', 

1318 bygroups(Punctuation, Name.Variable)) 

1319 ], 

1320 'errors': [ 

1321 (words(('Error', 'TypeError', 'ReferenceError'), 

1322 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'), 

1323 Name.Exception), 

1324 (r'''(?x) 

1325 (?<![\w$]) 

1326 E\.[\w$](?:[\w$\-]*[\w$])? 

1327 (?:\.[\w$](?:[\w$\-]*[\w$])?)* 

1328 (?=[({\[?!\s])''', 

1329 Name.Exception), 

1330 ], 

1331 'control': [ 

1332 (r'''(?x) 

1333 ([a-zA-Z$_](?:[\w$-]*[\w$])?) 

1334 (?!\n)\s+ 

1335 (?!and|as|each\*|each|in|is|mod|of|or|when|where|with) 

1336 (?=(?:[+\-*/~^<>%&|?!@#.])?[a-zA-Z$_](?:[\w$-]*[\w$])?)''', 

1337 Keyword.Control), 

1338 (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(?!\n)(\s+)(?=[\'"\d{\[(])', 

1339 bygroups(Keyword.Control, Whitespace)), 

1340 (r'''(?x) 

1341 (?: 

1342 (?<=[%=])| 

1343 (?<=[=\-]>)| 

1344 (?<=with|each|with)| 

1345 (?<=each\*|where) 

1346 )(\s+) 

1347 ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''', 

1348 bygroups(Whitespace, Keyword.Control, Punctuation)), 

1349 (r'''(?x) 

1350 (?<![+\-*/~^<>%&|?!@#.])(\s+) 

1351 ([a-zA-Z$_](?:[\w$-]*[\w$])?)(:)''', 

1352 bygroups(Whitespace, Keyword.Control, Punctuation)), 

1353 ], 

1354 'nested': [ 

1355 (r'''(?x) 

1356 (?<=[\w$\]})])(\.) 

1357 ([a-zA-Z$_](?:[\w$-]*[\w$])?) 

1358 (?=\s+with(?:\s|\n))''', 

1359 bygroups(Punctuation, Name.Function)), 

1360 (r'''(?x) 

1361 (?<!\s)(\.) 

1362 ([a-zA-Z$_](?:[\w$-]*[\w$])?) 

1363 (?=[}\]).,;:\s])''', 

1364 bygroups(Punctuation, Name.Field)), 

1365 (r'''(?x) 

1366 (?<=[\w$\]})])(\.) 

1367 ([a-zA-Z$_](?:[\w$-]*[\w$])?) 

1368 (?=[\[{(:])''', 

1369 bygroups(Punctuation, Name.Function)), 

1370 ], 

1371 'keywords': [ 

1372 (words(( 

1373 'each', 'each*', 'mod', 'await', 'break', 'chain', 

1374 'continue', 'elif', 'expr-value', 'if', 'match', 

1375 'return', 'yield', 'pass', 'else', 'require', 'var', 

1376 'let', 'async', 'method', 'gen'), 

1377 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'), 

1378 Keyword.Pseudo), 

1379 (words(('this', 'self', '@'), 

1380 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'), 

1381 Keyword.Constant), 

1382 (words(( 

1383 'Function', 'Object', 'Array', 'String', 'Number', 

1384 'Boolean', 'ErrorFactory', 'ENode', 'Promise'), 

1385 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$])'), 

1386 Keyword.Type), 

1387 ], 

1388 'builtins': [ 

1389 (words(( 

1390 'send', 'object', 'keys', 'items', 'enumerate', 'zip', 

1391 'product', 'neighbours', 'predicate', 'equal', 

1392 'nequal', 'contains', 'repr', 'clone', 'range', 

1393 'getChecker', 'get-checker', 'getProperty', 'get-property', 

1394 'getProjector', 'get-projector', 'consume', 'take', 

1395 'promisify', 'spawn', 'constructor'), 

1396 prefix=r'(?<![\w\-#.])', suffix=r'(?![\w\-.])'), 

1397 Name.Builtin), 

1398 (words(( 

1399 'true', 'false', 'null', 'undefined'), 

1400 prefix=r'(?<![\w\-$.])', suffix=r'(?![\w\-$.])'), 

1401 Name.Constant), 

1402 ], 

1403 'name': [ 

1404 (r'@([a-zA-Z$_](?:[\w$-]*[\w$])?)', Name.Variable.Instance), 

1405 (r'([a-zA-Z$_](?:[\w$-]*[\w$])?)(\+\+|\-\-)?', 

1406 bygroups(Name.Symbol, Operator.Word)) 

1407 ], 

1408 'tuple': [ 

1409 (r'#[a-zA-Z_][\w\-]*(?=[\s{(,;])', Name.Namespace) 

1410 ], 

1411 'interpoling_string': [ 

1412 (r'\}', String.Interpol, '#pop'), 

1413 include('root') 

1414 ], 

1415 'stringescape': [ 

1416 (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|' 

1417 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) 

1418 ], 

1419 'strings': [ 

1420 (r'[^\\\'"]', String), 

1421 (r'[\'"\\]', String), 

1422 (r'\n', String) # All strings are multiline in EG 

1423 ], 

1424 'dqs': [ 

1425 (r'"', String, '#pop'), 

1426 (r'\\\\|\\"|\\\n', String.Escape), 

1427 include('strings') 

1428 ], 

1429 'sqs': [ 

1430 (r"'", String, '#pop'), 

1431 (r"\\\\|\\'|\\\n", String.Escape), 

1432 (r'\{', String.Interpol, 'interpoling_string'), 

1433 include('strings') 

1434 ], 

1435 'tdqs': [ 

1436 (r'"""', String, '#pop'), 

1437 include('strings'), 

1438 ], 

1439 'bt': [ 

1440 (r'`', String.Backtick, '#pop'), 

1441 (r'(?<!`)\n', String.Backtick), 

1442 (r'\^=?', String.Escape), 

1443 (r'.+', String.Backtick), 

1444 ], 

1445 'tbt': [ 

1446 (r'```', String.Backtick, '#pop'), 

1447 (r'\n', String.Backtick), 

1448 (r'\^=?', String.Escape), 

1449 (r'[^`]+', String.Backtick), 

1450 ], 

1451 'numbers': [ 

1452 (r'\d+\.(?!\.)\d*([eE][+-]?[0-9]+)?', Number.Float), 

1453 (r'\d+[eE][+-]?[0-9]+', Number.Float), 

1454 (r'8r[0-7]+', Number.Oct), 

1455 (r'2r[01]+', Number.Bin), 

1456 (r'16r[a-fA-F0-9]+', Number.Hex), 

1457 (r'([3-79]|[12][0-9]|3[0-6])r[a-zA-Z\d]+(\.[a-zA-Z\d]+)?', 

1458 Number.Radix), 

1459 (r'\d+', Number.Integer) 

1460 ], 

1461 } 

1462 

1463 

1464class JuttleLexer(RegexLexer): 

1465 """ 

1466 For Juttle source code. 

1467 """ 

1468 

1469 name = 'Juttle' 

1470 url = 'http://juttle.github.io/' 

1471 aliases = ['juttle'] 

1472 filenames = ['*.juttle'] 

1473 mimetypes = ['application/juttle', 'application/x-juttle', 

1474 'text/x-juttle', 'text/juttle'] 

1475 version_added = '2.2' 

1476 

1477 flags = re.DOTALL | re.MULTILINE 

1478 

1479 tokens = { 

1480 'commentsandwhitespace': [ 

1481 (r'\s+', Whitespace), 

1482 (r'(//.*?)(\n)', bygroups(Comment.Single, Whitespace)), 

1483 (r'/\*.*?\*/', Comment.Multiline) 

1484 ], 

1485 'slashstartsregex': [ 

1486 include('commentsandwhitespace'), 

1487 (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' 

1488 r'([gimuysd]+\b|\B)', String.Regex, '#pop'), 

1489 (r'(?=/)', Text, ('#pop', 'badregex')), 

1490 default('#pop') 

1491 ], 

1492 'badregex': [ 

1493 (r'\n', Text, '#pop') 

1494 ], 

1495 'root': [ 

1496 (r'^(?=\s|/)', Text, 'slashstartsregex'), 

1497 include('commentsandwhitespace'), 

1498 (r':\d{2}:\d{2}:\d{2}(\.\d*)?:', String.Moment), 

1499 (r':(now|beginning|end|forever|yesterday|today|tomorrow|' 

1500 r'(\d+(\.\d*)?|\.\d+)(ms|[smhdwMy])?):', String.Moment), 

1501 (r':\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d*)?)?' 

1502 r'(Z|[+-]\d{2}:\d{2}|[+-]\d{4})?:', String.Moment), 

1503 (r':((\d+(\.\d*)?|\.\d+)[ ]+)?(millisecond|second|minute|hour|' 

1504 r'day|week|month|year)[s]?' 

1505 r'(([ ]+and[ ]+(\d+[ ]+)?(millisecond|second|minute|hour|' 

1506 r'day|week|month|year)[s]?)' 

1507 r'|[ ]+(ago|from[ ]+now))*:', String.Moment), 

1508 (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' 

1509 r'(==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'), 

1510 (r'[{(\[;,]', Punctuation, 'slashstartsregex'), 

1511 (r'[})\].]', Punctuation), 

1512 (r'(import|return|continue|if|else)\b', Keyword, 'slashstartsregex'), 

1513 (r'(var|const|function|reducer|sub|input)\b', Keyword.Declaration, 

1514 'slashstartsregex'), 

1515 (r'(batch|emit|filter|head|join|keep|pace|pass|put|read|reduce|remove|' 

1516 r'sequence|skip|sort|split|tail|unbatch|uniq|view|write)\b', 

1517 Keyword.Reserved), 

1518 (r'(true|false|null|Infinity)\b', Keyword.Constant), 

1519 (r'(Array|Date|Juttle|Math|Number|Object|RegExp|String)\b', 

1520 Name.Builtin), 

1521 (JS_IDENT, Name.Other), 

1522 (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 

1523 (r'[0-9]+', Number.Integer), 

1524 (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double), 

1525 (r"'(\\\\|\\[^\\]|[^'\\])*'", String.Single), 

1526 ] 

1527 

1528 } 

1529 

1530 

1531class NodeConsoleLexer(Lexer): 

1532 """ 

1533 For parsing within an interactive Node.js REPL, such as: 

1534 

1535 .. sourcecode:: nodejsrepl 

1536 

1537 > let a = 3 

1538 undefined 

1539 > a 

1540 3 

1541 > let b = '4' 

1542 undefined 

1543 > b 

1544 '4' 

1545 > b == a 

1546 false 

1547 

1548 .. versionadded: 2.10 

1549 """ 

1550 name = 'Node.js REPL console session' 

1551 aliases = ['nodejsrepl', ] 

1552 mimetypes = ['text/x-nodejsrepl', ] 

1553 url = 'https://nodejs.org' 

1554 version_added = '' 

1555 

1556 def get_tokens_unprocessed(self, text): 

1557 jslexer = JavascriptLexer(**self.options) 

1558 

1559 curcode = '' 

1560 insertions = [] 

1561 

1562 for match in line_re.finditer(text): 

1563 line = match.group() 

1564 if line.startswith('> '): 

1565 insertions.append((len(curcode), 

1566 [(0, Generic.Prompt, line[:1]), 

1567 (1, Whitespace, line[1:2])])) 

1568 

1569 curcode += line[2:] 

1570 elif line.startswith('...'): 

1571 # node does a nested ... thing depending on depth 

1572 code = line.lstrip('.') 

1573 lead = len(line) - len(code) 

1574 

1575 insertions.append((len(curcode), 

1576 [(0, Generic.Prompt, line[:lead])])) 

1577 

1578 curcode += code 

1579 else: 

1580 if curcode: 

1581 yield from do_insertions(insertions, 

1582 jslexer.get_tokens_unprocessed(curcode)) 

1583 

1584 curcode = '' 

1585 insertions = [] 

1586 

1587 yield from do_insertions([], 

1588 jslexer.get_tokens_unprocessed(line)) 

1589 

1590 if curcode: 

1591 yield from do_insertions(insertions, 

1592 jslexer.get_tokens_unprocessed(curcode))