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

Function parseArithPrimary

source code/utils/bash/bashParser.ts:4323–4426  ·  view source on GitHub ↗
(
  P: ParseState,
  stop: string,
  mode: ArithMode,
)

Source from the content-addressed store, hash-verified

4321}
4322
4323function parseArithPrimary(
4324 P: ParseState,
4325 stop: string,
4326 mode: ArithMode,
4327): TsNode | null {
4328 skipBlanks(P.L)
4329 if (isArithStop(P, stop)) return null
4330 const c = peek(P.L)
4331 if (c === '(') {
4332 const s = P.L.b
4333 advance(P.L)
4334 const open = mk(P, '(', s, P.L.b, [])
4335 // Parenthesized expression may contain comma-separated exprs
4336 const inners = parseArithCommaList(P, ')', mode)
4337 skipBlanks(P.L)
4338 let close: TsNode
4339 if (peek(P.L) === ')') {
4340 const cs = P.L.b
4341 advance(P.L)
4342 close = mk(P, ')', cs, P.L.b, [])
4343 } else {
4344 close = mk(P, ')', P.L.b, P.L.b, [])
4345 }
4346 return mk(P, 'parenthesized_expression', open.startIndex, close.endIndex, [
4347 open,
4348 ...inners,
4349 close,
4350 ])
4351 }
4352 if (c === '"') {
4353 return parseDoubleQuoted(P)
4354 }
4355 if (c === '$') {
4356 return parseDollarLike(P)
4357 }
4358 if (isDigit(c)) {
4359 const s = P.L.b
4360 while (isDigit(peek(P.L))) advance(P.L)
4361 // Hex: 0x1f
4362 if (
4363 P.L.b - s === 1 &&
4364 c === '0' &&
4365 (peek(P.L) === 'x' || peek(P.L) === 'X')
4366 ) {
4367 advance(P.L)
4368 while (isHexDigit(peek(P.L))) advance(P.L)
4369 }
4370 // Base notation: BASE#DIGITS e.g. 2#1010, 16#ff
4371 else if (peek(P.L) === '#') {
4372 advance(P.L)
4373 while (isBaseDigit(peek(P.L))) advance(P.L)
4374 }
4375 return mk(P, 'number', s, P.L.b, [])
4376 }
4377 if (isIdentStart(c)) {
4378 const s = P.L.b
4379 while (isIdentChar(peek(P.L))) advance(P.L)
4380 const nc = peek(P.L)

Callers 1

parseArithPostfixFunction · 0.85

Calls 14

skipBlanksFunction · 0.85
isArithStopFunction · 0.85
advanceFunction · 0.85
mkFunction · 0.85
parseArithCommaListFunction · 0.85
parseDoubleQuotedFunction · 0.85
parseDollarLikeFunction · 0.85
isDigitFunction · 0.85
isHexDigitFunction · 0.85
isBaseDigitFunction · 0.85
isIdentStartFunction · 0.85
isIdentCharFunction · 0.85

Tested by

no test coverage detected