56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
#ifndef idB6D0694FDF6B4902A244C7A51C9727FE
|
|
#define idB6D0694FDF6B4902A244C7A51C9727FE
|
|
|
|
#define BOOST_SPIRIT_USE_PHOENIX_V3
|
|
#include <boost/config/warning_disable.hpp>
|
|
#include <boost/spirit/include/qi.hpp>
|
|
#include <boost/spirit/include/support_istream_iterator.hpp>
|
|
#include <boost/spirit/include/support_line_pos_iterator.hpp>
|
|
#include <boost/spirit/repository/include/qi_iter_pos.hpp>
|
|
#include <boost/spirit/include/support_multi_pass.hpp>
|
|
#include <boost/spirit/include/phoenix.hpp>
|
|
#include <boost/spirit/include/phoenix_stl.hpp>
|
|
|
|
namespace dk { namespace implem {
|
|
struct get_line_f {
|
|
template <typename> struct result { typedef size_t type; };
|
|
template <typename I> size_t operator()(const I& parStart, const I& parPosIter) const {
|
|
return boost::spirit::get_column(parStart, parPosIter) - 1;
|
|
}
|
|
};
|
|
|
|
template <typename I, typename T>
|
|
struct AsciiMapGrammar : boost::spirit::qi::grammar<I, std::vector<T>()> {
|
|
explicit AsciiMapGrammar ( const I& parItStart );
|
|
|
|
boost::spirit::qi::rule<I, std::vector<T>()> start;
|
|
std::vector<int> lengths;
|
|
boost::phoenix::function<get_line_f> getline;
|
|
boost::spirit::qi::int_parser<T, 10, 1, 1> digit_int;
|
|
};
|
|
|
|
template <typename I, typename T>
|
|
AsciiMapGrammar<I, T>::AsciiMapGrammar (const I& parItStart) :
|
|
AsciiMapGrammar::base_type(start)
|
|
{
|
|
using boost::phoenix::push_back;
|
|
using boost::spirit::qi::_1;
|
|
using boost::spirit::qi::eol;
|
|
using boost::spirit::qi::eoi;
|
|
using boost::spirit::qi::raw;
|
|
using boost::phoenix::begin;
|
|
using boost::spirit::qi::int_parser;
|
|
|
|
start %= *digit_int %
|
|
raw[
|
|
eol
|
|
][push_back(boost::phoenix::ref(lengths), getline(boost::phoenix::val(parItStart), begin(_1)))]
|
|
;
|
|
}
|
|
|
|
|
|
}} //namespace dk::implem
|
|
|
|
#undef BOOST_SPIRIT_USE_PHOENIX_V3
|
|
|
|
#endif
|