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

Function parseTestRegexRhs

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

Source from the content-addressed store, hash-verified

3937// RHS of =~ in [[ ]] — scan as single (regex) node with paren/bracket counting
3938// so | ( ) inside the regex don't break parsing. Stop at ]] or ws+&&/||.
3939function parseTestRegexRhs(P: ParseState): TsNode | null {
3940 skipBlanks(P.L)
3941 const start = P.L.b
3942 let parenDepth = 0
3943 let bracketDepth = 0
3944 while (P.L.i < P.L.len) {
3945 const c = peek(P.L)
3946 if (c === '\\' && P.L.i + 1 < P.L.len) {
3947 advance(P.L)
3948 advance(P.L)
3949 continue
3950 }
3951 if (c === '\n') break
3952 if (parenDepth === 0 && bracketDepth === 0) {
3953 if (c === ']' && peek(P.L, 1) === ']') break
3954 if (c === ' ' || c === '\t') {
3955 // Peek past blanks for ]] or &&/||
3956 let j = P.L.i
3957 while (j < P.L.len && (P.L.src[j] === ' ' || P.L.src[j] === '\t')) j++
3958 const nc = P.L.src[j] ?? ''
3959 const nc1 = P.L.src[j + 1] ?? ''
3960 if (
3961 (nc === ']' && nc1 === ']') ||
3962 (nc === '&' && nc1 === '&') ||
3963 (nc === '|' && nc1 === '|')
3964 ) {
3965 break
3966 }
3967 advance(P.L)
3968 continue
3969 }
3970 }
3971 if (c === '(') parenDepth++
3972 else if (c === ')' && parenDepth > 0) parenDepth--
3973 else if (c === '[') bracketDepth++
3974 else if (c === ']' && bracketDepth > 0) bracketDepth--
3975 advance(P.L)
3976 }
3977 if (P.L.b === start) return null
3978 return mk(P, 'regex', start, P.L.b, [])
3979}
3980
3981// RHS of ==/!=/= in [[ ]] — returns array of parts. Bare text → extglob_pattern
3982// (with paren counting for @(a|b)); $(...)/${}/quoted → proper node types.

Callers 1

parseTestBinaryFunction · 0.85

Calls 4

skipBlanksFunction · 0.85
advanceFunction · 0.85
mkFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected