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

Function conditionalGroups

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

468 * reads as comments.
469 */
470function conditionalGroups(s: string): ConditionalGroup[] {
471 const groups: ConditionalGroup[] = [];
472 const open: ConditionalGroup[] = [];
473 const n = s.length;
474 let i = 0;
475 while (i < n) {
476 const c = s.charCodeAt(i);
477 const k = c === CH_LBRACE || c === CH_QUOTE || c === CH_LPAREN || c === CH_SLASH ? commentOrStringEnd(s, i) : -1;
478 if (k < 0) {
479 i++;
480 continue;
481 }
482 if (c === CH_LBRACE && s.charCodeAt(i + 1) === CH_DOLLAR) {
483 const kind = conditionalKind(s, i);
484 const top = open[open.length - 1];
485 if (kind === COND_OPEN) {
486 if (top) top.nested[top.nested.length - 1] = true;
487 open.push({ bounds: [i, k], nested: [false] });
488 } else if (kind === COND_ELSE && top) {
489 top.bounds.push(i, k);
490 top.nested.push(false);
491 } else if (kind === COND_CLOSE && top) {
492 top.bounds.push(i, k);
493 groups.push(open.pop()!);
494 }
495 }
496 i = k;
497 }
498 return groups;
499}
500
501/**
502 * 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