fork(1) download
  1. // spirit-test.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <string>
  5. #include <iostream>
  6. #include <boost/bind.hpp>
  7. #include <boost/spirit/include/qi.hpp>
  8. #include <boost/iterator/iterator_facade.hpp>
  9. #include <boost/spirit/include/support_ascii.hpp>
  10.  
  11.  
  12. namespace qi = boost::spirit::qi;
  13. namespace fusion = boost::fusion;
  14. namespace phoenix = boost::phoenix;
  15.  
  16. void getstr(std::string& str)
  17. {
  18. std::cout << str;
  19. return ;
  20. }
  21.  
  22. template <typename Iterator >
  23. bool parse (Iterator begin, Iterator end)
  24. {
  25. using qi::lexeme;
  26. using qi::char_;
  27. using qi::lit;
  28. using qi::rule;
  29. using qi::space;
  30. using boost::spirit::no_skip;
  31. using boost::spirit::ascii::space_type;
  32.  
  33.  
  34.  
  35. rule<Iterator> Sequence;
  36. rule<Iterator, std::string()> KeyName, Value, ValueExpression;
  37.  
  38.  
  39. KeyName
  40. %= no_skip[+char_("a-zA-Z0-9_") >> lit("=")]
  41. ;
  42.  
  43. Value
  44. %= +(char_ - char_("{="))
  45. ;
  46.  
  47. ValueExpression
  48. %= (
  49. Value
  50. >> *space
  51. >> &(KeyName | lit("{"))
  52. )
  53. ;
  54.  
  55. Sequence
  56. =
  57. +( KeyName[boost::bind(&getstr, _1)]
  58. >> ValueExpression[boost::bind(&getstr, _1)]
  59. )
  60. ;
  61.  
  62. bool r = qi::phrase_parse(begin, end, Sequence, space);
  63. if (!r || begin != end) { return false; }
  64. else return true;
  65. }
  66.  
  67. int main ()
  68. {
  69. std::string test(" ARG=Test still in first ARG ARG2=Zombie cat EXP2=FunctionCall(A, B C) {" );
  70. bool status = parse<std::string::const_iterator> (test.begin(), test.end());
  71. return 0;
  72. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty