5_2_3.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_3_HPP
  2. #define BOOST_METAPARSE_GETTING_STARTED_5_2_3_HPP
  3. // Automatically generated header file
  4. // Definitions before section 5.2.2
  5. #include "5_2_2.hpp"
  6. // Definitions of section 5.2.2
  7. using exp_parser8 =
  8. build_parser<
  9. sequence<
  10. int_token, /* parse the first <number> */
  11. transform<
  12. repeated<sequence<plus_token, int_token>>, /* parse the "+ <number>" elements */
  13. /* lambda expression summarising the "+ <number>" elements using fold */
  14. boost::mpl::lambda<
  15. /* The folding expression we have just created */
  16. boost::mpl::fold<
  17. boost::mpl::_1, /* the argument of the lambda expression, the result */
  18. /* of the repeated<...> parser */
  19. boost::mpl::int_<0>,
  20. boost::mpl::quote2<sum_items>
  21. >
  22. >::type
  23. >
  24. >
  25. >;
  26. // query:
  27. // exp_parser8::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type
  28. using exp_parser9 =
  29. build_parser<
  30. transform<
  31. /* What we had so far */
  32. sequence<
  33. int_token,
  34. transform<
  35. repeated<sequence<plus_token, int_token>>,
  36. boost::mpl::lambda<
  37. boost::mpl::fold<
  38. boost::mpl::_1,
  39. boost::mpl::int_<0>,
  40. boost::mpl::quote2<sum_items>
  41. >
  42. >::type
  43. >
  44. >,
  45. boost::mpl::quote1<sum_vector> /* summarise the vector of numbers */
  46. >
  47. >;
  48. // query:
  49. // exp_parser9::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type
  50. #endif