| 977 | } |
| 978 | |
| 979 | common_peg_parser common_peg_parser_builder::choice(const std::vector<common_peg_parser_id> & parsers) { |
| 980 | // Flatten nested choices |
| 981 | std::vector<common_peg_parser_id> flattened; |
| 982 | for (const auto & p : parsers) { |
| 983 | const auto & parser = arena_.get(p); |
| 984 | if (auto choice = std::get_if<common_peg_choice_parser>(&parser)) { |
| 985 | flattened.insert(flattened.end(), choice->children.begin(), choice->children.end()); |
| 986 | } else { |
| 987 | flattened.push_back(p); |
| 988 | } |
| 989 | } |
| 990 | return wrap(arena_.add_parser(common_peg_choice_parser{flattened})); |
| 991 | } |
| 992 | |
| 993 | common_peg_parser common_peg_parser_builder::choice(const std::vector<common_peg_parser> & parsers) { |
| 994 | std::vector<common_peg_parser_id> ids; |