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

Function parseDoubleQuoted

src/utils/bash/bashParser.ts:2335–2423  ·  view source on GitHub ↗
(P: ParseState)

Source from the content-addressed store, hash-verified

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

Callers 8

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

Calls 10

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

Tested by

no test coverage detected