#ifndef CHILON_PARSER_CHOICE_HPP
#define CHILON_PARSER_CHOICE_HPP
#include <chilon/parser/parse.hpp>
#include <chilon/parser/detail/choice.hpp>
#include <chilon/meta/flatten.hpp>
namespace chilon { namespace parser {
/**
* Ordered choice (| in grammar)
*/
template <class... Matches>
struct choice;
template <>
struct choice<> {
template <class Stream>
inline static bool skip(Stream& stream) {
return false;
}
template <class Stream>
inline static bool match(Stream const& stream) {
return false;
}
};
template <class Head, class... Tail>
struct choice<Head, Tail...>
: parse_base<detail::parse_choice<Head, Tail...>>
{
template <class Stream>
inline static bool skip(Stream& stream) {
return Head::skip(stream) || choice<Tail...>::skip(stream);
}
template <class Stream>
inline static bool match(Stream const& stream) {
return Head::match(stream) || choice<Tail...>::match(stream);
}
};
template <class... T>
struct parse<detail::parse_choice<T...>> : detail::parse_choice<T...> {};
} }
#endif