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

Function tryParseBraceExpr

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

Source from the content-addressed store, hash-verified

2209}
2210
2211function tryParseBraceExpr(P: ParseState): TsNode | null {
2212 // {N..M} where N, M are numbers or single chars
2213 const save = saveLex(P.L)
2214 if (peek(P.L) !== '{') return null
2215 const oStart = P.L.b
2216 advance(P.L)
2217 const oEnd = P.L.b
2218 // First part
2219 const p1Start = P.L.b
2220 while (isDigit(peek(P.L)) || isIdentStart(peek(P.L))) advance(P.L)
2221 const p1End = P.L.b
2222 if (p1End === p1Start || peek(P.L) !== '.' || peek(P.L, 1) !== '.') {
2223 restoreLex(P.L, save)
2224 return null
2225 }
2226 const dotStart = P.L.b
2227 advance(P.L)
2228 advance(P.L)
2229 const dotEnd = P.L.b
2230 const p2Start = P.L.b
2231 while (isDigit(peek(P.L)) || isIdentStart(peek(P.L))) advance(P.L)
2232 const p2End = P.L.b
2233 if (p2End === p2Start || peek(P.L) !== '}') {
2234 restoreLex(P.L, save)
2235 return null
2236 }
2237 const cStart = P.L.b
2238 advance(P.L)
2239 const cEnd = P.L.b
2240 const p1Text = sliceBytes(P, p1Start, p1End)
2241 const p2Text = sliceBytes(P, p2Start, p2End)
2242 const p1IsNum = /^\d+$/.test(p1Text)
2243 const p2IsNum = /^\d+$/.test(p2Text)
2244 // Valid brace expression: both numbers OR both single chars. Mixed = reject.
2245 if (p1IsNum !== p2IsNum) {
2246 restoreLex(P.L, save)
2247 return null
2248 }
2249 if (!p1IsNum && (p1Text.length !== 1 || p2Text.length !== 1)) {
2250 restoreLex(P.L, save)
2251 return null
2252 }
2253 const p1Type = p1IsNum ? 'number' : 'word'
2254 const p2Type = p2IsNum ? 'number' : 'word'
2255 return mk(P, 'brace_expression', oStart, cEnd, [
2256 mk(P, '{', oStart, oEnd, []),
2257 mk(P, p1Type, p1Start, p1End, []),
2258 mk(P, '..', dotStart, dotEnd, []),
2259 mk(P, p2Type, p2Start, p2End, []),
2260 mk(P, '}', cStart, cEnd, []),
2261 ])
2262}
2263
2264function tryParseBraceLikeCat(P: ParseState): TsNode[] | null {
2265 // {a,b,c} or {} → split into word fragments like tree-sitter does

Callers 1

parseWordFunction · 0.85

Calls 8

saveLexFunction · 0.85
advanceFunction · 0.85
isDigitFunction · 0.85
isIdentStartFunction · 0.85
restoreLexFunction · 0.85
sliceBytesFunction · 0.85
peekFunction · 0.70
mkFunction · 0.70

Tested by

no test coverage detected