Home | Libraries | People | FAQ | More |
#include <boost/metaparse/string.hpp>
Definitions before section 3.1.
#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_>;
Definitions before section 3.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_>;
Definitions before section 3.3.
#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/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_>>>;
Definitions before section 4.1.
#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>
Definitions before section 4.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/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> > >;
Definitions before section 5.1.
#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> > >;
Definitions before section 5.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 */ > >;
Definitions before section 5.2.1.
#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;
Definitions before section 5.2.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 > {};
Definitions before section 5.2.3.
#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 */ > >;
Definitions before section 5.2.4.
#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/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 */ > >;
Definitions before section 6.1.
#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 */ > >;
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> > >;
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >;
Definitions before section 7.1.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >;
Definitions before section 7.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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >;
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >;
Definitions before section 8.1.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >;
Definitions before section 8.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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >;
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >;
Definitions before section 10.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >;
Definitions before section 11.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >; using lparen_token = token<lit_c<'('>>; using rparen_token = token<lit_c<')'>>; using plus_exp1 = foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> >; using paren_exp1 = sequence<lparen_token, plus_exp1, rparen_token>; #include <boost/metaparse/middle_of.hpp> using paren_exp2 = middle_of<lparen_token, plus_exp1, rparen_token>; using primary_exp1 = one_of<int_token, paren_exp2>; struct plus_exp2; using paren_exp3 = middle_of<lparen_token, plus_exp2, rparen_token>; using primary_exp2 = one_of<int_token, paren_exp2>; using unary_exp2 = foldr_start_with_parser< minus_token, primary_exp2, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp5 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp2>, unary_exp2, boost::mpl::quote2<binary_op> >; struct plus_exp2 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp5>, mult_exp5, boost::mpl::quote2<binary_op> > {}; using exp_parser19 = build_parser<plus_exp2>;
Definitions before section 11.1.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >; using lparen_token = token<lit_c<'('>>; using rparen_token = token<lit_c<')'>>; using plus_exp1 = foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> >; using paren_exp1 = sequence<lparen_token, plus_exp1, rparen_token>; #include <boost/metaparse/middle_of.hpp> using paren_exp2 = middle_of<lparen_token, plus_exp1, rparen_token>; using primary_exp1 = one_of<int_token, paren_exp2>; struct plus_exp2; using paren_exp3 = middle_of<lparen_token, plus_exp2, rparen_token>; using primary_exp2 = one_of<int_token, paren_exp2>; using unary_exp2 = foldr_start_with_parser< minus_token, primary_exp2, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp5 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp2>, unary_exp2, boost::mpl::quote2<binary_op> >; struct plus_exp2 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp5>, mult_exp5, boost::mpl::quote2<binary_op> > {}; using exp_parser19 = build_parser<plus_exp2>;
Definitions before section 11.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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >; using lparen_token = token<lit_c<'('>>; using rparen_token = token<lit_c<')'>>; using plus_exp1 = foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> >; using paren_exp1 = sequence<lparen_token, plus_exp1, rparen_token>; #include <boost/metaparse/middle_of.hpp> using paren_exp2 = middle_of<lparen_token, plus_exp1, rparen_token>; using primary_exp1 = one_of<int_token, paren_exp2>; struct plus_exp2; using paren_exp3 = middle_of<lparen_token, plus_exp2, rparen_token>; using primary_exp2 = one_of<int_token, paren_exp2>; using unary_exp2 = foldr_start_with_parser< minus_token, primary_exp2, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp5 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp2>, unary_exp2, boost::mpl::quote2<binary_op> >; struct plus_exp2 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp5>, mult_exp5, boost::mpl::quote2<binary_op> > {}; using exp_parser19 = build_parser<plus_exp2>;
Definitions before section 11.3.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >; using lparen_token = token<lit_c<'('>>; using rparen_token = token<lit_c<')'>>; using plus_exp1 = foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> >; using paren_exp1 = sequence<lparen_token, plus_exp1, rparen_token>; #include <boost/metaparse/middle_of.hpp> using paren_exp2 = middle_of<lparen_token, plus_exp1, rparen_token>; using primary_exp1 = one_of<int_token, paren_exp2>; struct plus_exp2; using paren_exp3 = middle_of<lparen_token, plus_exp2, rparen_token>; using primary_exp2 = one_of<int_token, paren_exp2>; using unary_exp2 = foldr_start_with_parser< minus_token, primary_exp2, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp5 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp2>, unary_exp2, boost::mpl::quote2<binary_op> >; struct plus_exp2 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp5>, mult_exp5, boost::mpl::quote2<binary_op> > {}; using exp_parser19 = build_parser<plus_exp2>; #include <boost/metaparse/define_error.hpp> BOOST_METAPARSE_DEFINE_ERROR(missing_primary_expression, "Missing primary expression"); struct plus_exp3; using paren_exp4 = middle_of<lparen_token, plus_exp3, rparen_token>; #include <boost/metaparse/fail.hpp> using primary_exp3 = one_of<int_token, paren_exp4, fail<missing_primary_expression>>; using unary_exp3 = foldr_start_with_parser< minus_token, primary_exp3, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp6 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp3>, unary_exp3, boost::mpl::quote2<binary_op> >; struct plus_exp3 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> > {}; using exp_parser20 = build_parser<plus_exp3>;
Definitions before section 11.3.1.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >; using lparen_token = token<lit_c<'('>>; using rparen_token = token<lit_c<')'>>; using plus_exp1 = foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> >; using paren_exp1 = sequence<lparen_token, plus_exp1, rparen_token>; #include <boost/metaparse/middle_of.hpp> using paren_exp2 = middle_of<lparen_token, plus_exp1, rparen_token>; using primary_exp1 = one_of<int_token, paren_exp2>; struct plus_exp2; using paren_exp3 = middle_of<lparen_token, plus_exp2, rparen_token>; using primary_exp2 = one_of<int_token, paren_exp2>; using unary_exp2 = foldr_start_with_parser< minus_token, primary_exp2, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp5 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp2>, unary_exp2, boost::mpl::quote2<binary_op> >; struct plus_exp2 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp5>, mult_exp5, boost::mpl::quote2<binary_op> > {}; using exp_parser19 = build_parser<plus_exp2>; #include <boost/metaparse/define_error.hpp> BOOST_METAPARSE_DEFINE_ERROR(missing_primary_expression, "Missing primary expression"); struct plus_exp3; using paren_exp4 = middle_of<lparen_token, plus_exp3, rparen_token>; #include <boost/metaparse/fail.hpp> using primary_exp3 = one_of<int_token, paren_exp4, fail<missing_primary_expression>>; using unary_exp3 = foldr_start_with_parser< minus_token, primary_exp3, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp6 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp3>, unary_exp3, boost::mpl::quote2<binary_op> >; struct plus_exp3 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> > {}; using exp_parser20 = build_parser<plus_exp3>; #include <boost/metaparse/fail_at_first_char_expected.hpp> #include <boost/metaparse/first_of.hpp> struct plus_exp4 : first_of< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> >, fail_at_first_char_expected< sequence<one_of<plus_token, minus_token>, mult_exp6> > > {}; using exp_parser21 = build_parser<plus_exp4>;
Definitions before section 11.3.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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >; using lparen_token = token<lit_c<'('>>; using rparen_token = token<lit_c<')'>>; using plus_exp1 = foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> >; using paren_exp1 = sequence<lparen_token, plus_exp1, rparen_token>; #include <boost/metaparse/middle_of.hpp> using paren_exp2 = middle_of<lparen_token, plus_exp1, rparen_token>; using primary_exp1 = one_of<int_token, paren_exp2>; struct plus_exp2; using paren_exp3 = middle_of<lparen_token, plus_exp2, rparen_token>; using primary_exp2 = one_of<int_token, paren_exp2>; using unary_exp2 = foldr_start_with_parser< minus_token, primary_exp2, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp5 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp2>, unary_exp2, boost::mpl::quote2<binary_op> >; struct plus_exp2 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp5>, mult_exp5, boost::mpl::quote2<binary_op> > {}; using exp_parser19 = build_parser<plus_exp2>; #include <boost/metaparse/define_error.hpp> BOOST_METAPARSE_DEFINE_ERROR(missing_primary_expression, "Missing primary expression"); struct plus_exp3; using paren_exp4 = middle_of<lparen_token, plus_exp3, rparen_token>; #include <boost/metaparse/fail.hpp> using primary_exp3 = one_of<int_token, paren_exp4, fail<missing_primary_expression>>; using unary_exp3 = foldr_start_with_parser< minus_token, primary_exp3, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp6 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp3>, unary_exp3, boost::mpl::quote2<binary_op> >; struct plus_exp3 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> > {}; using exp_parser20 = build_parser<plus_exp3>; #include <boost/metaparse/fail_at_first_char_expected.hpp> #include <boost/metaparse/first_of.hpp> struct plus_exp4 : first_of< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> >, fail_at_first_char_expected< sequence<one_of<plus_token, minus_token>, mult_exp6> > > {}; using exp_parser21 = build_parser<plus_exp4>; #include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> struct plus_exp5 : foldl_reject_incomplete_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> > {}; using exp_parser22 = build_parser<plus_exp5>;
Definitions before section 12.
#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> > >; #include <boost/mpl/minus.hpp> template <class L, char Op, class R> struct eval_binary_op; template <class L, class R> struct eval_binary_op<L, '+', R> : boost::mpl::plus<L, R>::type {}; template <class L, class R> struct eval_binary_op<L, '-', R> : boost::mpl::minus<L, R>::type {}; template <class S, class Item> struct binary_op : eval_binary_op< S, boost::mpl::at_c<Item, 0>::type::value, typename boost::mpl::at_c<Item, 1>::type > {}; using exp_parser13 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/times.hpp> template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; using times_token = token<lit_c<'*'>>; using exp_parser14 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token, times_token>, int_token>, int_token, boost::mpl::quote2<binary_op> > >; using mult_exp1 = foldl_start_with_parser<sequence<times_token, int_token>, int_token, boost::mpl::quote2<binary_op>>; using exp_parser15 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp1>, mult_exp1, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/divides.hpp> template <class L, class R> struct eval_binary_op<L, '/', R> : boost::mpl::divides<L, R>::type {}; using divides_token = token<lit_c<'/'>>; using mult_exp2 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, int_token>, int_token, boost::mpl::quote2<binary_op> >; using exp_parser16 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp2>, mult_exp2, boost::mpl::quote2<binary_op> > >; template <class S, class Item> struct reverse_binary_op : eval_binary_op< typename boost::mpl::at_c<Item, 0>::type, boost::mpl::at_c<Item, 1>::type::value, S > {}; #include <boost/metaparse/foldr_start_with_parser.hpp> using mult_exp3 = foldr_start_with_parser< sequence<int_token, one_of<times_token, divides_token>>, /* The parser applied repeatedly */ int_token, /* The parser parsing the last number */ boost::mpl::quote2<reverse_binary_op> /* The function called for every result */ /* of applying the above parser */ >; using exp_parser17 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp3>, mult_exp3, boost::mpl::quote2<binary_op> > >; #include <boost/mpl/negate.hpp> using unary_exp1 = foldr_start_with_parser< minus_token, int_token, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp4 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp1>, unary_exp1, boost::mpl::quote2<binary_op> >; using exp_parser18 = build_parser< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> > >; using lparen_token = token<lit_c<'('>>; using rparen_token = token<lit_c<')'>>; using plus_exp1 = foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp4>, mult_exp4, boost::mpl::quote2<binary_op> >; using paren_exp1 = sequence<lparen_token, plus_exp1, rparen_token>; #include <boost/metaparse/middle_of.hpp> using paren_exp2 = middle_of<lparen_token, plus_exp1, rparen_token>; using primary_exp1 = one_of<int_token, paren_exp2>; struct plus_exp2; using paren_exp3 = middle_of<lparen_token, plus_exp2, rparen_token>; using primary_exp2 = one_of<int_token, paren_exp2>; using unary_exp2 = foldr_start_with_parser< minus_token, primary_exp2, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp5 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp2>, unary_exp2, boost::mpl::quote2<binary_op> >; struct plus_exp2 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp5>, mult_exp5, boost::mpl::quote2<binary_op> > {}; using exp_parser19 = build_parser<plus_exp2>; #include <boost/metaparse/define_error.hpp> BOOST_METAPARSE_DEFINE_ERROR(missing_primary_expression, "Missing primary expression"); struct plus_exp3; using paren_exp4 = middle_of<lparen_token, plus_exp3, rparen_token>; #include <boost/metaparse/fail.hpp> using primary_exp3 = one_of<int_token, paren_exp4, fail<missing_primary_expression>>; using unary_exp3 = foldr_start_with_parser< minus_token, primary_exp3, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp6 = foldl_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp3>, unary_exp3, boost::mpl::quote2<binary_op> >; struct plus_exp3 : foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> > {}; using exp_parser20 = build_parser<plus_exp3>; #include <boost/metaparse/fail_at_first_char_expected.hpp> #include <boost/metaparse/first_of.hpp> struct plus_exp4 : first_of< foldl_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> >, fail_at_first_char_expected< sequence<one_of<plus_token, minus_token>, mult_exp6> > > {}; using exp_parser21 = build_parser<plus_exp4>; #include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> struct plus_exp5 : foldl_reject_incomplete_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp6>, mult_exp6, boost::mpl::quote2<binary_op> > {}; using exp_parser22 = build_parser<plus_exp5>; struct plus_exp6; using paren_exp5 = middle_of<lparen_token, plus_exp6, rparen_token>; using primary_exp4 = one_of<int_token, paren_exp5, fail<missing_primary_expression>>; using unary_exp4 = foldr_start_with_parser< minus_token, primary_exp4, boost::mpl::lambda<boost::mpl::negate<boost::mpl::_1>>::type >; using mult_exp7 = foldl_reject_incomplete_start_with_parser< sequence<one_of<times_token, divides_token>, unary_exp4>, unary_exp4, boost::mpl::quote2<binary_op> >; struct plus_exp6 : foldl_reject_incomplete_start_with_parser< sequence<one_of<plus_token, minus_token>, mult_exp7>, mult_exp7, boost::mpl::quote2<binary_op> > {}; using exp_parser23 = build_parser<plus_exp6>;