fork download
  1. // #define BOOST_SPIRIT_DEBUG
  2. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  3. #define BOOST_RESULT_OF_USE_DECLTYPE
  4. #endif
  5. #include <boost/fusion/adapted.hpp>
  6. // #include <boost/optional.hpp>
  7. // #include <boost/variant.hpp>
  8. // #include <boost/variant/recursive_wrapper.hpp>
  9. #include <boost/spirit/include/qi.hpp>
  10. #include <boost/spirit/include/karma.hpp>
  11. // #include <boost/spirit/include/phoenix.hpp>
  12. // #include <boost/spirit/include/phoenix_operator.hpp>
  13.  
  14. namespace qi = boost::spirit::qi;
  15. namespace karma = boost::spirit::karma;
  16. namespace phx = boost::phoenix;
  17.  
  18. typedef std::string attr_t;
  19.  
  20. template <typename It, typename Skipper = qi::space_type>
  21. struct parser : qi::grammar<It, attr_t(), Skipper>
  22. {
  23. parser() : parser::base_type(start)
  24. {
  25. using namespace qi;
  26. // using phx::bind; using phx::ref; using phx::val;
  27.  
  28. start %= eps;
  29. BOOST_SPIRIT_DEBUG_NODE(start);
  30. }
  31.  
  32. private:
  33. qi::rule<It, attr_t(), Skipper> start;
  34. };
  35.  
  36. template <typename C, typename Skipper>
  37. bool doParse(const C& input, const Skipper& skipper)
  38. {
  39. auto f(std::begin(input)), l(std::end(input));
  40.  
  41. parser<decltype(f), Skipper> p;
  42. attr_t data;
  43. bool ok = qi::phrase_parse(f,l,p,skipper,data);
  44.  
  45. try
  46. {
  47. if (ok)
  48. {
  49. std::cout << "parse success\n";
  50. std::cout << "data: " << karma::format_delimited(karma::auto_, ' ', data) << "\n";
  51. }
  52. else std::cerr << "parse failed: '" << std::string(f,l) << "'\n";
  53.  
  54. if (f!=l) std::cerr << "trailing unparsed: '" << std::string(f,l) << "'\n";
  55. return ok;
  56. } catch(const qi::expectation_failure<decltype(f)>& e)
  57. {
  58. std::string frag(e.first, e.last);
  59. std::cerr << e.what() << "'" << frag << "'\n";
  60. }
  61.  
  62. return false;
  63. }
  64.  
  65. template <typename C>
  66. bool doParse(const C& input)
  67. {
  68. return doParse(input, qi::space);
  69. }
  70.  
  71.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:36: fatal error: boost/fusion/adapted.hpp: No such file or directory
compilation terminated.
stdout
Standard output is empty