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

Function parseIf

source code/utils/bash/bashParser.ts:3154–3189  ·  view source on GitHub ↗
(P: ParseState, ifTok: Token)

Source from the content-addressed store, hash-verified

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

Callers 1

parseCommandFunction · 0.85

Calls 7

leafFunction · 0.85
parseStatementsFunction · 0.85
consumeKeywordFunction · 0.85
saveLexFunction · 0.85
nextTokenFunction · 0.85
mkFunction · 0.85
restoreLexFunction · 0.85

Tested by

no test coverage detected