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

Function parseFor

source code/utils/bash/bashParser.ts:3202–3306  ·  view source on GitHub ↗
(P: ParseState, forTok: Token)

Source from the content-addressed store, hash-verified

3200}
3201
3202function parseFor(P: ParseState, forTok: Token): TsNode {
3203 const forKw = leaf(P, forTok.value, forTok)
3204 skipBlanks(P.L)
3205 // C-style for (( ; ; )) — only for `for`, not `select`
3206 if (forTok.value === 'for' && peek(P.L) === '(' && peek(P.L, 1) === '(') {
3207 const oStart = P.L.b
3208 advance(P.L)
3209 advance(P.L)
3210 const open = mk(P, '((', oStart, P.L.b, [])
3211 const kids: TsNode[] = [forKw, open]
3212 // init; cond; update — all three use 'assign' mode so `c = expr` emits
3213 // variable_assignment, while bare idents (c in `c<=5`) → word. Each
3214 // clause may be a comma-separated list.
3215 for (let k = 0; k < 3; k++) {
3216 skipBlanks(P.L)
3217 const es = parseArithCommaList(P, k < 2 ? ';' : '))', 'assign')
3218 kids.push(...es)
3219 if (k < 2) {
3220 if (peek(P.L) === ';') {
3221 const s = P.L.b
3222 advance(P.L)
3223 kids.push(mk(P, ';', s, P.L.b, []))
3224 }
3225 }
3226 }
3227 skipBlanks(P.L)
3228 if (peek(P.L) === ')' && peek(P.L, 1) === ')') {
3229 const cStart = P.L.b
3230 advance(P.L)
3231 advance(P.L)
3232 kids.push(mk(P, '))', cStart, P.L.b, []))
3233 }
3234 // Optional ; or newline
3235 const save = saveLex(P.L)
3236 const sep = nextToken(P.L, 'cmd')
3237 if (sep.type === 'OP' && sep.value === ';') {
3238 kids.push(leaf(P, ';', sep))
3239 } else if (sep.type !== 'NEWLINE') {
3240 restoreLex(P.L, save)
3241 }
3242 const dg = parseDoGroup(P)
3243 if (dg) {
3244 kids.push(dg)
3245 } else {
3246 // C-style for can also use `{ ... }` body instead of `do ... done`
3247 skipNewlines(P)
3248 skipBlanks(P.L)
3249 if (peek(P.L) === '{') {
3250 const bOpen = P.L.b
3251 advance(P.L)
3252 const brace = mk(P, '{', bOpen, P.L.b, [])
3253 const body = parseStatements(P, '}')
3254 let bClose: TsNode
3255 if (peek(P.L) === '}') {
3256 const cs = P.L.b
3257 advance(P.L)
3258 bClose = mk(P, '}', cs, P.L.b, [])
3259 } else {

Callers 1

parseCommandFunction · 0.85

Calls 13

leafFunction · 0.85
skipBlanksFunction · 0.85
advanceFunction · 0.85
mkFunction · 0.85
parseArithCommaListFunction · 0.85
saveLexFunction · 0.85
nextTokenFunction · 0.85
restoreLexFunction · 0.85
parseDoGroupFunction · 0.85
skipNewlinesFunction · 0.85
parseStatementsFunction · 0.85
parseWordFunction · 0.85

Tested by

no test coverage detected