| 1187 | } |
| 1188 | |
| 1189 | common_peg_parser common_peg_parser_builder::choice(const std::vector<common_peg_parser_id> & parsers) { |
| 1190 | // Flatten nested choices |
| 1191 | std::vector<common_peg_parser_id> flattened; |
| 1192 | for (const auto & p : parsers) { |
| 1193 | const auto & parser = arena_.get(p); |
| 1194 | if (auto choice = std::get_if<common_peg_choice_parser>(&parser)) { |
| 1195 | flattened.insert(flattened.end(), choice->children.begin(), choice->children.end()); |
| 1196 | } else { |
| 1197 | flattened.push_back(p); |
| 1198 | } |
| 1199 | } |
| 1200 | return wrap(arena_.add_parser(common_peg_choice_parser{flattened})); |
| 1201 | } |
| 1202 | |
| 1203 | common_peg_parser common_peg_parser_builder::choice(const std::vector<common_peg_parser> & parsers) { |
| 1204 | std::vector<common_peg_parser_id> ids; |