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

Function parseDeclaration

source code/utils/bash/bashParser.ts:3600–3650  ·  view source on GitHub ↗
(P: ParseState, kwTok: Token)

Source from the content-addressed store, hash-verified

3598}
3599
3600function parseDeclaration(P: ParseState, kwTok: Token): TsNode {
3601 const kw = leaf(P, kwTok.value, kwTok)
3602 const kids: TsNode[] = [kw]
3603 while (true) {
3604 skipBlanks(P.L)
3605 const c = peek(P.L)
3606 if (
3607 c === '' ||
3608 c === '\n' ||
3609 c === ';' ||
3610 c === '&' ||
3611 c === '|' ||
3612 c === ')' ||
3613 c === '<' ||
3614 c === '>'
3615 ) {
3616 break
3617 }
3618 const a = tryParseAssignment(P)
3619 if (a) {
3620 kids.push(a)
3621 continue
3622 }
3623 // Quoted string or concatenation: `export "FOO=bar"`, `export 'X'`
3624 if (c === '"' || c === "'" || c === '$') {
3625 const w = parseWord(P, 'arg')
3626 if (w) {
3627 kids.push(w)
3628 continue
3629 }
3630 break
3631 }
3632 // Flag like -a or bare variable name
3633 const save = saveLex(P.L)
3634 const tok = nextToken(P.L, 'arg')
3635 if (tok.type === 'WORD' || tok.type === 'NUMBER') {
3636 if (tok.value.startsWith('-')) {
3637 kids.push(leaf(P, 'word', tok))
3638 } else if (isIdentStart(tok.value[0] ?? '')) {
3639 kids.push(mk(P, 'variable_name', tok.start, tok.end, []))
3640 } else {
3641 kids.push(leaf(P, 'word', tok))
3642 }
3643 } else {
3644 restoreLex(P.L, save)
3645 break
3646 }
3647 }
3648 const last = kids[kids.length - 1]!
3649 return mk(P, 'declaration_command', kw.startIndex, last.endIndex, kids)
3650}
3651
3652function parseUnset(P: ParseState, kwTok: Token): TsNode {
3653 const kw = leaf(P, 'unset', kwTok)

Callers 1

parseCommandFunction · 0.85

Calls 10

leafFunction · 0.85
skipBlanksFunction · 0.85
tryParseAssignmentFunction · 0.85
parseWordFunction · 0.85
saveLexFunction · 0.85
nextTokenFunction · 0.85
isIdentStartFunction · 0.85
mkFunction · 0.85
restoreLexFunction · 0.85
peekFunction · 0.70

Tested by

no test coverage detected