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

Function tryParseAssignment

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

Source from the content-addressed store, hash-verified

1431}
1432
1433function tryParseAssignment(P: ParseState): TsNode | null {
1434 const save = saveLex(P.L)
1435 skipBlanks(P.L)
1436 const startB = P.L.b
1437 // Must start with identifier
1438 if (!isIdentStart(peek(P.L))) {
1439 restoreLex(P.L, save)
1440 return null
1441 }
1442 while (isIdentChar(peek(P.L))) advance(P.L)
1443 const nameEnd = P.L.b
1444 // Optional subscript
1445 let subEnd = nameEnd
1446 if (peek(P.L) === '[') {
1447 advance(P.L)
1448 let depth = 1
1449 while (P.L.i < P.L.len && depth > 0) {
1450 const c = peek(P.L)
1451 if (c === '[') depth++
1452 else if (c === ']') depth--
1453 advance(P.L)
1454 }
1455 subEnd = P.L.b
1456 }
1457 const c = peek(P.L)
1458 const c1 = peek(P.L, 1)
1459 let op: string
1460 if (c === '=' && c1 !== '=') {
1461 op = '='
1462 } else if (c === '+' && c1 === '=') {
1463 op = '+='
1464 } else {
1465 restoreLex(P.L, save)
1466 return null
1467 }
1468 const nameNode = mk(P, 'variable_name', startB, nameEnd, [])
1469 // Subscript handling: wrap in subscript node if present
1470 let lhs: TsNode = nameNode
1471 if (subEnd > nameEnd) {
1472 const brOpen = mk(P, '[', nameEnd, nameEnd + 1, [])
1473 const idx = parseSubscriptIndex(P, nameEnd + 1, subEnd - 1)
1474 const brClose = mk(P, ']', subEnd - 1, subEnd, [])
1475 lhs = mk(P, 'subscript', startB, subEnd, [nameNode, brOpen, idx, brClose])
1476 }
1477 const opStart = P.L.b
1478 advance(P.L)
1479 if (op === '+=') advance(P.L)
1480 const opEnd = P.L.b
1481 const opNode = mk(P, op, opStart, opEnd, [])
1482 let val: TsNode | null = null
1483 if (peek(P.L) === '(') {
1484 // Array
1485 const aoTok = nextToken(P.L, 'cmd')
1486 const aOpen = leaf(P, '(', aoTok)
1487 const elems: TsNode[] = [aOpen]
1488 while (true) {
1489 skipBlanks(P.L)
1490 if (peek(P.L) === ')') break

Callers 2

parseSimpleCommandFunction · 0.85
parseDeclarationFunction · 0.85

Calls 12

saveLexFunction · 0.85
skipBlanksFunction · 0.85
isIdentStartFunction · 0.85
restoreLexFunction · 0.85
isIdentCharFunction · 0.85
advanceFunction · 0.85
mkFunction · 0.85
parseSubscriptIndexFunction · 0.85
nextTokenFunction · 0.85
leafFunction · 0.85
parseWordFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected