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

Function conditionalGroups

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

* Every closed conditional group in `s`, innermost first. Directives in * strings and comments don't count, nor do `(*$…*)` ones, which the grammar * reads as comments.

(s: string)

Source from the content-addressed store, hash-verified

463 * reads as comments.
464 */
465function conditionalGroups(s: string): ConditionalGroup[] {
466 const groups: ConditionalGroup[] = [];
467 const open: ConditionalGroup[] = [];
468 const n = s.length;
469 let i = 0;
470 while (i < n) {
471 const c = s.charCodeAt(i);
472 const k = c === CH_LBRACE || c === CH_QUOTE || c === CH_LPAREN || c === CH_SLASH ? commentOrStringEnd(s, i) : -1;
473 if (k < 0) {
474 i++;
475 continue;
476 }
477 if (c === CH_LBRACE && s.charCodeAt(i + 1) === CH_DOLLAR) {
478 const kind = conditionalKind(s, i);
479 const top = open[open.length - 1];
480 if (kind === COND_OPEN) {
481 if (top) top.nested[top.nested.length - 1] = true;
482 open.push({ bounds: [i, k], nested: [false] });
483 } else if (kind === COND_ELSE && top) {
484 top.bounds.push(i, k);
485 top.nested.push(false);
486 } else if (kind === COND_CLOSE && top) {
487 top.bounds.push(i, k);
488 groups.push(open.pop()!);
489 }
490 }
491 i = k;
492 }
493 return groups;
494}
495
496/**
497 * Whether the code from `from` to `to` is a routine's locals and body, the

Callers 1

preParsePascalFunction · 0.85

Calls 3

commentOrStringEndFunction · 0.85
conditionalKindFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected