MCPcopy Index your code
hub / github.com/liuup/claude-code-analysis / parseDeclaration

Function parseDeclaration

src/utils/bash/bashParser.ts:3598–3648  ·  view source on GitHub ↗
(P: ParseState, kwTok: Token)

Source from the content-addressed store, hash-verified

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