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

Function parseFunction

source code/utils/bash/bashParser.ts:3567–3598  ·  view source on GitHub ↗
(P: ParseState, fnTok: Token)

Source from the content-addressed store, hash-verified

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

Callers 1

parseCommandFunction · 0.85

Calls 7

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

Tested by

no test coverage detected