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

Function parseTestExtglobRhs

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

Source from the content-addressed store, hash-verified

3982// (with paren counting for @(a|b)); $(...)/${}/quoted → proper node types.
3983// Multiple parts become flat children of binary_expression per tree-sitter.
3984function parseTestExtglobRhs(P: ParseState): TsNode[] {
3985 skipBlanks(P.L)
3986 const parts: TsNode[] = []
3987 let segStart = P.L.b
3988 let segStartI = P.L.i
3989 let parenDepth = 0
3990 const flushSeg = () => {
3991 if (P.L.i > segStartI) {
3992 const text = P.src.slice(segStartI, P.L.i)
3993 // Pure number stays number; everything else is extglob_pattern
3994 const type = /^\d+$/.test(text) ? 'number' : 'extglob_pattern'
3995 parts.push(mk(P, type, segStart, P.L.b, []))
3996 }
3997 }
3998 while (P.L.i < P.L.len) {
3999 const c = peek(P.L)
4000 if (c === '\\' && P.L.i + 1 < P.L.len) {
4001 advance(P.L)
4002 advance(P.L)
4003 continue
4004 }
4005 if (c === '\n') break
4006 if (parenDepth === 0) {
4007 if (c === ']' && peek(P.L, 1) === ']') break
4008 if (c === ' ' || c === '\t') {
4009 let j = P.L.i
4010 while (j < P.L.len && (P.L.src[j] === ' ' || P.L.src[j] === '\t')) j++
4011 const nc = P.L.src[j] ?? ''
4012 const nc1 = P.L.src[j + 1] ?? ''
4013 if (
4014 (nc === ']' && nc1 === ']') ||
4015 (nc === '&' && nc1 === '&') ||
4016 (nc === '|' && nc1 === '|')
4017 ) {
4018 break
4019 }
4020 advance(P.L)
4021 continue
4022 }
4023 }
4024 // $ " ' must be parsed even inside @( ) extglob parens — parseDollarLike
4025 // consumes matching ) so parenDepth stays consistent.
4026 if (c === '$') {
4027 const c1 = peek(P.L, 1)
4028 if (
4029 c1 === '(' ||
4030 c1 === '{' ||
4031 isIdentStart(c1) ||
4032 SPECIAL_VARS.has(c1)
4033 ) {
4034 flushSeg()
4035 const exp = parseDollarLike(P)
4036 if (exp) parts.push(exp)
4037 segStart = P.L.b
4038 segStartI = P.L.i
4039 continue
4040 }
4041 }

Callers 1

parseTestBinaryFunction · 0.85

Calls 10

skipBlanksFunction · 0.85
advanceFunction · 0.85
isIdentStartFunction · 0.85
flushSegFunction · 0.85
parseDollarLikeFunction · 0.85
parseDoubleQuotedFunction · 0.85
nextTokenFunction · 0.85
leafFunction · 0.85
peekFunction · 0.70
hasMethod · 0.45

Tested by

no test coverage detected