MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / parseIf

Function parseIf

src/utils/bash/bashParser.ts:3148–3183  ·  view source on GitHub ↗
(P: ParseState, ifTok: Token)

Source from the content-addressed store, hash-verified

3146}
3147
3148function parseIf(P: ParseState, ifTok: Token): TsNode {
3149 const ifKw = leaf(P, 'if', ifTok)
3150 const kids: TsNode[] = [ifKw]
3151 const cond = parseStatements(P, null)
3152 kids.push(...cond)
3153 consumeKeyword(P, 'then', kids)
3154 const body = parseStatements(P, null)
3155 kids.push(...body)
3156 while (true) {
3157 const save = saveLex(P.L)
3158 const t = nextToken(P.L, 'cmd')
3159 if (t.type === 'WORD' && t.value === 'elif') {
3160 const eKw = leaf(P, 'elif', t)
3161 const eCond = parseStatements(P, null)
3162 const eKids: TsNode[] = [eKw, ...eCond]
3163 consumeKeyword(P, 'then', eKids)
3164 const eBody = parseStatements(P, null)
3165 eKids.push(...eBody)
3166 const last = eKids[eKids.length - 1]!
3167 kids.push(mk(P, 'elif_clause', eKw.startIndex, last.endIndex, eKids))
3168 } else if (t.type === 'WORD' && t.value === 'else') {
3169 const elKw = leaf(P, 'else', t)
3170 const elBody = parseStatements(P, null)
3171 const last = elBody.length > 0 ? elBody[elBody.length - 1]! : elKw
3172 kids.push(
3173 mk(P, 'else_clause', elKw.startIndex, last.endIndex, [elKw, ...elBody]),
3174 )
3175 } else {
3176 restoreLex(P.L, save)
3177 break
3178 }
3179 }
3180 consumeKeyword(P, 'fi', kids)
3181 const last = kids[kids.length - 1]!
3182 return mk(P, 'if_statement', ifKw.startIndex, last.endIndex, kids)
3183}
3184
3185function parseWhile(P: ParseState, kwTok: Token): TsNode {
3186 const kw = leaf(P, kwTok.value, kwTok)

Callers 1

parseCommandFunction · 0.85

Calls 8

leafFunction · 0.85
parseStatementsFunction · 0.85
consumeKeywordFunction · 0.85
saveLexFunction · 0.85
nextTokenFunction · 0.85
restoreLexFunction · 0.85
mkFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected