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

Function openBlocks

src/extraction/languages/pascal-preparse.ts:621–646  ·  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.

(s: string, from: number, to: number)

Source from the content-addressed store, hash-verified

619 * `case` and `record`), or null when it closes a block it didn't open.
620 */
621function openBlocks(s: string, from: number, to: number): Array<[number, number]> | null {
622 const open: Array<[number, number]> = [];
623 let i = from;
624 while (i < to) {
625 const k = commentOrStringEnd(s, i);
626 if (k >= 0) {
627 i = k;
628 continue;
629 }
630 if (isIdentStart(s.charCodeAt(i))) {
631 const e = wordEnd(s, i + 1);
632 if (e - i >= 3 && e - i <= 6) {
633 const word = s.slice(i, e).toLowerCase();
634 if (word === 'end') {
635 if (open.pop() === undefined) return null;
636 } else if (BLOCK_OPENERS.has(word)) {
637 open.push([i, word === 'begin' ? OPEN_BEGIN : word === 'asm' ? OPEN_ASM : OPEN_OTHER]);
638 }
639 }
640 i = e;
641 continue;
642 }
643 i++;
644 }
645 return open;
646}
647
648/**
649 * In every conditional (holding no conditional of its own) whose branches

Callers 1

blankDuplicateBeginsFunction · 0.85

Calls 5

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

Tested by

no test coverage detected