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

Function parseCaseItem

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

Source from the content-addressed store, hash-verified

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

Callers 1

parseCaseFunction · 0.85

Calls 11

skipBlanksFunction · 0.85
advanceFunction · 0.85
mkFunction · 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

Tested by

no test coverage detected