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

Function stripErlang

src/resolution/strip-comments.ts:486–528  ·  view source on GitHub ↗

* Erlang: `%` starts a line comment unless it sits inside a `"string"`, a * `'quoted atom'`, or is the character literal `$%`. Strings and quoted atoms * are left intact (a behaviour callback name can be a quoted atom); only the * comment text is blanked.

(src: string)

Source from the content-addressed store, hash-verified

484 * comment text is blanked.
485 */
486function stripErlang(src: string): string {
487 const out = src.split('');
488 let i = 0;
489 const n = src.length;
490
491 while (i < n) {
492 const c = src[i];
493
494 if (c === '"' || c === "'") {
495 const quote = c;
496 i++;
497 while (i < n && src[i] !== quote) {
498 if (src[i] === '\\' && i + 1 < n) {
499 i += 2;
500 continue;
501 }
502 i++;
503 }
504 if (i < n) i++;
505 continue;
506 }
507
508 // Character literal: `$x`, `$\n`, `$%` — the next char (or escape) is data.
509 if (c === '$') {
510 i++;
511 if (i < n && src[i] === '\\') i++;
512 i++;
513 continue;
514 }
515
516 if (c === '%') {
517 let end = i;
518 while (end < n && src[end] !== '\n') end++;
519 blankRange(out, i, end, src);
520 i = end;
521 continue;
522 }
523
524 i++;
525 }
526
527 return out.join('');
528}

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected