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

Function parseCaseItem

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

Source from the content-addressed store, hash-verified

3344}
3345
3346function parseCaseItem(P: ParseState): TsNode | null {
3347 skipBlanks(P.L)
3348 const start = P.L.b
3349 const kids: TsNode[] = []
3350 // Optional leading '(' before pattern — bash allows (pattern) syntax
3351 if (peek(P.L) === '(') {
3352 const s = P.L.b
3353 advance(P.L)
3354 kids.push(mk(P, '(', s, P.L.b, []))
3355 }
3356 // Pattern(s)
3357 let isFirstAlt = true
3358 while (true) {
3359 skipBlanks(P.L)
3360 const c = peek(P.L)
3361 if (c === ')' || c === '') break
3362 const pats = parseCasePattern(P)
3363 if (pats.length === 0) break
3364 // tree-sitter quirk: first alternative with quotes is inlined as flat
3365 // siblings; subsequent alternatives are wrapped in (concatenation) with
3366 // `word` instead of `extglob_pattern` for bare segments.
3367 if (!isFirstAlt && pats.length > 1) {
3368 const rewritten = pats.map(p =>
3369 p.type === 'extglob_pattern'
3370 ? mk(P, 'word', p.startIndex, p.endIndex, [])
3371 : p,
3372 )
3373 const first = rewritten[0]!
3374 const last = rewritten[rewritten.length - 1]!
3375 kids.push(
3376 mk(P, 'concatenation', first.startIndex, last.endIndex, rewritten),
3377 )
3378 } else {
3379 kids.push(...pats)
3380 }
3381 isFirstAlt = false
3382 skipBlanks(P.L)
3383 // \<newline> line continuation between alternatives
3384 if (peek(P.L) === '\\' && peek(P.L, 1) === '\n') {
3385 advance(P.L)
3386 advance(P.L)
3387 skipBlanks(P.L)
3388 }
3389 if (peek(P.L) === '|') {
3390 const s = P.L.b
3391 advance(P.L)
3392 kids.push(mk(P, '|', s, P.L.b, []))
3393 // \<newline> after | is also a line continuation
3394 if (peek(P.L) === '\\' && peek(P.L, 1) === '\n') {
3395 advance(P.L)
3396 advance(P.L)
3397 }
3398 } else {
3399 break
3400 }
3401 }
3402 if (peek(P.L) === ')') {
3403 const s = P.L.b

Callers 1

parseCaseFunction · 0.85

Calls 12

skipBlanksFunction · 0.85
advanceFunction · 0.85
parseCasePatternFunction · 0.85
parseStatementsFunction · 0.85
saveLexFunction · 0.85
nextTokenFunction · 0.85
leafFunction · 0.85
restoreLexFunction · 0.85
sliceBytesFunction · 0.85
peekFunction · 0.70
mkFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected