123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- [#before_6_2]
- ['Definitions before section 6.2.]
- #include <boost/metaparse/string.hpp>
- #include <boost/metaparse/int_.hpp>
- #include <boost/metaparse/build_parser.hpp>
- using namespace boost::metaparse;
- using exp_parser1 = build_parser<int_>;
- #include <boost/metaparse/entire_input.hpp>
- using exp_parser2 = build_parser<entire_input<int_>>;
- #include <boost/metaparse/token.hpp>
- using exp_parser3 = build_parser<entire_input<token<int_>>>;
- #include <boost/metaparse/lit_c.hpp>
- #include <boost/metaparse/sequence.hpp>
- using exp_parser4 = build_parser<sequence<token<int_>, token<lit_c<'+'>>, token<int_>>>;
- #include <metashell/formatter.hpp>
-
- using int_token = token<int_>;
- using plus_token = token<lit_c<'+'>>;
- using exp_parser5 = build_parser<sequence<int_token, plus_token, int_token>>;
- #include <boost/metaparse/transform.hpp>
- #include <boost/mpl/plus.hpp>
- #include <boost/mpl/at.hpp>
- template <class Vector>
- struct eval_plus :
- boost::mpl::plus<
- typename boost::mpl::at_c<Vector, 0>::type,
- typename boost::mpl::at_c<Vector, 2>::type
- > {};
- #include <boost/mpl/quote.hpp>
- using exp_parser6 =
- build_parser<
- transform<
- sequence<int_token, plus_token, int_token>,
- boost::mpl::quote1<eval_plus>
- >
- >;
- #include <boost/metaparse/any.hpp>
- using exp_parser7 =
- build_parser<
- sequence<
- int_token, /* The first <number> */
- repeated<sequence<plus_token, int_token>> /* The "+ <number>" elements */
- >
- >;
- using temp_result = exp_parser7::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type;
- #include <boost/mpl/fold.hpp>
- using vector_of_numbers =
- boost::mpl::vector<
- boost::mpl::int_<2>,
- boost::mpl::int_<5>,
- boost::mpl::int_<6>
- >;
- template <class Vector>
- struct sum_vector :
- boost::mpl::fold<
- Vector,
- boost::mpl::int_<0>,
- boost::mpl::lambda<
- boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>
- >::type
- >
- {};
- template <class Sum, class Item>
- struct sum_items :
- boost::mpl::plus<
- Sum,
- typename boost::mpl::at_c<Item, 1>::type
- >
- {};
- using exp_parser8 =
- build_parser<
- sequence<
- int_token, /* parse the first <number> */
- transform<
- repeated<sequence<plus_token, int_token>>, /* parse the "+ <number>" elements */
- /* lambda expression summarising the "+ <number>" elements using fold */
- boost::mpl::lambda<
- /* The folding expression we have just created */
- boost::mpl::fold<
- boost::mpl::_1, /* the argument of the lambda expression, the result */
- /* of the repeated<...> parser */
- boost::mpl::int_<0>,
- boost::mpl::quote2<sum_items>
- >
- >::type
- >
- >
- >;
- using exp_parser9 =
- build_parser<
- transform<
- /* What we had so far */
- sequence<
- int_token,
- transform<
- repeated<sequence<plus_token, int_token>>,
- boost::mpl::lambda<
- boost::mpl::fold<
- boost::mpl::_1,
- boost::mpl::int_<0>,
- boost::mpl::quote2<sum_items>
- >
- >::type
- >
- >,
- boost::mpl::quote1<sum_vector> /* summarise the vector of numbers */
- >
- >;
- #include <boost/metaparse/foldl.hpp>
- using exp_parser10 =
- build_parser<
- transform<
- sequence<
- int_token,
- foldl<
- sequence<plus_token, int_token>,
- boost::mpl::int_<0>,
- boost::mpl::quote2<sum_items>
- >
- >,
- boost::mpl::quote1<sum_vector>>
- >;
- #include <boost/metaparse/foldl_start_with_parser.hpp>
- using exp_parser11 =
- build_parser<
- foldl_start_with_parser<
- sequence<plus_token, int_token>, /* apply this parser repeatedly */
- int_token, /* use this parser to get the initial value */
- boost::mpl::quote2<sum_items> /* use this function to add a new value to the summary */
- >
- >;
- using minus_token = token<lit_c<'-'>>;
- #include <boost/metaparse/one_of.hpp>
- using exp_parser12 =
- build_parser<
- foldl_start_with_parser<
- sequence<one_of<plus_token, minus_token>, int_token>,
- int_token,
- boost::mpl::quote2<sum_items>
- >
- >;
|