MCPcopy Index your code
hub / github.com/codeaashu/claude-code / parseFunction

Function parseFunction

src/utils/bash/bashParser.ts:3565–3596  ·  view source on GitHub ↗
(P: ParseState, fnTok: Token)

Source from the content-addressed store, hash-verified

3563}
3564
3565function parseFunction(P: ParseState, fnTok: Token): TsNode {
3566 const fnKw = leaf(P, 'function', fnTok)
3567 skipBlanks(P.L)
3568 const nameTok = nextToken(P.L, 'arg')
3569 const name = mk(P, 'word', nameTok.start, nameTok.end, [])
3570 const kids: TsNode[] = [fnKw, name]
3571 skipBlanks(P.L)
3572 if (peek(P.L) === '(' && peek(P.L, 1) === ')') {
3573 const o = nextToken(P.L, 'cmd')
3574 const c = nextToken(P.L, 'cmd')
3575 kids.push(leaf(P, '(', o))
3576 kids.push(leaf(P, ')', c))
3577 }
3578 skipBlanks(P.L)
3579 skipNewlines(P)
3580 const body = parseCommand(P)
3581 if (body) {
3582 // Hoist redirects from redirected_statement(compound_statement, ...) to
3583 // function_definition level per tree-sitter grammar
3584 if (
3585 body.type === 'redirected_statement' &&
3586 body.children.length >= 2 &&
3587 body.children[0]!.type === 'compound_statement'
3588 ) {
3589 kids.push(...body.children)
3590 } else {
3591 kids.push(body)
3592 }
3593 }
3594 const last = kids[kids.length - 1]!
3595 return mk(P, 'function_definition', fnKw.startIndex, last.endIndex, kids)
3596}
3597
3598function parseDeclaration(P: ParseState, kwTok: Token): TsNode {
3599 const kw = leaf(P, kwTok.value, kwTok)

Callers 1

parseCommandFunction · 0.85

Calls 8

leafFunction · 0.85
skipBlanksFunction · 0.85
nextTokenFunction · 0.85
mkFunction · 0.85
skipNewlinesFunction · 0.85
peekFunction · 0.70
parseCommandFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected