TODO: 把手动解构做成自动解构,或者根据原始语法自动生成类 if exp then block { elseif exp then block } [ else block ] end */
| 1185 | end |
| 1186 | */ |
| 1187 | MatchResult *ParserContext::make_if_ast_node(ParserFunctor *pf, MatchResult *mr) |
| 1188 | { |
| 1189 | std::vector<GluaConditionNodeInfo> condition_node_infos; |
| 1190 | MatchResult *else_block_mr = nullptr; |
| 1191 | assert(mr->is_complex()); |
| 1192 | auto cmr = mr->as_complex(); |
| 1193 | assert(cmr->size() >= 5); |
| 1194 | condition_node_infos.push_back(std::make_pair(cmr->get_item(1), cmr->get_item(3))); |
| 1195 | for(size_t cur_pos=4;cur_pos<cmr->size()-1;++cur_pos) |
| 1196 | { |
| 1197 | MatchResult *cur_mr = cmr->get_item(cur_pos); |
| 1198 | auto head_token = cur_mr->head_token().token; |
| 1199 | if(head_token == "elseif") |
| 1200 | { |
| 1201 | assert(cur_mr->is_complex() && cur_mr->as_complex()->size()>=4); |
| 1202 | auto cur_cmr = cur_mr->as_complex(); |
| 1203 | condition_node_infos.push_back(std::make_pair(cur_cmr->get_item(1), cur_cmr->get_item(3))); |
| 1204 | } |
| 1205 | else if(head_token == "else") |
| 1206 | { |
| 1207 | else_block_mr = cmr->get_item(cur_pos+1); |
| 1208 | break; |
| 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | // end |
| 1213 | break; |
| 1214 | } |
| 1215 | } |
| 1216 | auto *node = new GluaIfStatNode(mr, condition_node_infos, else_block_mr); |
| 1217 | node->set_node_name("if_stat"); |
| 1218 | add_match_result(node); |
| 1219 | return node; |
| 1220 | } |
| 1221 | |
| 1222 | ParserFunctor *ParserContext::generate_glua_parser() |
| 1223 | { |
no test coverage detected