Skip to content

Instantly share code, notes, and snippets.

@Bloodb0ne
Created March 20, 2020 12:54
Show Gist options
  • Save Bloodb0ne/55723e99ded151b8482448657e7bbf50 to your computer and use it in GitHub Desktop.
Save Bloodb0ne/55723e99ded151b8482448657e7bbf50 to your computer and use it in GitHub Desktop.
Parser Combinators Example
template<typename Parser>
struct Many {
using is_parser_type = std::true_type;
using return_type = typename std::vector<typename Parser::return_type>;
using temp_result_type = typename Parser::return_type;
Parser const p;
Many(Parser const& p_) :p(p_) {};
//CAN REPEAT 0 Times
template<typename Iterator>
bool operator()(Iterator& it, Iterator end, return_type* result) const {
Iterator backtrack = it;
size_t cnt = 0;
temp_result_type tmpres;
while (p(it, end, &tmpres)) {
result->push_back(tmpres);
backtrack = it;
++cnt;
}
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment