MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / stripComments

Function stripComments

scripts/rubi/extract-rules.ts:45–62  ·  view source on GitHub ↗
(src: string)

Source from the content-addressed store, hash-verified

43
44/** Strip WL comments (nested), preserving newlines for cell structure. */
45export function stripComments(src: string): string {
46 let out = '';
47 let depth = 0;
48 for (let i = 0; i < src.length; i++) {
49 if (src.startsWith('(*', i)) {
50 depth++;
51 i++;
52 } else if (depth > 0 && src.startsWith('*)', i)) {
53 depth--;
54 i++;
55 } else if (depth === 0) {
56 out += src[i];
57 } else if (src[i] === '\n') {
58 out += '\n';
59 }
60 }
61 return out;
62}
63
64function asCall(expr: Json, op: string): Json[] | null {
65 return Array.isArray(expr) && expr[0] === op ? (expr as Json[]) : null;

Callers 2

extractRulesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected