before_5_2_1.qbk 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [#before_5_2_1]
  2. ['Definitions before section 5.2.1.]
  3. #include <boost/metaparse/string.hpp>
  4. #include <boost/metaparse/int_.hpp>
  5. #include <boost/metaparse/build_parser.hpp>
  6. using namespace boost::metaparse;
  7. using exp_parser1 = build_parser<int_>;
  8. #include <boost/metaparse/entire_input.hpp>
  9. using exp_parser2 = build_parser<entire_input<int_>>;
  10. #include <boost/metaparse/token.hpp>
  11. using exp_parser3 = build_parser<entire_input<token<int_>>>;
  12. #include <boost/metaparse/lit_c.hpp>
  13. #include <boost/metaparse/sequence.hpp>
  14. using exp_parser4 = build_parser<sequence<token<int_>, token<lit_c<'+'>>, token<int_>>>;
  15. #include <metashell/formatter.hpp>
  16. using int_token = token<int_>;
  17. using plus_token = token<lit_c<'+'>>;
  18. using exp_parser5 = build_parser<sequence<int_token, plus_token, int_token>>;
  19. #include <boost/metaparse/transform.hpp>
  20. #include <boost/mpl/plus.hpp>
  21. #include <boost/mpl/at.hpp>
  22. template <class Vector>
  23. struct eval_plus :
  24. boost::mpl::plus<
  25. typename boost::mpl::at_c<Vector, 0>::type,
  26. typename boost::mpl::at_c<Vector, 2>::type
  27. > {};
  28. #include <boost/mpl/quote.hpp>
  29. using exp_parser6 =
  30. build_parser<
  31. transform<
  32. sequence<int_token, plus_token, int_token>,
  33. boost::mpl::quote1<eval_plus>
  34. >
  35. >;
  36. #include <boost/metaparse/any.hpp>
  37. using exp_parser7 =
  38. build_parser<
  39. sequence<
  40. int_token, /* The first <number> */
  41. repeated<sequence<plus_token, int_token>> /* The "+ <number>" elements */
  42. >
  43. >;
  44. using temp_result = exp_parser7::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type;