Created
March 20, 2020 12:54
-
-
Save Bloodb0ne/55723e99ded151b8482448657e7bbf50 to your computer and use it in GitHub Desktop.
Parser Combinators Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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