| 1 | 
 | 
|---|
| 2 | #include <boost/config/warning_disable.hpp>
 | 
|---|
| 3 | #include <boost/spirit/include/qi.hpp>
 | 
|---|
| 4 | #include <boost/spirit/include/phoenix_core.hpp>
 | 
|---|
| 5 | #include <boost/spirit/include/phoenix_operator.hpp>
 | 
|---|
| 6 | #include <boost/spirit/include/phoenix_object.hpp>
 | 
|---|
| 7 | #include <boost/fusion/include/adapt_struct.hpp>
 | 
|---|
| 8 | #include <boost/fusion/include/io.hpp>
 | 
|---|
| 9 | #include <boost/fusion/include/begin.hpp>
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #include <iostream>
 | 
|---|
| 12 | #include <string>
 | 
|---|
| 13 | #include <complex>
 | 
|---|
| 14 | 
 | 
|---|
| 15 | namespace qi = boost::spirit::qi;
 | 
|---|
| 16 | namespace ascii = boost::spirit::ascii;
 | 
|---|
| 17 | 
 | 
|---|
| 18 | class Foo
 | 
|---|
| 19 | {
 | 
|---|
| 20 | public:
 | 
|---|
| 21 |     Foo() {}
 | 
|---|
| 22 |     Foo(unsigned, unsigned) {}
 | 
|---|
| 23 |     Foo(const boost::fusion::vector<unsigned, unsigned> & v) {}
 | 
|---|
| 24 |     unsigned a;
 | 
|---|
| 25 |     unsigned b;
 | 
|---|
| 26 | };
 | 
|---|
| 27 | 
 | 
|---|
| 28 | // Fails to build without the latter
 | 
|---|
| 29 | #if 0
 | 
|---|
| 30 | BOOST_FUSION_ADAPT_STRUCT(
 | 
|---|
| 31 |     Foo,
 | 
|---|
| 32 |     (unsigned, a)
 | 
|---|
| 33 |     (unsigned, b)
 | 
|---|
| 34 | )
 | 
|---|
| 35 | #endif
 | 
|---|
| 36 | 
 | 
|---|
| 37 | template <typename Iterator>
 | 
|---|
| 38 | struct FooParser : qi::grammar<Iterator, std::vector<Foo>(), ascii::space_type>
 | 
|---|
| 39 | {
 | 
|---|
| 40 |     qi::rule<Iterator, Foo(), ascii::space_type> foo;
 | 
|---|
| 41 |     qi::rule<Iterator, Foo(), ascii::space_type> foo_workaround;
 | 
|---|
| 42 | 
 | 
|---|
| 43 |     qi::rule<Iterator, std::vector<Foo>(), ascii::space_type> start;
 | 
|---|
| 44 | 
 | 
|---|
| 45 |     FooParser() : FooParser::base_type(start)
 | 
|---|
| 46 |     {
 | 
|---|
| 47 |         using qi::hex;
 | 
|---|
| 48 | 
 | 
|---|
| 49 |         foo_workaround = hex >> "," >> hex;
 | 
|---|
| 50 |         foo %= foo_workaround.alias();
 | 
|---|
| 51 |         start %= *foo;
 | 
|---|
| 52 |     }
 | 
|---|
| 53 | };
 | 
|---|
| 54 | 
 | 
|---|
| 55 | int main()
 | 
|---|
| 56 | {
 | 
|---|
| 57 |     std::string s;
 | 
|---|
| 58 | 
 | 
|---|
| 59 |     using boost::spirit::ascii::space;
 | 
|---|
| 60 |     FooParser<std::string::const_iterator> g;
 | 
|---|
| 61 | 
 | 
|---|
| 62 |     std::vector<Foo> data;
 | 
|---|
| 63 |     std::string::const_iterator iter = s.begin();
 | 
|---|
| 64 |     std::string::const_iterator end = s.end();
 | 
|---|
| 65 |     bool r = phrase_parse(iter, end, g, space, data);
 | 
|---|
| 66 | 
 | 
|---|
| 67 |     return 0;
 | 
|---|
| 68 | }
 | 
|---|