MCPcopy Index your code
hub / github.com/codeaashu/claude-code / parseCasePattern

Function parseCasePattern

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

Source from the content-addressed store, hash-verified

3439}
3440
3441function parseCasePattern(P: ParseState): TsNode[] {
3442 skipBlanks(P.L)
3443 const save = saveLex(P.L)
3444 const start = P.L.b
3445 const startI = P.L.i
3446 let parenDepth = 0
3447 let hasDollar = false
3448 let hasBracketOutsideParen = false
3449 let hasQuote = false
3450 while (P.L.i < P.L.len) {
3451 const c = peek(P.L)
3452 if (c === '\\' && P.L.i + 1 < P.L.len) {
3453 // Escaped char — consume both (handles `bar\ baz` as single pattern)
3454 // \<newline> is a line continuation; eat it but stay in pattern.
3455 advance(P.L)
3456 advance(P.L)
3457 continue
3458 }
3459 if (c === '"' || c === "'") {
3460 hasQuote = true
3461 // Skip past the quoted segment so its content (spaces, |, etc.) doesn't
3462 // break the peek-ahead scan.
3463 advance(P.L)
3464 while (P.L.i < P.L.len && peek(P.L) !== c) {
3465 if (peek(P.L) === '\\' && P.L.i + 1 < P.L.len) advance(P.L)
3466 advance(P.L)
3467 }
3468 if (peek(P.L) === c) advance(P.L)
3469 continue
3470 }
3471 // Paren counting: any ( inside pattern opens a scope; don't break at ) or |
3472 // until balanced. Handles extglob *(a|b) and nested shapes *([0-9])([0-9]).
3473 if (c === '(') {
3474 parenDepth++
3475 advance(P.L)
3476 continue
3477 }
3478 if (parenDepth > 0) {
3479 if (c === ')') {
3480 parenDepth--
3481 advance(P.L)
3482 continue
3483 }
3484 if (c === '\n') break
3485 advance(P.L)
3486 continue
3487 }
3488 if (c === ')' || c === '|' || c === ' ' || c === '\t' || c === '\n') break
3489 if (c === '$') hasDollar = true
3490 if (c === '[') hasBracketOutsideParen = true
3491 advance(P.L)
3492 }
3493 if (P.L.b === start) return []
3494 const text = P.src.slice(startI, P.L.i)
3495 const hasExtglobParen = /[*?+@!]\(/.test(text)
3496 // Quoted segments in pattern: tree-sitter splits at quote boundaries into
3497 // multiple sibling nodes. `*"foo"*` → (extglob_pattern)(string)(extglob_pattern).
3498 // Re-scan with a segmenting pass.

Callers 1

parseCaseItemFunction · 0.85

Calls 8

skipBlanksFunction · 0.85
saveLexFunction · 0.85
advanceFunction · 0.85
restoreLexFunction · 0.85
parseWordFunction · 0.85
mkFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected