2024-07
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <boost/spirit/home/qi.hpp>
|
||||
#include <boost/fusion/include/boost_tuple.hpp>
|
||||
|
||||
namespace aocpp {
|
||||
|
||||
@@ -46,6 +47,20 @@ auto ParseGrammar_(G const& grammar, std::istream & in) -> typename G::start_typ
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename P, typename R>
|
||||
auto ParseSimple(std::istream& in, P p, R & result) -> void
|
||||
{
|
||||
namespace qi = boost::spirit::qi;
|
||||
auto const content = std::string{std::istreambuf_iterator{in}, {}};
|
||||
qi::rule<std::string::const_iterator, R()> r { std::move(p) };
|
||||
auto it = content.begin();
|
||||
auto const end = content.end();
|
||||
bool success = qi::parse(it, end, r, result);
|
||||
if (!success || it != end) {
|
||||
throw std::runtime_error("Parsing failed or input was not fully consumed.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user