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

Function parseCasePattern

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

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected