(P: ParseState, ifTok: Token)
| 3146 | } |
| 3147 | |
| 3148 | function 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 | |
| 3185 | function parseWhile(P: ParseState, kwTok: Token): TsNode { |
| 3186 | const kw = leaf(P, kwTok.value, kwTok) |
no test coverage detected