MCPcopy Create free account
hub / github.com/sql-js/sql.js / highlight

Function highlight

documentation/javascript/application.js:369–566  ·  view source on GitHub ↗
(language_name, value)

Source from the content-addressed store, hash-verified

367
368 */
369 function highlight(language_name, value) {
370 if (!compileModes.called) {
371 compileModes();
372 compileModes.called = true;
373 }
374
375 function subMode(lexem, mode) {
376 for (var i = 0; i < mode.contains.length; i++) {
377 if (mode.contains[i].beginRe.test(lexem)) {
378 return mode.contains[i];
379 }
380 }
381 }
382
383 function endOfMode(mode_index, lexem) {
384 if (modes[mode_index].end && modes[mode_index].endRe.test(lexem))
385 return 1;
386 if (modes[mode_index].endsWithParent) {
387 var level = endOfMode(mode_index - 1, lexem);
388 return level ? level + 1 : 0;
389 }
390 return 0;
391 }
392
393 function isIllegal(lexem, mode) {
394 return mode.illegal && mode.illegalRe.test(lexem);
395 }
396
397 function compileTerminators(mode, language) {
398 var terminators = [];
399
400 for (var i = 0; i < mode.contains.length; i++) {
401 terminators.push(mode.contains[i].begin);
402 }
403
404 var index = modes.length - 1;
405 do {
406 if (modes[index].end) {
407 terminators.push(modes[index].end);
408 }
409 index--;
410 } while (modes[index + 1].endsWithParent);
411
412 if (mode.illegal) {
413 terminators.push(mode.illegal);
414 }
415
416 return langRe(language, '(' + terminators.join('|') + ')', true);
417 }
418
419 function eatModeChunk(value, index) {
420 var mode = modes[modes.length - 1];
421 if (!mode.terminators) {
422 mode.terminators = compileTerminators(mode, language);
423 }
424 mode.terminators.lastIndex = index;
425 var match = mode.terminators.exec(value);
426 if (match)

Callers 3

processBufferFunction · 0.85
highlightAutoFunction · 0.85
highlightBlockFunction · 0.85

Calls 4

compileModesFunction · 0.85
eatModeChunkFunction · 0.85
processModeInfoFunction · 0.85
escapeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…