Created
March 20, 2020 12:22
-
-
Save Bloodb0ne/1f3c777466008795b2ecaa41874499db to your computer and use it in GitHub Desktop.
Parser Combinator Examples
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 ...Parsers> | |
struct Seq { | |
using is_parser_type = std::true_type; | |
using return_type = typename std::tuple<typename Parsers::return_type...>; | |
using container_type = typename std::tuple<Parsers...>; | |
container_type const parsers; | |
explicit constexpr Seq(Parsers const& ...p) :parsers(p...) {}; | |
template<typename Iterator> | |
bool operator()(Iterator& it, Iterator end, return_type* result) const{ | |
return_type tmp; | |
Iterator backtrack = it; | |
bool res = std::apply(all_applicator_res<Iterator, return_type, Parsers...>, parsers)(it, end, tmp); | |
if (res) { | |
*result = tmp; | |
} | |
else { | |
it = backtrack; | |
} | |
return res; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment