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

Function parseFunction

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

Source from the content-addressed store, hash-verified

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

Callers 1

parseCommandFunction · 0.85

Calls 8

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

Tested by

no test coverage detected