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

Function parseCasePattern

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

Source from the content-addressed store, hash-verified

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