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

Function parseArithUnary

src/utils/bash/bashParser.ts:4260–4296  ·  view source on GitHub ↗
(
  P: ParseState,
  stop: string,
  mode: ArithMode,
)

Source from the content-addressed store, hash-verified

4258}
4259
4260function parseArithUnary(
4261 P: ParseState,
4262 stop: string,
4263 mode: ArithMode,
4264): TsNode | null {
4265 skipBlanks(P.L)
4266 if (isArithStop(P, stop)) return null
4267 const c = peek(P.L)
4268 const c1 = peek(P.L, 1)
4269 // Prefix ++ --
4270 if ((c === '+' && c1 === '+') || (c === '-' && c1 === '-')) {
4271 const s = P.L.b
4272 advance(P.L)
4273 advance(P.L)
4274 const op = mk(P, c + c1, s, P.L.b, [])
4275 const inner = parseArithUnary(P, stop, mode)
4276 if (!inner) return op
4277 return mk(P, 'unary_expression', op.startIndex, inner.endIndex, [op, inner])
4278 }
4279 if (c === '-' || c === '+' || c === '!' || c === '~') {
4280 // In 'word'/'assign' mode (c-style for head), `-N` is a single number
4281 // literal per tree-sitter, not unary_expression. 'var' mode uses unary.
4282 if (mode !== 'var' && c === '-' && isDigit(c1)) {
4283 const s = P.L.b
4284 advance(P.L)
4285 while (isDigit(peek(P.L))) advance(P.L)
4286 return mk(P, 'number', s, P.L.b, [])
4287 }
4288 const s = P.L.b
4289 advance(P.L)
4290 const op = mk(P, c, s, P.L.b, [])
4291 const inner = parseArithUnary(P, stop, mode)
4292 if (!inner) return op
4293 return mk(P, 'unary_expression', op.startIndex, inner.endIndex, [op, inner])
4294 }
4295 return parseArithPostfix(P, stop, mode)
4296}
4297
4298function parseArithPostfix(
4299 P: ParseState,

Callers 1

parseArithBinaryFunction · 0.85

Calls 7

skipBlanksFunction · 0.85
isArithStopFunction · 0.85
advanceFunction · 0.85
isDigitFunction · 0.85
parseArithPostfixFunction · 0.85
peekFunction · 0.70
mkFunction · 0.70

Tested by

no test coverage detected