MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / openBlocks

Function openBlocks

src/extraction/languages/pascal-preparse.ts:667–692  ·  view source on GitHub ↗

* The blocks the code from `from` to `to` leaves open, in order, each as its * opener's offset and kind (OPEN_BEGIN, OPEN_ASM, or OPEN_OTHER for `try`, * `case` and `record`), or null when it closes a block it didn't open. A * word starting in one of the `[from, to)` spans in `blanked` doesn't co

(s: string, from: number, to: number, blanked: readonly number[] = [])

Source from the content-addressed store, hash-verified

665 * word starting in one of the `[from, to)` spans in `blanked` doesn't count.
666 */
667function openBlocks(s: string, from: number, to: number, blanked: readonly number[] = []): Array<[number, number]> | null {
668 const open: Array<[number, number]> = [];
669 let i = from;
670 while (i < to) {
671 const k = commentOrStringEnd(s, i);
672 if (k >= 0) {
673 i = k;
674 continue;
675 }
676 if (isIdentStart(s.charCodeAt(i))) {
677 const e = wordEnd(s, i + 1);
678 if (e - i >= 3 && e - i <= 6 && !(blanked.length > 0 && overlapsRange(blanked, i, i + 1))) {
679 const word = s.slice(i, e).toLowerCase();
680 if (word === 'end') {
681 if (open.pop() === undefined) return null;
682 } else if (BLOCK_OPENERS.has(word)) {
683 open.push([i, word === 'begin' ? OPEN_BEGIN : word === 'asm' ? OPEN_ASM : OPEN_OTHER]);
684 }
685 }
686 i = e;
687 continue;
688 }
689 i++;
690 }
691 return open;
692}
693
694/**
695 * In every conditional whose branches each leave blocks open for the code

Callers 1

blankDuplicateBeginsFunction · 0.85

Calls 6

commentOrStringEndFunction · 0.85
isIdentStartFunction · 0.85
overlapsRangeFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
wordEndFunction · 0.70

Tested by

no test coverage detected