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

Function stripPython

src/resolution/strip-comments.ts:264–322  ·  view source on GitHub ↗
(src: string)

Source from the content-addressed store, hash-verified

262// ---------- Python ----------
263
264function stripPython(src: string): string {
265 const out = new BlankedText(src);
266 let i = 0;
267 const n = src.length;
268
269 while (i < n) {
270 const c = src[i]!;
271 const c2 = src[i + 1] ?? '';
272 const c3 = src[i + 2] ?? '';
273
274 // Triple-quoted string: """...""" or '''...'''
275 if ((c === '"' || c === "'") && c2 === c && c3 === c) {
276 const quote = c;
277 const start = i;
278 i += 3;
279 while (i < n) {
280 if (src[i] === '\\' && i + 1 < n) {
281 i += 2;
282 continue;
283 }
284 if (src[i] === quote && src[i + 1] === quote && src[i + 2] === quote) {
285 i += 3;
286 break;
287 }
288 i++;
289 }
290 out.blank(start, i);
291 continue;
292 }
293
294 // Single-line string: '...' or "..."
295 if (c === '"' || c === "'") {
296 const quote = c;
297 i++;
298 while (i < n && src[i] !== quote) {
299 if (src[i] === '\\' && i + 1 < n) {
300 i += 2;
301 continue;
302 }
303 if (src[i] === '\n') break; // unterminated
304 i++;
305 }
306 if (i < n && src[i] === quote) i++;
307 continue;
308 }
309
310 // Line comment
311 if (c === '#') {
312 const start = i;
313 while (i < n && src[i] !== '\n') i++;
314 out.blank(start, i);
315 continue;
316 }
317
318 i++;
319 }
320
321 return out.text();

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankMethod · 0.95
textMethod · 0.95

Tested by

no test coverage detected