Skip to content

Instantly share code, notes, and snippets.

@Bloodb0ne
Created March 20, 2020 12:22
Show Gist options
  • Save Bloodb0ne/1f3c777466008795b2ecaa41874499db to your computer and use it in GitHub Desktop.
Save Bloodb0ne/1f3c777466008795b2ecaa41874499db to your computer and use it in GitHub Desktop.
Parser Combinator Examples
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