| 1 |
|
|---|
| 2 | #include <boost/fusion/adapted.hpp>
|
|---|
| 3 | #include <boost/fusion/container/vector.hpp>
|
|---|
| 4 |
|
|---|
| 5 | #include <boost/spirit/home/qi.hpp>
|
|---|
| 6 |
|
|---|
| 7 | #include <iostream>
|
|---|
| 8 |
|
|---|
| 9 | namespace qi = boost::spirit::qi;
|
|---|
| 10 |
|
|---|
| 11 | struct test
|
|---|
| 12 | {
|
|---|
| 13 | int a;
|
|---|
| 14 | char b;
|
|---|
| 15 | };
|
|---|
| 16 |
|
|---|
| 17 | BOOST_FUSION_ADAPT_STRUCT(
|
|---|
| 18 | test
|
|---|
| 19 | , (int, a)
|
|---|
| 20 | (char, b)
|
|---|
| 21 | )
|
|---|
| 22 |
|
|---|
| 23 | template <typename P, typename T>
|
|---|
| 24 | void test_parser_attr(
|
|---|
| 25 | char const* input, P const& p, T& attr, bool full_match = true)
|
|---|
| 26 | {
|
|---|
| 27 | using boost::spirit::qi::parse;
|
|---|
| 28 |
|
|---|
| 29 | char const* f(input);
|
|---|
| 30 | char const* l(f + strlen(f));
|
|---|
| 31 | if (parse(f, l, p, attr) && (!full_match || (f == l)))
|
|---|
| 32 | std::cout << "ok" << std::endl;
|
|---|
| 33 | else
|
|---|
| 34 | std::cout << "fail" << std::endl;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | int main( int argc, char** argv )
|
|---|
| 38 | {
|
|---|
| 39 | boost::fusion::vector< int, char > ft;
|
|---|
| 40 | test_parser_attr( "64c128.0", qi::int_ > qi::char_ > qi::float_, ft );
|
|---|
| 41 |
|
|---|
| 42 | test st;
|
|---|
| 43 | test_parser_attr( "64c128.0", qi::int_ > qi::char_ > qi::float_, st );
|
|---|
| 44 | test_parser_attr( "64c128.0", qi::as< test >()[ qi::int_ > qi::char_ > qi::float_ ], st );
|
|---|
| 45 |
|
|---|
| 46 | return 0;
|
|---|
| 47 | }
|
|---|