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

Function blankDuplicateBegins

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

* In every conditional (holding no conditional of its own) whose branches * each leave blocks open for the code after it to close. When they all leave * the same number of `begin`s open, the `begin`s each branch after the first * leaves open are blanked: read together, they would open that many b

(s: string, groups: readonly ConditionalGroup[], ranges: number[])

Source from the content-addressed store, hash-verified

657 * whole, so the Pascal one is the body; the graph reads nothing in assembler.
658 */
659function blankDuplicateBegins(s: string, groups: readonly ConditionalGroup[], ranges: number[]): void {
660 for (const { bounds, nested } of groups) {
661 if (nested.length < 2 || nested.includes(true)) continue;
662 const open: Array<Array<[number, number]>> = [];
663 for (let b = 0; b < nested.length; b++) {
664 const blocks = openBlocks(s, bounds[2 * b + 1]!, bounds[2 * b + 2]!);
665 if (!blocks || blocks.length === 0) break;
666 open.push(blocks);
667 }
668 if (open.length < nested.length) continue;
669 const kinds = (kind: number) => open.filter((o) => o.every(([, k]) => k === kind)).length;
670 if (kinds(OPEN_BEGIN) === open.length && open.every((o) => o.length === open[0]!.length)) {
671 for (let b = 1; b < open.length; b++) for (const [at] of open[b]!) ranges.push(at, at + 5);
672 } else if (open.every((o) => o.length === 1) && kinds(OPEN_ASM) > 0 && kinds(OPEN_BEGIN) > 0 && kinds(OPEN_BEGIN) + kinds(OPEN_ASM) === open.length) {
673 let kept = false;
674 for (let b = 0; b < open.length; b++) {
675 const [at, kind] = open[b]![0]!;
676 if (kind === OPEN_ASM) ranges.push(bounds[2 * b + 1]!, bounds[2 * b + 2]!);
677 else if (kept) ranges.push(at, at + 5);
678 else kept = true;
679 }
680 }
681 }
682}
683
684const SHAPE_NONE = -1, SHAPE_STATEMENTS = 0, SHAPE_STATEMENTS_SEMI = 1, SHAPE_EMPTY = 2;
685const START_NONE = 0, START_STATEMENT = 1, START_CALL = 2, START_NAME = 3;

Callers 1

preParsePascalFunction · 0.85

Calls 3

openBlocksFunction · 0.85
pushMethod · 0.80
kindsFunction · 0.70

Tested by

no test coverage detected