#include #include #include #include #include #include #include #include #include #include #include struct test { boost::uint8_t a; }; BOOST_FUSION_ADAPT_STRUCT ( test, (boost::uint8_t, a) ) template struct test_generator: boost::spirit::karma::grammar { test_generator(): test_generator::base_type(start) { using boost::spirit::byte_; using boost::spirit::big_dword; start = ( big_dword(666) << byte_(6) ) ; } boost::spirit::karma::rule start; }; template struct test_parser: boost::spirit::qi::grammar { test_parser(): test_parser::base_type(start) { using boost::spirit::byte_; using boost::spirit::big_dword; using boost::spirit::omit; using boost::phoenix::ref; using boost::spirit::_1; start = ( //omit[big_dword[std::cout << _1 << std::endl]] >> byte_ // Works. big_dword[std::cout << _1 << std::endl] >> byte_ // Doesn't. ) ; } boost::spirit::qi::rule start; }; int main() { std::ofstream out("test.bin", std::ios::binary | std::ios::trunc); if(!out) { std::cerr << "Failed to open output file\n"; return 1; } typedef std::ostream_iterator iterator; typedef test_generator test_generator; test_generator bg; iterator it(out); bool result = boost::spirit::karma::generate(it, bg); out.close(); if(!result) { std::cerr << "Failed to generate\n"; return 1; } std::ifstream in("test.bin", std::ios::binary); if(!in) { std::cerr << "Failed to open input file\n"; return 1; } namespace spirit = boost::spirit; typedef std::istreambuf_iterator base_iterator_type; spirit::multi_pass first = spirit::make_default_multi_pass(base_iterator_type(in)); spirit::multi_pass last = spirit::make_default_multi_pass(base_iterator_type()); typedef test_parser > test_parser; test_parser bp; test t; bool result2 = parse(first, last, bp, t); in.close(); if(!result2 || first != last) { std::cerr << "Failed to parse\n"; return 1; } assert(t.a == 6); return 0; }