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