MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseDoubleQuoted

Function parseDoubleQuoted

source code/utils/bash/bashParser.ts:2341–2429  ·  view source on GitHub ↗
(P: ParseState)

Source from the content-addressed store, hash-verified

2339}
2340
2341function parseDoubleQuoted(P: ParseState): TsNode {
2342 const qStart = P.L.b
2343 advance(P.L)
2344 const qEnd = P.L.b
2345 const openQ = mk(P, '"', qStart, qEnd, [])
2346 const parts: TsNode[] = [openQ]
2347 let contentStart = P.L.b
2348 let contentStartI = P.L.i
2349 const flushContent = (): void => {
2350 if (P.L.b > contentStart) {
2351 // Tree-sitter's extras rule /\s/ has higher precedence than
2352 // string_content (prec -1), so whitespace-only segments are elided.
2353 // `" ${x} "` → (string (expansion)) not (string (string_content)(expansion)(string_content)).
2354 // Note: this intentionally diverges from preserving all content — cc
2355 // tests relying on whitespace-only string_content need updating
2356 // (CCReconcile).
2357 const txt = P.src.slice(contentStartI, P.L.i)
2358 if (!/^[ \t]+$/.test(txt)) {
2359 parts.push(mk(P, 'string_content', contentStart, P.L.b, []))
2360 }
2361 }
2362 }
2363 while (P.L.i < P.L.len) {
2364 const c = peek(P.L)
2365 if (c === '"') break
2366 if (c === '\\' && P.L.i + 1 < P.L.len) {
2367 advance(P.L)
2368 advance(P.L)
2369 continue
2370 }
2371 if (c === '\n') {
2372 // Split string_content at newline
2373 flushContent()
2374 advance(P.L)
2375 contentStart = P.L.b
2376 contentStartI = P.L.i
2377 continue
2378 }
2379 if (c === '$') {
2380 const c1 = peek(P.L, 1)
2381 if (
2382 c1 === '(' ||
2383 c1 === '{' ||
2384 isIdentStart(c1) ||
2385 SPECIAL_VARS.has(c1) ||
2386 isDigit(c1)
2387 ) {
2388 flushContent()
2389 const exp = parseDollarLike(P)
2390 if (exp) parts.push(exp)
2391 contentStart = P.L.b
2392 contentStartI = P.L.i
2393 continue
2394 }
2395 // Bare $ not at end-of-string: tree-sitter emits it as an anonymous
2396 // '$' token, which splits string_content. $ immediately before the
2397 // closing " is absorbed into the preceding string_content.
2398 if (c1 !== '"' && c1 !== '') {

Callers 8

parseWordFunction · 0.85
parseExpansionBodyFunction · 0.85
parseExpansionRestFunction · 0.85
parseTestBinaryFunction · 0.85
parseTestExtglobRhsFunction · 0.85
parseArithPrimaryFunction · 0.85

Calls 9

advanceFunction · 0.85
mkFunction · 0.85
flushContentFunction · 0.85
isIdentStartFunction · 0.85
isDigitFunction · 0.85
parseDollarLikeFunction · 0.85
parseBacktickFunction · 0.85
peekFunction · 0.70
hasMethod · 0.45

Tested by

no test coverage detected