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

Function parseExpansionRegexSegmented

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

Source from the content-addressed store, hash-verified

3030// repeat(choice(regex, string, raw_string, ')', /\s+/→regex)). Each quote
3031// becomes a SIBLING node, not absorbed. `${f%'str'*}` → (raw_string)(regex).
3032function parseExpansionRegexSegmented(P: ParseState): TsNode[] {
3033 const out: TsNode[] = []
3034 let segStart = P.L.b
3035 const flushRegex = (): void => {
3036 if (P.L.b > segStart) out.push(mk(P, 'regex', segStart, P.L.b, []))
3037 }
3038 while (P.L.i < P.L.len) {
3039 const c = peek(P.L)
3040 if (c === '}' || c === '\n') break
3041 if (c === '\\' && P.L.i + 1 < P.L.len) {
3042 advance(P.L)
3043 advance(P.L)
3044 continue
3045 }
3046 if (c === '"') {
3047 flushRegex()
3048 out.push(parseDoubleQuoted(P))
3049 segStart = P.L.b
3050 continue
3051 }
3052 if (c === "'") {
3053 flushRegex()
3054 const rStart = P.L.b
3055 advance(P.L)
3056 while (P.L.i < P.L.len && peek(P.L) !== "'") advance(P.L)
3057 if (peek(P.L) === "'") advance(P.L)
3058 out.push(mk(P, 'raw_string', rStart, P.L.b, []))
3059 segStart = P.L.b
3060 continue
3061 }
3062 // Nested ${...} $(...) — opaque scan so their } doesn't terminate us
3063 if (c === '$') {
3064 const c1 = peek(P.L, 1)
3065 if (c1 === '{') {
3066 let d = 1
3067 advance(P.L)
3068 advance(P.L)
3069 while (P.L.i < P.L.len && d > 0) {
3070 const nc = peek(P.L)
3071 if (nc === '{') d++
3072 else if (nc === '}') d--
3073 advance(P.L)
3074 }
3075 continue
3076 }
3077 if (c1 === '(') {
3078 let d = 1
3079 advance(P.L)
3080 advance(P.L)
3081 while (P.L.i < P.L.len && d > 0) {
3082 const nc = peek(P.L)
3083 if (nc === '(') d++
3084 else if (nc === ')') d--
3085 advance(P.L)
3086 }
3087 continue
3088 }
3089 }

Callers 1

parseExpansionBodyFunction · 0.85

Calls 6

advanceFunction · 0.85
flushRegexFunction · 0.85
parseDoubleQuotedFunction · 0.85
peekFunction · 0.70
mkFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected