diff options
Diffstat (limited to 'src/boost/libs/metaparse')
224 files changed, 13034 insertions, 0 deletions
diff --git a/src/boost/libs/metaparse/README.md b/src/boost/libs/metaparse/README.md new file mode 100644 index 000000000..6a4dd970d --- /dev/null +++ b/src/boost/libs/metaparse/README.md @@ -0,0 +1,8 @@ +# Boost.Metaparse + +[![Build Status](https://secure.travis-ci.org/boostorg/metaparse.svg?branch=master "Build Status")](http://travis-ci.org/boostorg/metaparse) +[![Windows build status](https://ci.appveyor.com/api/projects/status/u7ysxkssmrgr7vau/branch/master?svg=true)](https://ci.appveyor.com/project/sabel83/metaparse-04v04/branch/master) + +Metaparse is parser generator library for template metaprograms. The purpose of +this library is to support the creation of parsers that parse at compile time. + diff --git a/src/boost/libs/metaparse/example/Jamfile.v2 b/src/boost/libs/metaparse/example/Jamfile.v2 new file mode 100644 index 000000000..3b82aec21 --- /dev/null +++ b/src/boost/libs/metaparse/example/Jamfile.v2 @@ -0,0 +1,14 @@ +build-project binary_number ; +build-project calculator ; +build-project calculator_with_parens ; +build-project calculator_with_parens_and_unary_ops ; +build-project compile_to_native_code ; +build-project constexpr_parser ; +build-project grammar_calculator ; +build-project meta_hs ; +build-project meta_lambda ; +build-project meta_metaparse ; +build-project minimal_rational ; +build-project parsing_error ; +build-project rational ; +build-project regexp ; diff --git a/src/boost/libs/metaparse/example/binary_number/Jamfile.v2 b/src/boost/libs/metaparse/example/binary_number/Jamfile.v2 new file mode 100644 index 000000000..9d1bdfdc0 --- /dev/null +++ b/src/boost/libs/metaparse/example/binary_number/Jamfile.v2 @@ -0,0 +1 @@ +exe binary_number : main.cpp ; diff --git a/src/boost/libs/metaparse/example/binary_number/README b/src/boost/libs/metaparse/example/binary_number/README new file mode 100644 index 000000000..580532f48 --- /dev/null +++ b/src/boost/libs/metaparse/example/binary_number/README @@ -0,0 +1 @@ +Parser for binary numbers diff --git a/src/boost/libs/metaparse/example/binary_number/main.cpp b/src/boost/libs/metaparse/example/binary_number/main.cpp new file mode 100644 index 000000000..636245834 --- /dev/null +++ b/src/boost/libs/metaparse/example/binary_number/main.cpp @@ -0,0 +1,85 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl1.hpp> +#include <boost/metaparse/build_parser.hpp> +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/one_of_c.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/metaparse/util/digit_to_int.hpp> + +#include <boost/mpl/int.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/times.hpp> + +#include <iostream> + +using boost::metaparse::foldl1; +using boost::metaparse::build_parser; +using boost::metaparse::transform; +using boost::metaparse::one_of_c; +using boost::metaparse::entire_input; + +using boost::metaparse::util::digit_to_int; + +using boost::mpl::int_; +using boost::mpl::plus; +using boost::mpl::times; + +/* + * The grammar + * + * expression ::= ('1' | '0')* + */ + +struct next_element +{ + template <class Acc, class B> + struct apply : plus<times<Acc, int_<2> >, B> {}; +}; + +typedef + foldl1<transform<one_of_c<'0', '1'>, digit_to_int<> >, int_<0>, next_element> + S; + +typedef build_parser<entire_input<S> > binary_parser; + +template <class S> +struct binary : binary_parser::apply<S>::type {}; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 + +int main() +{ + using std::cout; + using std::endl; + using boost::metaparse::string; + + cout + << binary<string<'1','0','0'> >::value << endl + << binary<string<'1','0','1','1'> >::value << endl + << binary<string<'1'> >::value << endl; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << binary<_STR("100")>::value << endl + << binary<_STR("1011")>::value << endl + << binary<_STR("1")>::value << endl; +} +#endif + + diff --git a/src/boost/libs/metaparse/example/calculator/Jamfile.v2 b/src/boost/libs/metaparse/example/calculator/Jamfile.v2 new file mode 100644 index 000000000..887cff6a8 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/Jamfile.v2 @@ -0,0 +1,6 @@ +project : requirements + <toolset>gcc:<cxxflags>-ftemplate-depth=512 + <toolset>clang:<cxxflags>-ftemplate-depth=512 +; + +exe calculator : main.cpp ; diff --git a/src/boost/libs/metaparse/example/calculator/README b/src/boost/libs/metaparse/example/calculator/README new file mode 100644 index 000000000..8229ef4b0 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/README @@ -0,0 +1 @@ +Calculator, working at compile-time diff --git a/src/boost/libs/metaparse/example/calculator/main.cpp b/src/boost/libs/metaparse/example/calculator/main.cpp new file mode 100644 index 000000000..fc0dbffa1 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/main.cpp @@ -0,0 +1,157 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/first_of.hpp> +#include <boost/metaparse/space.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/build_parser.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/fold.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/divides.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/bool.hpp> + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::first_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::bool_; +using boost::mpl::equal_to; +using boost::mpl::bool_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= int_token ((mult_token | div_token) int_token)* + */ + +typedef token<lit_c<'+'> > plus_token; +typedef token<lit_c<'-'> > minus_token; +typedef token<lit_c<'*'> > mult_token; +typedef token<lit_c<'/'> > div_token; + +typedef token<int_> int_token; + +template <class T, char C> +struct is_c : bool_<T::type::value == C> {}; + +struct eval_plus +{ + template <class State, class C> + struct apply : + eval_if< + is_c<front<C>, '+'>, + plus<typename State::type, typename back<C>::type>, + minus<typename State::type, typename back<C>::type> + > + {}; +}; + +struct eval_mult +{ + template <class State, class C> + struct apply : + eval_if< + is_c<front<C>, '*'>, + times<typename State::type, typename back<C>::type>, + divides<typename State::type, typename back<C>::type> + > + {}; +}; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<mult_token, div_token>, int_token>, + int_token, + eval_mult + > + prod_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<plus_token, minus_token>, prod_exp>, + prod_exp, + eval_plus + > + plus_exp; + +typedef last_of<repeated<space>, plus_exp> expression; + +typedef build_parser<entire_input<expression> > calculator_parser; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + using std::cout; + using std::endl; + using boost::metaparse::string; + + cout + << apply_wrap1<calculator_parser, string<'1','3'> >::type::value << endl + << + apply_wrap1< + calculator_parser, string<' ','1','+',' ','2','*','4','-','6','/','2'> + >::type::value + << endl + ; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1<calculator_parser, _STR("13")>::type::value << endl + << apply_wrap1<calculator_parser, _STR(" 1+ 2*4-6/2")>::type::value << endl + ; +} +#endif + + diff --git a/src/boost/libs/metaparse/example/calculator_with_parens/Jamfile.v2 b/src/boost/libs/metaparse/example/calculator_with_parens/Jamfile.v2 new file mode 100644 index 000000000..af3cf8796 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens/Jamfile.v2 @@ -0,0 +1 @@ +exe calculator_with_parens : main.cpp ; diff --git a/src/boost/libs/metaparse/example/calculator_with_parens/README b/src/boost/libs/metaparse/example/calculator_with_parens/README new file mode 100644 index 000000000..32bccca45 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens/README @@ -0,0 +1,2 @@ +This is an extended version of the calculator example: it supports parens as +well. diff --git a/src/boost/libs/metaparse/example/calculator_with_parens/main.cpp b/src/boost/libs/metaparse/example/calculator_with_parens/main.cpp new file mode 100644 index 000000000..9a154fc36 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens/main.cpp @@ -0,0 +1,163 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/first_of.hpp> +#include <boost/metaparse/middle_of.hpp> +#include <boost/metaparse/space.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/build_parser.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/fold.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/divides.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/bool.hpp> + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::first_of; +using boost::metaparse::middle_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::bool_; +using boost::mpl::equal_to; +using boost::mpl::bool_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= int_token ((mult_token | div_token) simple_exp)* + * simple_exp ::= int_token | paren_exp + * paren_exp ::= open_paren_token expression close_paren_token + */ + +typedef token<lit_c<'+'> > plus_token; +typedef token<lit_c<'-'> > minus_token; +typedef token<lit_c<'*'> > mult_token; +typedef token<lit_c<'/'> > div_token; + +typedef token<lit_c<'('> > open_paren_token; +typedef token<lit_c<')'> > close_paren_token; + +typedef token<int_> int_token; + +template <class T, char C> +struct is_c : bool_<T::type::value == C> {}; + +struct eval_plus +{ + template <class State, class C> + struct apply : + eval_if< + is_c<front<C>, '+'>, + plus<typename State::type, typename back<C>::type>, + minus<typename State::type, typename back<C>::type> + > + {}; +}; + +struct eval_mult +{ + template <class State, class C> + struct apply : + eval_if< + is_c<front<C>, '*'>, + times<typename State::type, typename back<C>::type>, + divides<typename State::type, typename back<C>::type> + > + {}; +}; + +struct plus_exp; + +typedef middle_of<open_paren_token, plus_exp, close_paren_token> paren_exp; + +typedef one_of<int_token, paren_exp> simple_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<mult_token, div_token>, simple_exp>, + simple_exp, + eval_mult + > + prod_exp; + +struct plus_exp : + foldl_reject_incomplete_start_with_parser< + sequence<one_of<plus_token, minus_token>, prod_exp>, + prod_exp, + eval_plus + > +{}; + +typedef last_of<repeated<space>, plus_exp> expression; + +typedef build_parser<entire_input<expression> > calculator_parser; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + std::cout << "Please use a compiler that support constexpr" << std::endl; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1<calculator_parser, _STR("13")>::type::value << endl + << apply_wrap1<calculator_parser, _STR(" 1+ 2*4-6/2")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("1+2*3+4")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("(1+2)*(3+4)")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("(2*3)+(4*5)")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("2 * 3 + 4")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("2 + (3 * 4)")>::type::value << endl + ; +} +#endif + diff --git a/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/Jamfile.v2 b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/Jamfile.v2 new file mode 100644 index 000000000..4457aa322 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/Jamfile.v2 @@ -0,0 +1 @@ +exe calculator_with_parens_and_unary_ops : main.cpp ; diff --git a/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/README b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/README new file mode 100644 index 000000000..ed8e33ad4 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/README @@ -0,0 +1,2 @@ +This is an extended version of the calculator example: it supports unary +operators (eg. -13) as well. diff --git a/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/main.cpp b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/main.cpp new file mode 100644 index 000000000..e9557562d --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator_with_parens_and_unary_ops/main.cpp @@ -0,0 +1,192 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/first_of.hpp> +#include <boost/metaparse/middle_of.hpp> +#include <boost/metaparse/space.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/foldr_start_with_parser.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/build_parser.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/fold.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/divides.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/negate.hpp> +#include <boost/mpl/char.hpp> + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::first_of; +using boost::metaparse::middle_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::foldr_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::bool_; +using boost::mpl::equal_to; +using boost::mpl::bool_; +using boost::mpl::negate; +using boost::mpl::char_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= int_token ((mult_token | div_token) simple_exp)* + * simple_exp ::= (plus_token | minus_token)* (int_token | paren_exp) + * paren_exp ::= open_paren_token expression close_paren_token + */ + +typedef token<lit_c<'+'> > plus_token; +typedef token<lit_c<'-'> > minus_token; +typedef token<lit_c<'*'> > mult_token; +typedef token<lit_c<'/'> > div_token; + +typedef token<lit_c<'('> > open_paren_token; +typedef token<lit_c<')'> > close_paren_token; + +typedef token<int_> int_token; + +template <class T, char C> +struct is_c : bool_<T::type::value == C> {}; + +struct eval_plus +{ + template <class State, class C> + struct apply : + eval_if< + is_c<front<C>, '+'>, + plus<typename State::type, typename back<C>::type>, + minus<typename State::type, typename back<C>::type> + > + {}; +}; + +struct eval_mult +{ + template <class State, class C> + struct apply : + eval_if< + is_c<front<C>, '*'>, + times<typename State::type, typename back<C>::type>, + divides<typename State::type, typename back<C>::type> + > + {}; +}; + +struct eval_unary_plus +{ + template <class State, class C> + struct apply : + eval_if< + typename equal_to<char_<'+'>, typename C::type>::type, + State, // +State is State + negate<typename State::type> + > + {}; +}; + +struct plus_exp; + +typedef middle_of<open_paren_token, plus_exp, close_paren_token> paren_exp; + +typedef + foldr_start_with_parser< + one_of<plus_token, minus_token>, + one_of<int_token, paren_exp>, + eval_unary_plus + > + simple_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<mult_token, div_token>, simple_exp>, + simple_exp, + eval_mult + > + prod_exp; + +struct plus_exp : + foldl_reject_incomplete_start_with_parser< + sequence<one_of<plus_token, minus_token>, prod_exp>, + prod_exp, + eval_plus + > +{}; + +typedef last_of<repeated<space>, plus_exp> expression; + +typedef build_parser<entire_input<expression> > calculator_parser; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + std::cout << "Please use a compiler that support constexpr" << std::endl; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1<calculator_parser, _STR("13")>::type::value << endl + << apply_wrap1<calculator_parser, _STR(" 1+ 2*4-6/2")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("1+2*3+4")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("(1+2)*(3+4)")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("(2*3)+(4*5)")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("2 * 3 + 4")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("2 + (3 * 4)")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("+3")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("-21")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("24 + - 21")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("- - 21")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("-(3 * 4)")>::type::value << endl + ; +} +#endif + diff --git a/src/boost/libs/metaparse/example/compile_to_native_code/Jamfile.v2 b/src/boost/libs/metaparse/example/compile_to_native_code/Jamfile.v2 new file mode 100644 index 000000000..05530b7c8 --- /dev/null +++ b/src/boost/libs/metaparse/example/compile_to_native_code/Jamfile.v2 @@ -0,0 +1 @@ +exe compile_to_native_code : main.cpp ; diff --git a/src/boost/libs/metaparse/example/compile_to_native_code/README b/src/boost/libs/metaparse/example/compile_to_native_code/README new file mode 100644 index 000000000..f41680ff7 --- /dev/null +++ b/src/boost/libs/metaparse/example/compile_to_native_code/README @@ -0,0 +1 @@ +An example on how to compile an EDSL into native executable code. diff --git a/src/boost/libs/metaparse/example/compile_to_native_code/main.cpp b/src/boost/libs/metaparse/example/compile_to_native_code/main.cpp new file mode 100644 index 000000000..e83624b2f --- /dev/null +++ b/src/boost/libs/metaparse/example/compile_to_native_code/main.cpp @@ -0,0 +1,252 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/space.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/build_parser.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/if.hpp> + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; +using boost::metaparse::transform; +using boost::metaparse::always; + +using boost::mpl::apply_wrap1; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::if_; +using boost::mpl::bool_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= value_exp ((mult_token | div_token) value_exp)* + * value_exp ::= int_token | '_' + */ + +typedef token<lit_c<'+'> > plus_token; +typedef token<lit_c<'-'> > minus_token; +typedef token<lit_c<'*'> > mult_token; +typedef token<lit_c<'/'> > div_token; + +typedef token<int_> int_token; +typedef token<lit_c<'_'> > arg_token; + +template <class T, char C> +struct is_c : bool_<T::type::value == C> {}; + +struct build_plus +{ + template <class A, class B> + class _plus + { + public: + typedef _plus type; + + template <class T> + T operator()(T t) const + { + return _left(t) + _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class A, class B> + class _minus + { + public: + typedef _minus type; + + template <class T> + T operator()(T t) const + { + return _left(t) - _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class State, class C> + struct apply : + if_< + typename is_c<front<C>, '+'>::type, + _plus<State, typename back<C>::type>, + _minus<State, typename back<C>::type> + > + {}; +}; + +struct build_mult +{ + template <class A, class B> + class _mult + { + public: + typedef _mult type; + + template <class T> + T operator()(T t) const + { + return _left(t) * _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class A, class B> + class _div + { + public: + typedef _div type; + + template <class T> + T operator()(T t) const + { + return _left(t) / _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class State, class C> + struct apply : + if_< + typename is_c<front<C>, '*'>::type, + _mult<State, typename back<C>::type>, + _div<State, typename back<C>::type> + > + {}; +}; + +struct build_value +{ + typedef build_value type; + + template <class V> + struct apply + { + typedef apply type; + + template <class T> + int operator()(T) const + { + return V::type::value; + } + }; +}; + +struct arg +{ + typedef arg type; + + template <class T> + T operator()(T t) const + { + return t; + } +}; + +typedef + one_of<transform<int_token, build_value>, always<arg_token, arg> > + value_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<mult_token, div_token>, value_exp>, + value_exp, + build_mult + > + prod_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<plus_token, minus_token>, prod_exp>, + prod_exp, + build_plus + > + plus_exp; + +typedef last_of<repeated<space>, plus_exp> expression; + +typedef build_parser<entire_input<expression> > function_parser; + +#if BOOST_METAPARSE_STD < 2011 + +template <class Exp> +struct lambda : apply_wrap1<function_parser, Exp> {}; + +using boost::metaparse::string; + +lambda<string<'1','3'> >::type f1; +lambda<string<'2',' ','+',' ','3'> >::type f2; +lambda<string<'2',' ','*',' ','2'> >::type f3; +lambda<string<' ','1','+',' ','2','*','4','-','6','/','2'> >::type f4; +lambda<string<'2',' ','*',' ','_'> >::type f5; + +#else + +#ifdef LAMBDA + #error LAMBDA already defined +#endif +#define LAMBDA(exp) apply_wrap1<function_parser, BOOST_METAPARSE_STRING(#exp)>::type + +LAMBDA(13) f1; +LAMBDA(2 + 3) f2; +LAMBDA(2 * 2) f3; +LAMBDA( 1+ 2*4-6/2) f4; +LAMBDA(2 * _) f5; + +#endif + +int main() +{ + using std::cout; + using std::endl; + + cout + << f1(11) << endl + << f2(11) << endl + << f3(11) << endl + << f4(11) << endl + << f5(11) << endl + << f5(1.1) << endl + ; +} + + diff --git a/src/boost/libs/metaparse/example/constexpr_parser/Jamfile.v2 b/src/boost/libs/metaparse/example/constexpr_parser/Jamfile.v2 new file mode 100644 index 000000000..5e1f4246a --- /dev/null +++ b/src/boost/libs/metaparse/example/constexpr_parser/Jamfile.v2 @@ -0,0 +1 @@ +exe constexpr_parser : main.cpp ; diff --git a/src/boost/libs/metaparse/example/constexpr_parser/README b/src/boost/libs/metaparse/example/constexpr_parser/README new file mode 100644 index 000000000..8b50db0e5 --- /dev/null +++ b/src/boost/libs/metaparse/example/constexpr_parser/README @@ -0,0 +1,12 @@ +Parsers parsing "a* b* a*" and counting the appearance of the characters. +This parser is implemented in three different ways: +- One built with Metaparse +- One implemented using constexpr functions +- One built with Metaparse but parsing a subexpression with a constexpr parser: + - a* at the beginning is parsed using a Metaparse parser + - b* is parsed using a constexpr function + - a* at the end is parsed using a Mataparse parser again + +This example demonstrates how Metaparse can be combined with parsers using +constexpr functions. + diff --git a/src/boost/libs/metaparse/example/constexpr_parser/main.cpp b/src/boost/libs/metaparse/example/constexpr_parser/main.cpp new file mode 100644 index 000000000..4fe291b07 --- /dev/null +++ b/src/boost/libs/metaparse/example/constexpr_parser/main.cpp @@ -0,0 +1,318 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/foldl.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/build_parser.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/iterate_c.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/return_.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/pop_front.hpp> +#include <boost/mpl/size.hpp> + +#include <iostream> +#include <string> + +#if BOOST_METAPARSE_STD < 2011 + +int main() +{ + std::cout + << "This example focuses on constexpr, which is not supported" + << std::endl; +} + +#else + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::build_parser; +using boost::metaparse::foldl; +using boost::metaparse::entire_input; +using boost::metaparse::get_result; +using boost::metaparse::start; +using boost::metaparse::last_of; +using boost::metaparse::iterate_c; +using boost::metaparse::one_char; +using boost::metaparse::return_; + +using boost::mpl::apply_wrap1; +using boost::mpl::apply_wrap2; +using boost::mpl::plus; +using boost::mpl::int_; +using boost::mpl::at_c; +using boost::mpl::front; +using boost::mpl::pop_front; +using boost::mpl::size; + +using std::ostream; + +/* + * The grammar + * + * S ::= a* b* a* + */ + +struct parsed +{ + template <class T> + constexpr static parsed build() + { + return + parsed( + at_c<typename T::type, 0>::type::value, + at_c<typename T::type, 1>::type::value, + at_c<typename T::type, 2>::type::value + ); + } + + constexpr parsed(int a1, int b, int a2) : + a_count1(a1), + b_count(b), + a_count2(a2) + {}; + + int a_count1; + int b_count; + int a_count2; +}; + +ostream& operator<<(ostream& o, const parsed& p) +{ + return + o << "(" << p.a_count1 << ", " << p.b_count << ", " << p.a_count2 << ")"; +} + +// constexpr parser + +template <class T, int Len> +struct const_list +{ + T head; + const_list<T, Len - 1> tail; + + constexpr const_list(const T& h, const const_list<T, Len - 1>& t) : + head(h), + tail(t) + {} + + constexpr const_list<T, Len + 1> push_front(const T& t) const + { + return const_list<T, Len + 1>(t, *this); + } + + constexpr T at(int n) const + { + return n == 0 ? head : tail.at(n - 1); + } +}; + +template <class T> +struct const_list<T, 0> +{ + constexpr const_list<T, 1> push_front(const T& t) const + { + return const_list<T, 1>(t, *this); + } + + constexpr T at(int) const + { + return T(); + } +}; + +template <class T, int N, int from = 0> +struct to_list +{ + static constexpr const_list<T, N - from> run(const T (&s)[N]) + { + return const_list<T, N - from>(s[from], to_list<T, N, from + 1>::run(s)); + } +}; + +template <class T, int N> +struct to_list<T, N, N> +{ + static constexpr const_list<T, 0> run(const T (&s)[N]) + { + return const_list<T, 0>(); + } +}; + +struct presult +{ + int value; + int remaining_from; + + constexpr presult(int v, int r) : value(v), remaining_from(r) {} + + constexpr presult incr() const { return presult(value + 1, remaining_from); } +}; + +template <char C, int N> +constexpr presult parse_cs(const const_list<char, N>& s, int from) +{ + return + from < N ? + (s.at(from) == C ? parse_cs<C, N>(s, from + 1).incr() : presult(0, from)) : + presult(0, from); +} + +template <int N> +constexpr parsed parse_impl(const const_list<char, N>& s) +{ + return + parsed( + parse_cs<'a', N>(s, 0).value, + parse_cs<'b', N>(s, parse_cs<'a', N>(s, 0).remaining_from).value, + parse_cs<'a', N>( + s, + parse_cs<'b', N>( + s, + parse_cs<'a', N>(s, 0).remaining_from + ).remaining_from + ).value + ); +} + +template <int N> +constexpr parsed parse(const char (&s)[N]) +{ + return parse_impl(to_list<char, N>::run(s)); +} + +// TMP parser + +struct count +{ + typedef count type; + + template <class State, class C> + struct apply : plus<int_<1>, State> {}; +}; + +typedef foldl<lit_c<'a'>, int_<0>, count> as; +typedef foldl<lit_c<'b'>, int_<0>, count> bs; + +typedef sequence<as, bs, as> s; + +typedef build_parser<entire_input<s> > parser; + +#ifdef P + #error P already defined +#endif +#define P(x) \ + parsed::build<boost::mpl::apply_wrap1<parser, BOOST_METAPARSE_STRING(#x)> >() + +// Mixed parser + +template <class ValueType, class L, int Len> +struct tmp_to_const_list_impl +{ + constexpr static const_list<ValueType, Len> run() + { + return + const_list<ValueType, Len>( + front<L>::type::value, + tmp_to_const_list_impl< + ValueType, + typename pop_front<L>::type, + Len - 1 + >::run() + ); + } +}; + +template <class ValueType, class L> +struct tmp_to_const_list_impl<ValueType, L, 0> +{ + constexpr static const_list<ValueType, 0> run() + { + return const_list<ValueType, 0>(); + } +}; + +template <class ValueType, class L> +struct tmp_to_const_list : + tmp_to_const_list_impl<ValueType, L, size<L>::type::value> +{}; + +template <char C> +struct parse_with_constexpr +{ + typedef parse_with_constexpr type; + + template <class S> + static constexpr presult impl() + { + return + parse_cs<C, size<S>::type::value>(tmp_to_const_list<char, S>::run(), 0); + } + + template <class S, class Pos> + struct apply : + apply_wrap2< + last_of< + iterate_c<one_char, impl<S>().remaining_from>, + return_<int_<impl<S>().value> > + >, + S, + Pos + > + {}; +}; + +typedef parse_with_constexpr<'b'> bs_mixed; + +typedef sequence<as, bs_mixed, as> s_mixed; + +typedef build_parser<entire_input<s_mixed> > parser_mixed; + +#ifdef P_MIXED + #error P_MIXED already defined +#endif +#define P_MIXED(x) \ + parsed::build< \ + boost::mpl::apply_wrap1<parser_mixed, BOOST_METAPARSE_STRING(#x)> \ + >() + +int main() +{ + using std::cout; + using std::endl; + + cout + << "TMP only parsers:" << endl + << P(aba) << endl + << P(aaaaaaabbbbaaaa) << endl + << endl + + << "constexpr only parsers:" << endl + << parse("") << endl + << parse("aba") << endl + << parse("aaaaaaabbbbaaaa") << endl + << endl + + << "mixed parsers:" << endl + << P_MIXED(aba) << endl + << P_MIXED(aaaaaaabbbbaaaa) << endl + << endl + ; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1.hpp b/src/boost/libs/metaparse/example/getting_started/1.hpp new file mode 100644 index 000000000..ee00e7a1d --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1.hpp @@ -0,0 +1,9 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_HPP + +// Automatically generated header file + +// Definitions of section + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/10.hpp b/src/boost/libs/metaparse/example/getting_started/10.hpp new file mode 100644 index 000000000..e8ed5f1c3 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/10.hpp @@ -0,0 +1,42 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_10_HPP +#define BOOST_METAPARSE_GETTING_STARTED_10_HPP + +// Automatically generated header file + +// Definitions before section 9 +#include "9.hpp" + +// Definitions of section 9 +#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> + > + >; + +// query: +// exp_parser18::apply<BOOST_METAPARSE_STRING("---13")>::type + +// query: +// exp_parser18::apply<BOOST_METAPARSE_STRING("13")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11.hpp b/src/boost/libs/metaparse/example/getting_started/11.hpp new file mode 100644 index 000000000..3583496a8 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11.hpp @@ -0,0 +1,62 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_HPP + +// Automatically generated header file + +// Definitions before section 10 +#include "10.hpp" + +// Definitions of section 10 +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>; + +// query: +// exp_parser19::apply<BOOST_METAPARSE_STRING("(1 + 2) * 3")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_1.hpp b/src/boost/libs/metaparse/example/getting_started/11_1.hpp new file mode 100644 index 000000000..be2a2de63 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_1.hpp @@ -0,0 +1,14 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_1_HPP + +// Automatically generated header file + +// Definitions before section 11 +#include "11.hpp" + +// Definitions of section 11 +// query: +// exp_parser19::apply<BOOST_METAPARSE_STRING("hello")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_2.hpp b/src/boost/libs/metaparse/example/getting_started/11_2.hpp new file mode 100644 index 000000000..ae36b4e46 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_2_HPP + +// Automatically generated header file + +// Definitions before section 11.1 +#include "11_1.hpp" + +// Definitions of section 11.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_3.hpp b/src/boost/libs/metaparse/example/getting_started/11_3.hpp new file mode 100644 index 000000000..a93c2dc47 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_3.hpp @@ -0,0 +1,49 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_3_HPP + +// Automatically generated header file + +// Definitions before section 11.2 +#include "11_2.hpp" + +// Definitions of section 11.2 +#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>; + +// query: +// exp_parser20::apply<BOOST_METAPARSE_STRING("hello")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_3_1.hpp b/src/boost/libs/metaparse/example/getting_started/11_3_1.hpp new file mode 100644 index 000000000..56da35a82 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_3_1.hpp @@ -0,0 +1,38 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_3_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_3_1_HPP + +// Automatically generated header file + +// Definitions before section 11.3 +#include "11_3.hpp" + +// Definitions of section 11.3 +// query: +// exp_parser20::apply<BOOST_METAPARSE_STRING("(1+2")>::type + +// query: +// exp_parser20::apply<BOOST_METAPARSE_STRING("0+(1+2")>::type + +#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>; + +// query: +// exp_parser21::apply<BOOST_METAPARSE_STRING("0+(1+2")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/11_3_2.hpp b/src/boost/libs/metaparse/example/getting_started/11_3_2.hpp new file mode 100644 index 000000000..bf2e4b457 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/11_3_2.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_11_3_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_11_3_2_HPP + +// Automatically generated header file + +// Definitions before section 11.3.1 +#include "11_3_1.hpp" + +// Definitions of section 11.3.1 +#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>; + +// query: +// exp_parser22::apply<BOOST_METAPARSE_STRING("0+(1+2")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/12.hpp b/src/boost/libs/metaparse/example/getting_started/12.hpp new file mode 100644 index 000000000..d503539b1 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/12.hpp @@ -0,0 +1,46 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_12_HPP +#define BOOST_METAPARSE_GETTING_STARTED_12_HPP + +// Automatically generated header file + +// Definitions before section 11.3.2 +#include "11_3_2.hpp" + +// Definitions of section 11.3.2 +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>; + +// query: +// exp_parser23::apply<BOOST_METAPARSE_STRING("1+(2*")>::type + +// query: +// exp_parser23::apply<BOOST_METAPARSE_STRING("1+(2*3")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_1.hpp b/src/boost/libs/metaparse/example/getting_started/1_1.hpp new file mode 100644 index 000000000..36fa44660 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_1_HPP + +// Automatically generated header file + +// Definitions before section 1 +#include "1.hpp" + +// Definitions of section 1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_2.hpp b/src/boost/libs/metaparse/example/getting_started/1_2.hpp new file mode 100644 index 000000000..dd19e3ef9 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_2_HPP + +// Automatically generated header file + +// Definitions before section 1.1 +#include "1_1.hpp" + +// Definitions of section 1.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_2_1.hpp b/src/boost/libs/metaparse/example/getting_started/1_2_1.hpp new file mode 100644 index 000000000..db5d3fe53 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_2_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_2_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_2_1_HPP + +// Automatically generated header file + +// Definitions before section 1.2 +#include "1_2.hpp" + +// Definitions of section 1.2 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/1_2_2.hpp b/src/boost/libs/metaparse/example/getting_started/1_2_2.hpp new file mode 100644 index 000000000..f84edb36c --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/1_2_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_1_2_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_1_2_2_HPP + +// Automatically generated header file + +// Definitions before section 1.2.1 +#include "1_2_1.hpp" + +// Definitions of section 1.2.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/2.hpp b/src/boost/libs/metaparse/example/getting_started/2.hpp new file mode 100644 index 000000000..3c3ecb422 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_2_HPP + +// Automatically generated header file + +// Definitions before section 1.2.2 +#include "1_2_2.hpp" + +// Definitions of section 1.2.2 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3.hpp b/src/boost/libs/metaparse/example/getting_started/3.hpp new file mode 100644 index 000000000..4df3b531d --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3.hpp @@ -0,0 +1,19 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_HPP + +// Automatically generated header file + +// Definitions before section 2 +#include "2.hpp" + +// Definitions of section 2 +#include <boost/metaparse/string.hpp> + +// query: +// boost::metaparse::string<'1', '1', ' ', '+', ' ', '2'> + +// query: +// BOOST_METAPARSE_STRING("11 + 2") + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3_1.hpp b/src/boost/libs/metaparse/example/getting_started/3_1.hpp new file mode 100644 index 000000000..f383508db --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3_1.hpp @@ -0,0 +1,22 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_1_HPP + +// Automatically generated header file + +// Definitions before section 3 +#include "3.hpp" + +// Definitions of section 3 +#include <boost/metaparse/int_.hpp> + +#include <boost/metaparse/build_parser.hpp> + +using namespace boost::metaparse; + +using exp_parser1 = build_parser<int_>; + +// query: +// exp_parser1::apply<BOOST_METAPARSE_STRING("13")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3_2.hpp b/src/boost/libs/metaparse/example/getting_started/3_2.hpp new file mode 100644 index 000000000..0cc9a48e7 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3_2.hpp @@ -0,0 +1,14 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_2_HPP + +// Automatically generated header file + +// Definitions before section 3.1 +#include "3_1.hpp" + +// Definitions of section 3.1 +// query: +// exp_parser1::apply<BOOST_METAPARSE_STRING("thirteen")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/3_3.hpp b/src/boost/libs/metaparse/example/getting_started/3_3.hpp new file mode 100644 index 000000000..cc35183f1 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/3_3.hpp @@ -0,0 +1,24 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_3_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_3_3_HPP + +// Automatically generated header file + +// Definitions before section 3.2 +#include "3_2.hpp" + +// Definitions of section 3.2 +// query: +// exp_parser1::apply<BOOST_METAPARSE_STRING("11 13")>::type + +#include <boost/metaparse/entire_input.hpp> + +using exp_parser2 = build_parser<entire_input<int_>>; + +// query: +// exp_parser2::apply<BOOST_METAPARSE_STRING("13")>::type + +// query: +// exp_parser2::apply<BOOST_METAPARSE_STRING("11 13")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/4.hpp b/src/boost/libs/metaparse/example/getting_started/4.hpp new file mode 100644 index 000000000..6fe2fc8f6 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/4.hpp @@ -0,0 +1,21 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_4_HPP +#define BOOST_METAPARSE_GETTING_STARTED_4_HPP + +// Automatically generated header file + +// Definitions before section 3.3 +#include "3_3.hpp" + +// Definitions of section 3.3 +// query: +// exp_parser2::apply<BOOST_METAPARSE_STRING("11 ")>::type + +#include <boost/metaparse/token.hpp> + +using exp_parser3 = build_parser<entire_input<token<int_>>>; + +// query: +// exp_parser3::apply<BOOST_METAPARSE_STRING("11 ")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/4_1.hpp b/src/boost/libs/metaparse/example/getting_started/4_1.hpp new file mode 100644 index 000000000..513705947 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/4_1.hpp @@ -0,0 +1,27 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_4_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_4_1_HPP + +// Automatically generated header file + +// Definitions before section 4 +#include "4.hpp" + +// Definitions of section 4 +#include <boost/metaparse/lit_c.hpp> + +#include <boost/metaparse/sequence.hpp> + +using exp_parser4 = build_parser<sequence<token<int_>, token<lit_c<'+'>>, token<int_>>>; + +// query: +// exp_parser4::apply<BOOST_METAPARSE_STRING("11 + 2")>::type + +#ifdef __METASHELL +#include <metashell/formatter.hpp> +#endif + +// query: +// exp_parser4::apply<BOOST_METAPARSE_STRING("11 + 2")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/4_2.hpp b/src/boost/libs/metaparse/example/getting_started/4_2.hpp new file mode 100644 index 000000000..1663c4686 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/4_2.hpp @@ -0,0 +1,20 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_4_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_4_2_HPP + +// Automatically generated header file + +// Definitions before section 4.1 +#include "4_1.hpp" + +// Definitions of section 4.1 +using int_token = token<int_>; + +using plus_token = token<lit_c<'+'>>; + +using exp_parser5 = build_parser<sequence<int_token, plus_token, int_token>>; + +// query: +// exp_parser5::apply<BOOST_METAPARSE_STRING("11 + 2")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5.hpp b/src/boost/libs/metaparse/example/getting_started/5.hpp new file mode 100644 index 000000000..671b34e9e --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5.hpp @@ -0,0 +1,45 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_HPP + +// Automatically generated header file + +// Definitions before section 4.2 +#include "4_2.hpp" + +// Definitions of section 4.2 +#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 + > {}; + +// query: +// eval_plus< +// boost::mpl::vector< +// mpl_::integral_c<int, 11>, +// mpl_::char_<'+'>, +// mpl_::integral_c<int, 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> + > + >; + +// query: +// exp_parser6::apply<BOOST_METAPARSE_STRING("11 + 2")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_1.hpp b/src/boost/libs/metaparse/example/getting_started/5_1.hpp new file mode 100644 index 000000000..4042182e2 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_1_HPP + +// Automatically generated header file + +// Definitions before section 5 +#include "5.hpp" + +// Definitions of section 5 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2.hpp b/src/boost/libs/metaparse/example/getting_started/5_2.hpp new file mode 100644 index 000000000..ea9a0b18a --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2.hpp @@ -0,0 +1,24 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_HPP + +// Automatically generated header file + +// Definitions before section 5.1 +#include "5_1.hpp" + +// Definitions of section 5.1 +#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 */ + > + >; + +// query: +// exp_parser7::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_1.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_1.hpp new file mode 100644 index 000000000..f8e9ca219 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_1.hpp @@ -0,0 +1,13 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_1_HPP + +// Automatically generated header file + +// Definitions before section 5.2 +#include "5_2.hpp" + +// Definitions of section 5.2 +using temp_result = exp_parser7::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type; + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_2.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_2.hpp new file mode 100644 index 000000000..ea9ecb366 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_2.hpp @@ -0,0 +1,58 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_2_HPP + +// Automatically generated header file + +// Definitions before section 5.2.1 +#include "5_2_1.hpp" + +// Definitions of section 5.2.1 +#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 + > + {}; + +// query: +// sum_vector<vector_of_numbers>::type + +template <class Sum, class Item> + struct sum_items : + boost::mpl::plus< + Sum, + typename boost::mpl::at_c<Item, 1>::type + > + {}; + +// query: +// sum_items< +// mpl_::integral_c<int, 1>, +// boost::mpl::vector<mpl_::char_<'+'>, mpl_::integral_c<int, 2>> +// >::type + +// query: +// boost::mpl::at_c<temp_result, 1>::type + +// query: +// boost::mpl::fold< +// boost::mpl::at_c<temp_result, 1>::type, /* The vector to summarise */ +// boost::mpl::int_<0>, /* The value to start the sum from */ +// boost::mpl::quote2<sum_items> /* The function to call in each iteration */ +// >::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_3.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_3.hpp new file mode 100644 index 000000000..b14a0c5e5 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_3.hpp @@ -0,0 +1,58 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_3_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_3_HPP + +// Automatically generated header file + +// Definitions before section 5.2.2 +#include "5_2_2.hpp" + +// Definitions of section 5.2.2 +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 + > + > + >; + +// query: +// exp_parser8::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::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 */ + > + >; + +// query: +// exp_parser9::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/5_2_4.hpp b/src/boost/libs/metaparse/example/getting_started/5_2_4.hpp new file mode 100644 index 000000000..3d4d30210 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/5_2_4.hpp @@ -0,0 +1,27 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_4_HPP +#define BOOST_METAPARSE_GETTING_STARTED_5_2_4_HPP + +// Automatically generated header file + +// Definitions before section 5.2.3 +#include "5_2_3.hpp" + +// Definitions of section 5.2.3 +#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>> + >; + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/6.hpp b/src/boost/libs/metaparse/example/getting_started/6.hpp new file mode 100644 index 000000000..906cb04bd --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/6.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_6_HPP +#define BOOST_METAPARSE_GETTING_STARTED_6_HPP + +// Automatically generated header file + +// Definitions before section 5.2.4 +#include "5_2_4.hpp" + +// Definitions of section 5.2.4 +#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 */ + > + >; + +// query: +// exp_parser11::apply<BOOST_METAPARSE_STRING("1 + 2 + 3 + 4")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/6_1.hpp b/src/boost/libs/metaparse/example/getting_started/6_1.hpp new file mode 100644 index 000000000..0cc124497 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/6_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_6_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_6_1_HPP + +// Automatically generated header file + +// Definitions before section 6 +#include "6.hpp" + +// Definitions of section 6 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/6_2.hpp b/src/boost/libs/metaparse/example/getting_started/6_2.hpp new file mode 100644 index 000000000..d9f8bad27 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/6_2.hpp @@ -0,0 +1,27 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_6_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_6_2_HPP + +// Automatically generated header file + +// Definitions before section 6.1 +#include "6_1.hpp" + +// Definitions of section 6.1 +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> + > + >; + +// query: +// exp_parser12::apply<BOOST_METAPARSE_STRING("1 + 2 - 3")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/7.hpp b/src/boost/libs/metaparse/example/getting_started/7.hpp new file mode 100644 index 000000000..fe245b98a --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/7.hpp @@ -0,0 +1,49 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_7_HPP +#define BOOST_METAPARSE_GETTING_STARTED_7_HPP + +// Automatically generated header file + +// Definitions before section 6.2 +#include "6_2.hpp" + +// Definitions of section 6.2 +#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 {}; + +// query: +// eval_binary_op<boost::mpl::int_<11>, '+', boost::mpl::int_<2>>::type + +// query: +// eval_binary_op<boost::mpl::int_<13>, '-', boost::mpl::int_<2>>::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 + > + {}; + +// query: +// binary_op<boost::mpl::int_<11>, boost::mpl::vector<boost::mpl::char_<'+'>, boost::mpl::int_<2>>>::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> + > + >; + +// query: +// exp_parser13::apply<BOOST_METAPARSE_STRING("1 + 2 - 3")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/7_1.hpp b/src/boost/libs/metaparse/example/getting_started/7_1.hpp new file mode 100644 index 000000000..02b99e7b6 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/7_1.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_7_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_7_1_HPP + +// Automatically generated header file + +// Definitions before section 7 +#include "7.hpp" + +// Definitions of section 7 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/7_2.hpp b/src/boost/libs/metaparse/example/getting_started/7_2.hpp new file mode 100644 index 000000000..07e1a3583 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/7_2.hpp @@ -0,0 +1,35 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_7_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_7_2_HPP + +// Automatically generated header file + +// Definitions before section 7.1 +#include "7_1.hpp" + +// Definitions of section 7.1 +#include <boost/mpl/times.hpp> + +template <class L, class R> struct eval_binary_op<L, '*', R> : boost::mpl::times<L, R>::type {}; + +// query: +// eval_binary_op<boost::mpl::int_<3>, '*', boost::mpl::int_<4>>::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> + > + >; + +// query: +// exp_parser14::apply<BOOST_METAPARSE_STRING("2 * 3")>::type + +// query: +// exp_parser14::apply<BOOST_METAPARSE_STRING("1 + 2 * 3")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/8.hpp b/src/boost/libs/metaparse/example/getting_started/8.hpp new file mode 100644 index 000000000..c052f5b83 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/8.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_8_HPP +#define BOOST_METAPARSE_GETTING_STARTED_8_HPP + +// Automatically generated header file + +// Definitions before section 7.2 +#include "7_2.hpp" + +// Definitions of section 7.2 +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> + > + >; + +// query: +// exp_parser15::apply<BOOST_METAPARSE_STRING("1 + 2 * 3")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/8_1.hpp b/src/boost/libs/metaparse/example/getting_started/8_1.hpp new file mode 100644 index 000000000..aca70e75c --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/8_1.hpp @@ -0,0 +1,36 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_8_1_HPP +#define BOOST_METAPARSE_GETTING_STARTED_8_1_HPP + +// Automatically generated header file + +// Definitions before section 8 +#include "8.hpp" + +// Definitions of section 8 +#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> + > + >; + +// query: +// exp_parser16::apply<BOOST_METAPARSE_STRING("8 / 4")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/8_2.hpp b/src/boost/libs/metaparse/example/getting_started/8_2.hpp new file mode 100644 index 000000000..303c38830 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/8_2.hpp @@ -0,0 +1,12 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_8_2_HPP +#define BOOST_METAPARSE_GETTING_STARTED_8_2_HPP + +// Automatically generated header file + +// Definitions before section 8.1 +#include "8_1.hpp" + +// Definitions of section 8.1 + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/9.hpp b/src/boost/libs/metaparse/example/getting_started/9.hpp new file mode 100644 index 000000000..47366b913 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/9.hpp @@ -0,0 +1,42 @@ +#ifndef BOOST_METAPARSE_GETTING_STARTED_9_HPP +#define BOOST_METAPARSE_GETTING_STARTED_9_HPP + +// Automatically generated header file + +// Definitions before section 8.2 +#include "8_2.hpp" + +// Definitions of section 8.2 +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> + > + >; + +// query: +// exp_parser17::apply<BOOST_METAPARSE_STRING("8 / 4 / 2")>::type + +#endif + diff --git a/src/boost/libs/metaparse/example/getting_started/README b/src/boost/libs/metaparse/example/getting_started/README new file mode 100644 index 000000000..f2c6703b5 --- /dev/null +++ b/src/boost/libs/metaparse/example/getting_started/README @@ -0,0 +1,6 @@ +This example contains the code snippets of Getting Started. These headers are +intended to be used from Metashell. To get all the definitions before section +N. you need to include N.hpp + +The headers can always be re-generated by running tools/generate_all.py + diff --git a/src/boost/libs/metaparse/example/grammar_calculator/Jamfile.v2 b/src/boost/libs/metaparse/example/grammar_calculator/Jamfile.v2 new file mode 100644 index 000000000..cc98a4090 --- /dev/null +++ b/src/boost/libs/metaparse/example/grammar_calculator/Jamfile.v2 @@ -0,0 +1,6 @@ +project : requirements + <toolset>gcc:<cxxflags>-ftemplate-depth=512 + <toolset>clang:<cxxflags>-ftemplate-depth=512 +; + +exe grammar_calculator : main.cpp ; diff --git a/src/boost/libs/metaparse/example/grammar_calculator/README b/src/boost/libs/metaparse/example/grammar_calculator/README new file mode 100644 index 000000000..553170a15 --- /dev/null +++ b/src/boost/libs/metaparse/example/grammar_calculator/README @@ -0,0 +1,2 @@ +Calculator, working at compile-time. This example demonstrates how to build it +with grammars. diff --git a/src/boost/libs/metaparse/example/grammar_calculator/main.cpp b/src/boost/libs/metaparse/example/grammar_calculator/main.cpp new file mode 100644 index 000000000..95ca139c0 --- /dev/null +++ b/src/boost/libs/metaparse/example/grammar_calculator/main.cpp @@ -0,0 +1,160 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/config.hpp> + +#if BOOST_METAPARSE_STD < 2011 +#include <iostream> + +int main() +{ + std::cout << "Please use a compiler that supports constexpr" << std::endl; +} +#else + +#define BOOST_MPL_LIMIT_STRING_SIZE 64 +#define BOOST_METAPARSE_LIMIT_STRING_SIZE BOOST_MPL_LIMIT_STRING_SIZE + +#include <boost/metaparse/grammar.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/build_parser.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/util/digit_to_int.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/fold.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/divides.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/lambda.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/int.hpp> + +using boost::metaparse::build_parser; +using boost::metaparse::entire_input; +using boost::metaparse::token; +using boost::metaparse::grammar; + +using boost::metaparse::util::digit_to_int; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::equal_to; +using boost::mpl::_1; +using boost::mpl::_2; +using boost::mpl::char_; +using boost::mpl::lambda; +using boost::mpl::int_; + +#ifdef _STR + #error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +template <class A, class B> +struct lazy_plus : plus<typename A::type, typename B::type> {}; + +template <class A, class B> +struct lazy_minus : minus<typename A::type, typename B::type> {}; + +template <class A, class B> +struct lazy_times : times<typename A::type, typename B::type> {}; + +template <class A, class B> +struct lazy_divides : divides<typename A::type, typename B::type> {}; + +template <class C, class T, class F> +struct lazy_eval_if : eval_if<typename C::type, T, F> {}; + +template <class A, class B> +struct lazy_equal_to : equal_to<typename A::type, typename B::type> {}; + +template <class Sequence, class State, class ForwardOp> +struct lazy_fold : + fold<typename Sequence::type, typename State::type, typename ForwardOp::type> +{}; + +typedef + lazy_fold< + back<_1>, + front<_1>, + lambda< + lazy_eval_if< + lazy_equal_to<front<_2>, char_<'*'>>, + lazy_times<_1, back<_2>>, + lazy_divides<_1, back<_2>> + > + >::type + > + prod_action; + +typedef + lazy_fold< + back<_1>, + front<_1>, + lambda< + lazy_eval_if< + lazy_equal_to<front<_2>, char_<'+'>>, + lazy_plus<_1, back<_2>>, + lazy_minus<_1, back<_2>> + > + >::type + > + plus_action; + +typedef + lambda< + lazy_fold< + _1, + int_<0>, + lambda< + lazy_plus<lazy_times<_1, int_<10>>, apply_wrap1<digit_to_int<>, _2>> + >::type + > + >::type + int_action; + +typedef + grammar<_STR("plus_exp")> + + ::rule<_STR("int ::= ('0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9')+"), int_action>::type + ::rule<_STR("ws ::= (' ' | '\n' | '\r' | '\t')*")>::type + ::rule<_STR("int_token ::= int ws"), front<_1>>::type + ::rule<_STR("plus_token ::= '+' ws"), front<_1>>::type + ::rule<_STR("minus_token ::= '-' ws"), front<_1>>::type + ::rule<_STR("mult_token ::= '*' ws"), front<_1>>::type + ::rule<_STR("div_token ::= '/' ws"), front<_1>>::type + ::rule<_STR("plus_token ::= '+' ws")>::type + ::rule<_STR("plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)*"), plus_action>::type + ::rule<_STR("prod_exp ::= int_token ((mult_token | div_token) int_token)*"), prod_action>::type + expression; + +typedef build_parser<entire_input<expression>> calculator_parser; + +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1<calculator_parser, _STR("13")>::type::value << endl + << apply_wrap1<calculator_parser, _STR("1+ 2*4-6/2")>::type::value << endl + ; +} +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/Jamfile.v2 b/src/boost/libs/metaparse/example/meta_hs/Jamfile.v2 new file mode 100644 index 000000000..84d5c3c12 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/Jamfile.v2 @@ -0,0 +1,11 @@ + +project meta_hs : + requirements + <include>. + <toolset>gcc:<cxxflags>-ftemplate-depth=512 + <toolset>clang:<cxxflags>-ftemplate-depth=512 + ; + +exe handcrafted : main_handcrafted.cpp ; +exe in_haskell : main_in_haskell.cpp ; + diff --git a/src/boost/libs/metaparse/example/meta_hs/README b/src/boost/libs/metaparse/example/meta_hs/README new file mode 100644 index 000000000..0afcc4eb8 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/README @@ -0,0 +1,4 @@ +Haskell-like functional EDSL for template metafunctions. +This example contains two programs. Both of them define and execute a few +template metaprograms. One of the do it by using Boost.MPL directly, while the +other one defines the template metaprograms using the EDSL. diff --git a/src/boost/libs/metaparse/example/meta_hs/ast.hpp b/src/boost/libs/metaparse/example/meta_hs/ast.hpp new file mode 100644 index 000000000..68f25eaf9 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/ast.hpp @@ -0,0 +1,43 @@ +#ifndef META_HS_AST_HPP +#define META_HS_AST_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +namespace ast +{ + template <class V> + struct value + { + typedef value type; + }; + + template <class Name> + struct ref + { + typedef ref type; + }; + + template <class F, class Arg> + struct application + { + typedef application type; + }; + + template <class F, class ArgName> + struct lambda + { + typedef lambda type; + }; + + template <class E> + struct top_bound + { + typedef top_bound type; + }; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/bind.hpp b/src/boost/libs/metaparse/example/meta_hs/bind.hpp new file mode 100644 index 000000000..29316084a --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/bind.hpp @@ -0,0 +1,63 @@ +#ifndef META_HS_BIND_HPP +#define META_HS_BIND_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <lazy.hpp> +#include <ast.hpp> + +#include <boost/mpl/at.hpp> +#include <boost/mpl/insert.hpp> +#include <boost/mpl/pair.hpp> + +template <class AST, class TopEnv, class Env> +struct bind; + +template <class V, class TopEnv, class Env> +struct bind<ast::value<V>, TopEnv, Env> +{ + typedef lazy::value<V> type; +}; + +template <class Name, class TopEnv, class Env> +struct bind<ast::ref<Name>, TopEnv, Env> : + bind<typename boost::mpl::at<Env, Name>::type, TopEnv, Env> +{}; + +template <class F, class Arg, class TopEnv, class Env> +struct bind<ast::application<F, Arg>, TopEnv, Env> +{ + typedef + lazy::application< + typename bind<F, TopEnv, Env>::type, + typename bind<Arg, TopEnv, Env>::type + > + type; +}; + +template <class F, class ArgName, class TopEnv, class Env> +struct bind<ast::lambda<F, ArgName>, TopEnv, Env> +{ + typedef bind type; + + template <class ArgValue> + struct apply : + bind< + F, + TopEnv, + typename boost::mpl::insert< + Env, + boost::mpl::pair<ArgName, ast::value<ArgValue> > + >::type + >::type + {}; +}; + +template <class E, class TopEnv, class Env> +struct bind<ast::top_bound<E>, TopEnv, Env> : bind<E, TopEnv, TopEnv> {}; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/builder.hpp b/src/boost/libs/metaparse/example/meta_hs/builder.hpp new file mode 100644 index 000000000..b49a06a33 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/builder.hpp @@ -0,0 +1,80 @@ +#ifndef META_HS_EXCEPT_BUILDER_HPP +#define META_HS_EXCEPT_BUILDER_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <grammar.hpp> +#include <ast.hpp> +#include <bind.hpp> +#include <curry.hpp> + +#include <boost/mpl/map.hpp> +#include <boost/mpl/insert.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/pair.hpp> +#include <boost/mpl/apply_wrap.hpp> + +#include <boost/preprocessor/repetition/enum.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/repetition/repeat_from_to.hpp> +#include <boost/preprocessor/tuple/eat.hpp> + +typedef boost::mpl::map<> empty_environment; + +template <class Env = empty_environment> +struct builder +{ + typedef builder type; + + template <class Name, class Value> + struct import : + builder< + typename boost::mpl::insert< + Env, + boost::mpl::pair<Name, ast::value<Value> > + >::type + > + {}; + +#ifdef IMPORT +# error IMPORT already defined +#endif +#define IMPORT(z, n, unused) \ + template < \ + class Name, \ + template <BOOST_PP_ENUM(n, class BOOST_PP_TUPLE_EAT(3), ~)> class F \ + > \ + struct BOOST_PP_CAT(import, n) : \ + builder< \ + typename boost::mpl::insert< \ + Env, \ + boost::mpl::pair<Name, ast::value<BOOST_PP_CAT(curry, n)<F> > > \ + >::type \ + > \ + {}; + +BOOST_PP_REPEAT_FROM_TO(1, CURRY_MAX_ARGUMENT, IMPORT, ~) + +#undef IMPORT + + template <class S> + struct define : + builder< + typename boost::mpl::insert< + Env, + typename boost::mpl::apply_wrap1<grammar::def_parser, S>::type + >::type + > + {}; + + template <class S> + struct get : + bind<typename boost::mpl::at<Env, S>::type, Env, Env>::type::type + {}; +}; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/curry.hpp b/src/boost/libs/metaparse/example/meta_hs/curry.hpp new file mode 100644 index 000000000..5ca1711d3 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/curry.hpp @@ -0,0 +1,106 @@ +#ifndef BOOST_METAPARSE_META_HS_CURRY_HPP +#define BOOST_METAPARSE_META_HS_CURRY_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/apply.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/unpack_args.hpp> +#include <boost/mpl/deque.hpp> +#include <boost/mpl/quote.hpp> + +#include <boost/preprocessor/repetition/repeat_from_to.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/enum.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/tuple/eat.hpp> + +#ifndef CURRY_MAX_ARGUMENT +# define CURRY_MAX_ARGUMENT 5 +#endif + +namespace impl +{ + template < + class UnpackedMetafunctionClass, + class ArgumentsLeft, + class ArgumentList + > + struct curry_impl; + + + + template < + class UnpackedMetafunctionClass, + class ArgumentsLeft, + class ArgumentList + > + struct next_currying_step + { + typedef next_currying_step type; + + template <class T> + struct apply : + curry_impl< + UnpackedMetafunctionClass, + typename boost::mpl::minus< + ArgumentsLeft, + boost::mpl::int_<1> + >::type, + typename boost::mpl::push_back<ArgumentList, T>::type + > + {}; + }; + + + template < + class UnpackedMetafunctionClass, + class ArgumentsLeft, + class ArgumentList + > + struct curry_impl : + boost::mpl::eval_if< + typename boost::mpl::equal_to< + ArgumentsLeft, + boost::mpl::int_<0> + >::type, + boost::mpl::apply<UnpackedMetafunctionClass, ArgumentList>, + next_currying_step< + UnpackedMetafunctionClass, + ArgumentsLeft, + ArgumentList + > + > + {}; +} + + +template <class T> +struct curry0 : T {}; + +#ifdef CURRY +# error CURRY already defined +#endif +#define CURRY(z, n, unused) \ + template <template <BOOST_PP_ENUM(n,class BOOST_PP_TUPLE_EAT(3),~)> class T> \ + struct BOOST_PP_CAT(curry, n) : \ + impl::curry_impl< \ + boost::mpl::unpack_args<boost::mpl::BOOST_PP_CAT(quote, n) <T> >, \ + boost::mpl::int_<n>, \ + boost::mpl::deque<> \ + >::type \ + {}; + +BOOST_PP_REPEAT_FROM_TO(1, CURRY_MAX_ARGUMENT, CURRY, ~) + +#undef CURRY + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/double_number.hpp b/src/boost/libs/metaparse/example/meta_hs/double_number.hpp new file mode 100644 index 000000000..03d338c8c --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/double_number.hpp @@ -0,0 +1,18 @@ +#ifndef DOUBLE_NUMBER_HPP +#define DOUBLE_NUMBER_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/int.hpp> +#include <boost/mpl/times.hpp> + +template <class N> +struct double_number : + boost::mpl::times<typename N::type, boost::mpl::int_<2> > +{}; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/example_handcrafted.hpp b/src/boost/libs/metaparse/example/meta_hs/example_handcrafted.hpp new file mode 100644 index 000000000..b38441c93 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/example_handcrafted.hpp @@ -0,0 +1,93 @@ +#ifndef EXAMPLE_HANDCRAFTED_HPP +#define EXAMPLE_HANDCRAFTED_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <double_number.hpp> + +#include <boost/mpl/int.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/less.hpp> + +typedef boost::mpl::int_<11> val; + +struct fib +{ + typedef fib type; + + template <class N> + struct impl; + + template <class N> + struct apply : + boost::mpl::eval_if< + typename boost::mpl::less<N, boost::mpl::int_<2> >::type, + boost::mpl::int_<1>, + impl<N> + > + {}; +}; + +template <class N> +struct fib::impl : + boost::mpl::plus< + typename fib::apply< + typename boost::mpl::minus<N, boost::mpl::int_<1> >::type + >::type, + typename fib::apply< + typename boost::mpl::minus<N, boost::mpl::int_<2> >::type + >::type + > +{}; + +struct fact +{ + typedef fact type; + + template <class N> + struct impl; + + template <class N> + struct apply : + boost::mpl::eval_if< + typename boost::mpl::less<N, boost::mpl::int_<1> >::type, + boost::mpl::int_<1>, + impl<N> + > + {}; +}; + +template <class N> +struct fact::impl : + boost::mpl::times< + N, + typename fact::apply< + typename boost::mpl::minus<N, boost::mpl::int_<1> >::type + >::type + > +{}; + +struct times4 +{ + typedef times4 type; + + template <class N> + struct apply : double_number<typename double_number<N>::type> {}; +}; + +struct times11 +{ + typedef times11 type; + + template <class N> + struct apply : boost::mpl::times<N, val> {}; +}; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/example_in_haskell.hpp b/src/boost/libs/metaparse/example/meta_hs/example_in_haskell.hpp new file mode 100644 index 000000000..7642eca6b --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/example_in_haskell.hpp @@ -0,0 +1,53 @@ +#ifndef EXAMPLE_IN_HASKELL_HPP +#define EXAMPLE_IN_HASKELL_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/config.hpp> + +#if BOOST_METAPARSE_STD < 2011 + +// We have to fall back on the handcrafted one +#include <example_handcrafted.hpp> + +#else + +#define BOOST_MPL_LIMIT_STRING_SIZE 50 +#define BOOST_METAPARSE_LIMIT_STRING_SIZE BOOST_MPL_LIMIT_STRING_SIZE + +#include <meta_hs.hpp> +#include <double_number.hpp> + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/int.hpp> + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +typedef + meta_hs + ::import1<_STR("f"), double_number>::type + ::import<_STR("val"), boost::mpl::int_<11> >::type + + ::define<_STR("fib n = if n<2 then 1 else fib(n-2) + fib(n-1)")>::type + ::define<_STR("fact n = if n<1 then 1 else n * fact(n-1)")>::type + ::define<_STR("times4 n = f (f n)")>::type + ::define<_STR("times11 n = n * val")>::type + metafunctions; + +typedef metafunctions::get<_STR("fib")> fib; +typedef metafunctions::get<_STR("fact")> fact; +typedef metafunctions::get<_STR("times4")> times4; +typedef metafunctions::get<_STR("times11")> times11; + +#endif + +#endif + + diff --git a/src/boost/libs/metaparse/example/meta_hs/except_keywords.hpp b/src/boost/libs/metaparse/example/meta_hs/except_keywords.hpp new file mode 100644 index 000000000..b6700f008 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/except_keywords.hpp @@ -0,0 +1,61 @@ +#ifndef META_HS_EXCEPT_KEYWORDS_HPP +#define META_HS_EXCEPT_KEYWORDS_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/accept_when.hpp> + +#include <boost/mpl/equal.hpp> +#include <boost/mpl/and.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/fold.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/apply_wrap.hpp> + +struct keywords_are_not_allowed {}; + +template <class P, class Keywords> +class except_keywords +{ +private: + template <class T> + struct not_a_keyword + { + typedef not_a_keyword type; + + template <class Acc, class Keyword> + struct apply : + boost::mpl::and_< + Acc, + boost::mpl::not_<typename boost::mpl::equal<T, Keyword>::type> + > + {}; + }; + + struct not_keyword + { + typedef not_keyword type; + + template <class T> + struct apply : + boost::mpl::fold<Keywords, boost::mpl::true_, not_a_keyword<T> > + {}; + }; +public: + typedef except_keywords type; + + template <class S, class Pos> + struct apply : + boost::mpl::apply_wrap2< + boost::metaparse::accept_when<P, not_keyword, keywords_are_not_allowed>, + S, + Pos + > + {}; +}; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/grammar.hpp b/src/boost/libs/metaparse/example/meta_hs/grammar.hpp new file mode 100644 index 000000000..e4bcf0b63 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/grammar.hpp @@ -0,0 +1,130 @@ +#ifndef META_HS_GRAMMAR_HPP +#define META_HS_GRAMMAR_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <token.hpp> +#include <semantic.hpp> + +#include <boost/metaparse/middle_of.hpp> +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/foldr_start_with_parser.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/build_parser.hpp> + +namespace grammar +{ + /* + * The grammar + * + * definition ::= token::name+ token::define expression + * expression ::= cmp_exp + * cmp_exp ::= plus_exp (token::cmp plus_exp)* + * plus_exp ::= mult_exp ((token::plus | token::minus) mult_exp)* + * mult_exp ::= application ((token::mult | token::div) application)* + * application ::= single_exp+ + * single_exp ::= if_exp | token::name | token::int_ | bracket_exp + * if_exp ::= token::if_ expression token::then expression token::else_ expression + * bracket_exp ::= token::open_bracket expression token::close_bracket + */ + + struct expression; + + typedef + boost::metaparse::middle_of< + token::open_bracket, + expression, + token::close_bracket + > + bracket_exp; + + typedef + boost::metaparse::transform< + boost::metaparse::sequence< + boost::metaparse::last_of<token::if_, expression>, + boost::metaparse::last_of<token::then, expression>, + boost::metaparse::last_of<token::else_, expression> + >, + semantic::if_ + > + if_exp; + + typedef + boost::metaparse::one_of< + if_exp, + boost::metaparse::transform<token::name, semantic::ref>, + boost::metaparse::transform<token::int_, semantic::value>, + bracket_exp + > + single_exp; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + single_exp, + single_exp, + semantic::application + > + application; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + boost::metaparse::sequence< + boost::metaparse::one_of<token::mult, token::div>, + application + >, + application, + semantic::binary_op + > + mult_exp; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + boost::metaparse::sequence< + boost::metaparse::one_of<token::plus, token::minus>, + mult_exp + >, + mult_exp, + semantic::binary_op + > + plus_exp; + + typedef + boost::metaparse::foldl_reject_incomplete_start_with_parser< + boost::metaparse::sequence<token::cmp, plus_exp>, + plus_exp, + semantic::binary_op + > + cmp_exp; + + struct expression : cmp_exp {}; + + typedef + boost::metaparse::transform< + boost::metaparse::sequence< + token::name, + boost::metaparse::foldr_start_with_parser< + token::name, + boost::metaparse::last_of<token::define, expression>, + semantic::lambda + > + >, + semantic::pair + > + definition; + + typedef + boost::metaparse::build_parser< + boost::metaparse::entire_input<definition> + > + def_parser; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/lazy.hpp b/src/boost/libs/metaparse/example/meta_hs/lazy.hpp new file mode 100644 index 000000000..c3a3cf832 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/lazy.hpp @@ -0,0 +1,24 @@ +#ifndef META_HS_LAZY_HPP +#define META_HS_LAZY_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/mpl/apply_wrap.hpp> + +namespace lazy +{ + template <class V> + struct value + { + typedef V type; + }; + + template <class F, class Arg> + struct application : boost::mpl::apply_wrap1<typename F::type, Arg>::type {}; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/main_handcrafted.cpp b/src/boost/libs/metaparse/example/meta_hs/main_handcrafted.cpp new file mode 100644 index 000000000..33df728fa --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/main_handcrafted.cpp @@ -0,0 +1,20 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <example_handcrafted.hpp> + +#include <iostream> + +int main() +{ + using boost::mpl::int_; + + std::cout + << "fib 6 = " << fib::apply<int_<6> >::type::value << std::endl + << "fact 4 = " << fact::apply<int_<4> >::type::value << std::endl + << "times4 3 = " << times4::apply<int_<3> >::type::value << std::endl + << "times11 2 = " << times11::apply<int_<2> >::type::value << std::endl; +} + diff --git a/src/boost/libs/metaparse/example/meta_hs/main_in_haskell.cpp b/src/boost/libs/metaparse/example/meta_hs/main_in_haskell.cpp new file mode 100644 index 000000000..af10d9a8e --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/main_in_haskell.cpp @@ -0,0 +1,20 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <example_in_haskell.hpp> + +#include <iostream> + +int main() +{ + using boost::mpl::int_; + + std::cout + << "fib 6 = " << fib::apply<int_<6> >::type::value << std::endl + << "fact 4 = " << fact::apply<int_<4> >::type::value << std::endl + << "times4 3 = " << times4::apply<int_<3> >::type::value << std::endl + << "times11 2 = " << times11::apply<int_<2> >::type::value << std::endl; +} + diff --git a/src/boost/libs/metaparse/example/meta_hs/meta_hs.hpp b/src/boost/libs/metaparse/example/meta_hs/meta_hs.hpp new file mode 100644 index 000000000..061b442a7 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/meta_hs.hpp @@ -0,0 +1,64 @@ +#ifndef META_HS_META_HS_HPP +#define META_HS_META_HS_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <builder.hpp> + +#include <boost/mpl/plus.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/divides.hpp> +#include <boost/mpl/less.hpp> +#include <boost/mpl/less_equal.hpp> +#include <boost/mpl/greater.hpp> +#include <boost/mpl/greater_equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/not_equal_to.hpp> + +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/seq/for_each.hpp> + +#ifdef DEFINE_LAZY + #error DEFINE_LAZY already defined +#endif +#define DEFINE_LAZY(r, unused, name) \ + template <class A, class B> \ + struct BOOST_PP_CAT(lazy_, name) : \ + boost::mpl::name<typename A::type, typename B::type> \ + {}; + +BOOST_PP_SEQ_FOR_EACH(DEFINE_LAZY, ~, + (plus) + (minus) + (times) + (divides) + (less) + (less_equal) + (greater) + (greater_equal) + (equal_to) + (not_equal_to) +) + +#undef DEFINE_LAZY + +typedef builder<> + ::import2<boost::metaparse::string<'.','+','.'>, lazy_plus>::type + ::import2<boost::metaparse::string<'.','-','.'>, lazy_minus>::type + ::import2<boost::metaparse::string<'.','*','.'>, lazy_times>::type + ::import2<boost::metaparse::string<'.','/','.'>, lazy_divides>::type + ::import2<boost::metaparse::string<'.','<','.'>, lazy_less>::type + ::import2<boost::metaparse::string<'.','<','=','.'>, lazy_less_equal>::type + ::import2<boost::metaparse::string<'.','>','.'>, lazy_greater>::type + ::import2<boost::metaparse::string<'.','>','=','.'>, lazy_greater_equal>::type + ::import2<boost::metaparse::string<'.','=','=','.'>, lazy_equal_to>::type + ::import2<boost::metaparse::string<'.','/','=','.'>, lazy_not_equal_to>::type + + meta_hs; + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/semantic.hpp b/src/boost/libs/metaparse/example/meta_hs/semantic.hpp new file mode 100644 index 000000000..42ad42217 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/semantic.hpp @@ -0,0 +1,115 @@ +#ifndef META_HS_SEMANTIC_HPP +#define META_HS_SEMANTIC_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <ast.hpp> +#include <curry.hpp> + +#include <boost/mpl/if.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/pair.hpp> + +namespace semantic +{ + struct ref + { + typedef ref type; + + template <class Name> + struct apply : ast::ref<Name> {}; + }; + + struct value + { + typedef value type; + + template <class V> + struct apply : ast::value<V> {}; + }; + + struct lambda + { + typedef lambda type; + + template <class F, class ArgName> + struct apply : ast::lambda<F, ArgName> {}; + }; + + struct application + { + typedef application type; + + template <class F, class Arg> + struct apply : ast::application<F, Arg> {}; + }; + + class if_ + { + private: + template <class C, class T, class F> + struct lazy_if : boost::mpl::if_<typename C::type, T, F> {}; + public: + typedef if_ type; + + template <class Seq> + struct apply : + boost::mpl::apply_wrap2< + application, + typename boost::mpl::apply_wrap2< + application, + typename boost::mpl::apply_wrap2< + application, + ast::value<curry3<lazy_if> >, + typename boost::mpl::at_c<Seq, 0>::type + >::type, + typename boost::mpl::at_c<Seq, 1>::type + >::type, + typename boost::mpl::at_c<Seq, 2>::type + > + {}; + }; + + struct binary_op + { + typedef binary_op type; + + template <class Exp, class C> + struct apply : + boost::mpl::apply_wrap2< + application, + typename boost::mpl::apply_wrap2< + application, + typename boost::mpl::apply_wrap1< + ref, + typename boost::mpl::front<C>::type + >::type, + Exp + >::type, + typename boost::mpl::back<C>::type + > + {}; + }; + + struct pair + { + typedef pair type; + + template <class Seq> + struct apply : + boost::mpl::pair< + typename boost::mpl::front<Seq>::type, + ast::top_bound<typename boost::mpl::back<Seq>::type> + > + {}; + }; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_hs/token.hpp b/src/boost/libs/metaparse/example/meta_hs/token.hpp new file mode 100644 index 000000000..23ec0bf79 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_hs/token.hpp @@ -0,0 +1,168 @@ +#ifndef META_HS_TOKEN_HPP +#define META_HS_TOKEN_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <ast.hpp> +#include <except_keywords.hpp> + +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/always_c.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/return_.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/alphanum.hpp> +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/optional.hpp> + +#include <boost/mpl/lambda.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/vector.hpp> + +namespace token +{ + typedef + boost::metaparse::token< + boost::metaparse::always_c<'+',boost::metaparse::string<'.','+','.'> > + > + plus; + + typedef + boost::metaparse::token< + boost::metaparse::always_c<'-',boost::metaparse::string<'.','-','.'> > + > + minus; + + typedef + boost::metaparse::token< + boost::metaparse::always_c<'*',boost::metaparse::string<'.','*','.'> > + > + mult; + + typedef + boost::metaparse::token< + boost::metaparse::always_c<'/',boost::metaparse::string<'.','/','.'> > + > + div; + + typedef + boost::metaparse::token< + boost::metaparse::one_of< + boost::metaparse::last_of< + boost::metaparse::lit_c<'='>, + boost::metaparse::lit_c<'='>, + boost::metaparse::return_< + boost::metaparse::string<'.','=','=','.'> + > + >, + boost::metaparse::last_of< + boost::metaparse::lit_c<'/'>, + boost::metaparse::lit_c<'='>, + boost::metaparse::return_< + boost::metaparse::string<'.','/','=','.'> + > + >, + boost::metaparse::last_of< + boost::metaparse::lit_c<'<'>, + boost::metaparse::one_of< + boost::metaparse::always_c< + '=', + boost::metaparse::string<'.','<','=','.'> + >, + boost::metaparse::return_< + boost::metaparse::string<'.','<','.'> + > + > + >, + boost::metaparse::last_of< + boost::metaparse::lit_c<'>'>, + boost::metaparse::optional< + boost::metaparse::always_c< + '=', + boost::metaparse::string<'.','>','=','.'> + >, + boost::metaparse::string<'.','>','.'> + > + > + > + > + cmp; + + typedef + boost::metaparse::token<boost::metaparse::lit_c<'('> > + open_bracket; + + typedef + boost::metaparse::token<boost::metaparse::lit_c<')'> > + close_bracket; + + typedef + boost::metaparse::token<boost::metaparse::lit_c<'='> > + define; + + typedef boost::metaparse::token<boost::metaparse::int_> int_; + + typedef + boost::metaparse::token< + except_keywords< + boost::metaparse::foldl_reject_incomplete_start_with_parser< + boost::metaparse::one_of< + boost::metaparse::alphanum, + boost::metaparse::lit_c<'_'> + >, + boost::metaparse::transform< + boost::metaparse::one_of< + boost::metaparse::letter, + boost::metaparse::lit_c<'_'> + >, + boost::mpl::lambda< + boost::mpl::push_back< + boost::metaparse::string<>, + boost::mpl::_1 + > + >::type + >, + boost::mpl::lambda< + boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2> + >::type + >, + boost::mpl::vector< + boost::metaparse::string<'i','f'>, + boost::metaparse::string<'t','h','e','n'>, + boost::metaparse::string<'e','l','s','e'> + > + > + > + name; + + typedef + boost::metaparse::token< + boost::metaparse::keyword<boost::metaparse::string<'i','f'> > + > + if_; + + typedef + boost::metaparse::token< + boost::metaparse::keyword<boost::metaparse::string<'t','h','e','n'> > + > + then; + + typedef + boost::metaparse::token< + boost::metaparse::keyword<boost::metaparse::string<'e','l','s','e'> > + > + else_; +} + +#endif + + diff --git a/src/boost/libs/metaparse/example/meta_lambda/Jamfile.v2 b/src/boost/libs/metaparse/example/meta_lambda/Jamfile.v2 new file mode 100644 index 000000000..fcaeae093 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_lambda/Jamfile.v2 @@ -0,0 +1 @@ +exe meta_lambda : main.cpp ; diff --git a/src/boost/libs/metaparse/example/meta_lambda/README b/src/boost/libs/metaparse/example/meta_lambda/README new file mode 100644 index 000000000..f55faff95 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_lambda/README @@ -0,0 +1 @@ +An example on how to compile an EDSL into a C++ template metaprogram. diff --git a/src/boost/libs/metaparse/example/meta_lambda/main.cpp b/src/boost/libs/metaparse/example/meta_lambda/main.cpp new file mode 100644 index 000000000..892e5756f --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_lambda/main.cpp @@ -0,0 +1,265 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/space.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/build_parser.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/plus.hpp> +#include <boost/mpl/minus.hpp> +#include <boost/mpl/times.hpp> +#include <boost/mpl/divides.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/if.hpp> + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; +using boost::metaparse::transform; +using boost::metaparse::always; + +using boost::mpl::apply_wrap1; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::if_; +using boost::mpl::bool_; +using boost::mpl::equal_to; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= value_exp ((mult_token | div_token) value_exp)* + * value_exp ::= int_token | '_' + */ + +typedef token<lit_c<'+'> > plus_token; +typedef token<lit_c<'-'> > minus_token; +typedef token<lit_c<'*'> > mult_token; +typedef token<lit_c<'/'> > div_token; + +typedef token<int_> int_token; +typedef token<lit_c<'_'> > arg_token; + +template <class T, char C> +struct is_c : bool_<T::type::value == C> {}; + +struct build_plus +{ + template <class A, class B> + struct _plus + { + typedef _plus type; + + template <class T> + struct apply : + plus<typename apply_wrap1<A, T>::type, typename apply_wrap1<B, T>::type> + {}; + }; + + template <class A, class B> + struct _minus + { + typedef _minus type; + + template <class T> + struct apply : + minus<typename apply_wrap1<A, T>::type, typename apply_wrap1<B, T>::type> + {}; + }; + + template <class State, class C> + struct apply : + if_< + typename is_c<front<C>, '+'>::type, + _plus<State, typename back<C>::type>, + _minus<State, typename back<C>::type> + > + {}; +}; + +struct build_mult +{ + template <class A, class B> + struct _mult + { + typedef _mult type; + + template <class T> + struct apply : + times<typename apply_wrap1<A, T>::type, typename apply_wrap1<B, T>::type> + {}; + }; + + template <class A, class B> + struct _div + { + typedef _div type; + + template <class T> + struct apply : + divides< + typename apply_wrap1<A, T>::type, + typename apply_wrap1<B, T>::type + > + {}; + }; + + template <class State, class C> + struct apply : + if_< + typename is_c<front<C>, '*'>::type, + _mult<State, typename back<C>::type>, + _div<State, typename back<C>::type> + > + {}; +}; + +class build_value +{ +private: + template <class V> + struct impl + { + typedef impl type; + + template <class T> + struct apply : V {}; + }; + +public: + typedef build_value type; + + template <class V> + struct apply : impl<typename V::type> {}; +}; + +struct arg +{ + typedef arg type; + + template <class T> + struct apply + { + typedef T type; + }; +}; + +typedef + one_of<transform<int_token, build_value>, always<arg_token, arg> > + value_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<mult_token, div_token>, value_exp>, + value_exp, + build_mult + > + prod_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence<one_of<plus_token, minus_token>, prod_exp>, + prod_exp, + build_plus + > + plus_exp; + +typedef last_of<repeated<space>, plus_exp> expression; + +typedef build_parser<entire_input<expression> > metafunction_parser; + +#if BOOST_METAPARSE_STD < 2011 + +template <class Exp> +struct meta_lambda : apply_wrap1<metafunction_parser, Exp> {}; + +int main() +{ + using std::cout; + using std::endl; + using boost::metaparse::string; + + typedef meta_lambda<string<'1','3'> >::type metafunction_class_1; + typedef meta_lambda<string<'2',' ','+',' ','3'> >::type metafunction_class_2; + typedef meta_lambda<string<'2',' ','*',' ','2'> >::type metafunction_class_3; + typedef + meta_lambda<string<' ','1','+',' ','2','*','4','-','6','/','2'> >::type + metafunction_class_4; + typedef meta_lambda<string<'2',' ','*',' ','_'> >::type metafunction_class_5; + + typedef boost::mpl::int_<11> int11; + + cout + << apply_wrap1<metafunction_class_1, int11>::type::value << endl + << apply_wrap1<metafunction_class_2, int11>::type::value << endl + << apply_wrap1<metafunction_class_3, int11>::type::value << endl + << apply_wrap1<metafunction_class_4, int11>::type::value << endl + << apply_wrap1<metafunction_class_5, int11>::type::value << endl + ; +} + +#else + +#ifdef META_LAMBDA + #error META_LAMBDA already defined +#endif +#define META_LAMBDA(exp) \ + apply_wrap1<metafunction_parser, BOOST_METAPARSE_STRING(#exp)>::type + +int main() +{ + using std::cout; + using std::endl; + + typedef META_LAMBDA(13) metafunction_class_1; + typedef META_LAMBDA(2 + 3) metafunction_class_2; + typedef META_LAMBDA(2 * 2) metafunction_class_3; + typedef META_LAMBDA( 1+ 2*4-6/2) metafunction_class_4; + typedef META_LAMBDA(2 * _) metafunction_class_5; + + typedef boost::mpl::int_<11> int11; + + cout + << apply_wrap1<metafunction_class_1, int11>::type::value << endl + << apply_wrap1<metafunction_class_2, int11>::type::value << endl + << apply_wrap1<metafunction_class_3, int11>::type::value << endl + << apply_wrap1<metafunction_class_4, int11>::type::value << endl + << apply_wrap1<metafunction_class_5, int11>::type::value << endl + ; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/meta_metaparse/Jamfile.v2 b/src/boost/libs/metaparse/example/meta_metaparse/Jamfile.v2 new file mode 100644 index 000000000..404a50065 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_metaparse/Jamfile.v2 @@ -0,0 +1,6 @@ +project : requirements + <toolset>gcc:<cxxflags>-ftemplate-depth=512 + <toolset>clang:<cxxflags>-ftemplate-depth=512 +; + +exe meta_metaparse : main.cpp ; diff --git a/src/boost/libs/metaparse/example/meta_metaparse/README b/src/boost/libs/metaparse/example/meta_metaparse/README new file mode 100644 index 000000000..a4d4a64b5 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_metaparse/README @@ -0,0 +1 @@ +This example demonstrates how to build an embedded DSL for Metaparse parsers. diff --git a/src/boost/libs/metaparse/example/meta_metaparse/main.cpp b/src/boost/libs/metaparse/example/meta_metaparse/main.cpp new file mode 100644 index 000000000..442549835 --- /dev/null +++ b/src/boost/libs/metaparse/example/meta_metaparse/main.cpp @@ -0,0 +1,258 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_MPL_LIMIT_STRING_SIZE 64 +#define BOOST_METAPARSE_LIMIT_STRING_SIZE BOOST_MPL_LIMIT_STRING_SIZE + +#include <boost/metaparse/grammar.hpp> + +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/build_parser.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/transform.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/fold.hpp> + +using boost::mpl::apply_wrap1; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::if_; +using boost::mpl::bool_; + +using boost::metaparse::build_parser; +using boost::metaparse::token; +using boost::metaparse::entire_input; +using boost::metaparse::int_; +using boost::metaparse::grammar; +using boost::metaparse::transform; + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + std::cout << "Please use a compiler that supports constexpr" << std::endl; +} +#else + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +template <class T, char C> +struct is_c : bool_<T::type::value == C> {}; + +struct build_plus_impl +{ + template <class A, class B> + class _plus + { + public: + typedef _plus type; + + template <class T> + T operator()(T t) const + { + return _left(t) + _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class A, class B> + class _minus + { + public: + typedef _minus type; + + template <class T> + T operator()(T t) const + { + return _left(t) - _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class State, class C> + struct apply : + if_< + typename is_c<front<C>, '+'>::type, + _plus<State, typename back<C>::type>, + _minus<State, typename back<C>::type> + > + {}; +}; + +struct build_plus +{ + typedef build_plus type; + + template <class Seq> + struct apply : + boost::mpl::fold< + typename back<Seq>::type, + typename front<Seq>::type, + build_plus_impl + > + {}; +}; + +struct build_mult_impl +{ + template <class A, class B> + class _mult + { + public: + typedef _mult type; + + template <class T> + T operator()(T t) const + { + return _left(t) * _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class A, class B> + class _div + { + public: + typedef _div type; + + template <class T> + T operator()(T t) const + { + return _left(t) / _right(t); + } + private: + typename A::type _left; + typename B::type _right; + }; + + template <class State, class C> + struct apply : + if_< + typename is_c<front<C>, '*'>::type, + _mult<State, typename back<C>::type>, + _div<State, typename back<C>::type> + > + {}; +}; + +struct build_mult +{ + typedef build_mult type; + + template <class Seq> + struct apply : + boost::mpl::fold< + typename back<Seq>::type, + typename front<Seq>::type, + build_mult_impl + > + {}; +}; + +struct build_value +{ + typedef build_value type; + + template <class V> + struct apply + { + typedef apply type; + + template <class T> + int operator()(T) const + { + return V::type::value; + } + }; +}; + +struct build_arg +{ + typedef build_arg type; + + template <class> + struct apply + { + typedef apply type; + + template <class T> + T operator()(T t) const + { + return t; + } + }; +}; + +struct keep_front +{ + typedef keep_front type; + + template <class Seq> + struct apply : front<Seq> {}; +}; + +typedef + grammar<_STR("plus_exp")> + ::import<_STR("int_token"), token<transform<int_, build_value>>>::type + + ::rule<_STR("ws ::= (' ' | '\n' | '\r' | '\t')*")>::type + ::rule<_STR("plus_token ::= '+' ws"), keep_front>::type + ::rule<_STR("minus_token ::= '-' ws"), keep_front>::type + ::rule<_STR("mult_token ::= '*' ws"), keep_front>::type + ::rule<_STR("div_token ::= '/' ws"), keep_front>::type + ::rule<_STR("arg_token ::= '_' ws"), keep_front>::type + + ::rule<_STR("plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)*"), build_plus>::type + ::rule<_STR("prod_exp ::= value_exp ((mult_token | div_token) value_exp)*"), build_mult>::type + ::rule<_STR("value_exp ::= int_token | arg_exp")>::type + ::rule<_STR("arg_exp ::= arg_token"), build_arg>::type + g; + +typedef build_parser<entire_input<g>> function_parser; + +#ifdef LAMBDA + #error LAMBDA already defined +#endif +#define LAMBDA(exp) apply_wrap1<function_parser, _STR(#exp)>::type + +LAMBDA(13) f1; +LAMBDA(2 + 3) f2; +LAMBDA(2 * 3) f3; +LAMBDA(1+ 2*4-6/2) f4; +LAMBDA(2 * _) f5; + +int main() +{ + using std::cout; + using std::endl; + + cout + << f1(11) << endl + << f2(11) << endl + << f3(11) << endl + << f4(11) << endl + << f5(11) << endl + << f5(1.1) << endl + ; +} + +#endif + + diff --git a/src/boost/libs/metaparse/example/minimal_rational/Jamfile.v2 b/src/boost/libs/metaparse/example/minimal_rational/Jamfile.v2 new file mode 100644 index 000000000..6f9000d56 --- /dev/null +++ b/src/boost/libs/metaparse/example/minimal_rational/Jamfile.v2 @@ -0,0 +1 @@ +exe minimal_rational : main.cpp ; diff --git a/src/boost/libs/metaparse/example/minimal_rational/README b/src/boost/libs/metaparse/example/minimal_rational/README new file mode 100644 index 000000000..6444e01d6 --- /dev/null +++ b/src/boost/libs/metaparse/example/minimal_rational/README @@ -0,0 +1,3 @@ +Parser for rational numbers. The aim is to present a very simple parser, +therefore error messages for invalid input can be improved. To see a more +advanced version, take a look at the rational example. diff --git a/src/boost/libs/metaparse/example/minimal_rational/main.cpp b/src/boost/libs/metaparse/example/minimal_rational/main.cpp new file mode 100644 index 000000000..3d6fd3ff6 --- /dev/null +++ b/src/boost/libs/metaparse/example/minimal_rational/main.cpp @@ -0,0 +1,79 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/sequence_apply.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/build_parser.hpp> + +#include <boost/rational.hpp> + +#include <boost/config.hpp> + +#include <iostream> + +using boost::metaparse::sequence_apply2; +using boost::metaparse::last_of; +using boost::metaparse::int_; +using boost::metaparse::token; +using boost::metaparse::lit_c; +using boost::metaparse::entire_input; +using boost::metaparse::build_parser; + +template <class Num, class Denom> +struct rational +{ + typedef rational type; + + static boost::rational<int> run() + { + return boost::rational<int>(Num::type::value, Denom::type::value); + } +}; + +typedef + sequence_apply2< + rational, + + token<int_>, + last_of<lit_c<'/'>, token<int_> > + > + rational_grammar; + +typedef build_parser<entire_input<rational_grammar> > rational_parser; + +#ifdef RATIONAL +# error RATIONAL already defined +#endif +#define RATIONAL(s) \ + (::rational_parser::apply<BOOST_METAPARSE_STRING(s)>::type::run()) + +#if BOOST_METAPARSE_STD < 2011 + +int main() +{ + std::cout << "Please use a compiler that supports constexpr" << std::endl; +} + +#else + +int main() +{ + const boost::rational<int> r1 = RATIONAL("1/3"); + const boost::rational<int> r2 = RATIONAL("4/4"); + const boost::rational<int> r3 = RATIONAL("13/11"); + + std::cout + << r1 << std::endl + << r2 << std::endl + << r3 << std::endl; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/parsing_error/Jamfile.v2 b/src/boost/libs/metaparse/example/parsing_error/Jamfile.v2 new file mode 100644 index 000000000..c69580b84 --- /dev/null +++ b/src/boost/libs/metaparse/example/parsing_error/Jamfile.v2 @@ -0,0 +1 @@ +exe parsing_error : main.cpp ; diff --git a/src/boost/libs/metaparse/example/parsing_error/README b/src/boost/libs/metaparse/example/parsing_error/README new file mode 100644 index 000000000..6d7cc00d6 --- /dev/null +++ b/src/boost/libs/metaparse/example/parsing_error/README @@ -0,0 +1,17 @@ +This example shows how a compile-time parsing error can be debugged. +The commented code fails to compile and on some platforms the error report might +be difficult to understand. This example demonstrates how debug_parsing_error +can be used to get a user friendly error report about such thing. You need to +run the compiled code to get the error message: + +Compile-time parsing results +---------------------------- +Input text: +aaac + +Parsing failed: +line 1, col 4: Expected: b + +The col and line information refers to the location of the error in the string +literal. + diff --git a/src/boost/libs/metaparse/example/parsing_error/main.cpp b/src/boost/libs/metaparse/example/parsing_error/main.cpp new file mode 100644 index 000000000..4a1695519 --- /dev/null +++ b/src/boost/libs/metaparse/example/parsing_error/main.cpp @@ -0,0 +1,51 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/debug_parsing_error.hpp> + +#include <boost/metaparse/build_parser.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/apply.hpp> + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::debug_parsing_error; + +using boost::mpl::apply; + +/* + * The grammar + * + * s ::= a*b + */ +typedef sequence<repeated<lit_c<'a'> >, lit_c<'b'> > s; + +typedef build_parser<s> test_parser; + +#if BOOST_METAPARSE_STD < 2011 + +typedef boost::metaparse::string<'a','a','a','c'> invalid_input; + +#else + +typedef BOOST_METAPARSE_STRING("aaac") invalid_input; + +#endif + +debug_parsing_error<test_parser, invalid_input> debug; + +int main() +{ + // This causes an error + // apply<test_parser, invalid_input>::type(); +} + + diff --git a/src/boost/libs/metaparse/example/rational/Jamfile.v2 b/src/boost/libs/metaparse/example/rational/Jamfile.v2 new file mode 100644 index 000000000..91886f701 --- /dev/null +++ b/src/boost/libs/metaparse/example/rational/Jamfile.v2 @@ -0,0 +1 @@ +exe rational : main.cpp ; diff --git a/src/boost/libs/metaparse/example/rational/README b/src/boost/libs/metaparse/example/rational/README new file mode 100644 index 000000000..72e9225f6 --- /dev/null +++ b/src/boost/libs/metaparse/example/rational/README @@ -0,0 +1 @@ +Parser for rational numbers. diff --git a/src/boost/libs/metaparse/example/rational/main.cpp b/src/boost/libs/metaparse/example/rational/main.cpp new file mode 100644 index 000000000..2de195222 --- /dev/null +++ b/src/boost/libs/metaparse/example/rational/main.cpp @@ -0,0 +1,97 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/sequence_apply.hpp> +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/empty.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/build_parser.hpp> + +#include <boost/rational.hpp> + +#include <boost/config.hpp> + +#include <boost/mpl/int.hpp> + +#include <iostream> + +using boost::metaparse::sequence_apply2; +using boost::metaparse::last_of; +using boost::metaparse::int_; +using boost::metaparse::token; +using boost::metaparse::lit_c; +using boost::metaparse::one_of; +using boost::metaparse::empty; +using boost::metaparse::entire_input; +using boost::metaparse::build_parser; + +template <class Num, class Denom> +struct rational +{ + typedef rational type; + + static boost::rational<int> run() + { + return boost::rational<int>(Num::type::value, Denom::type::value); + } +}; + +typedef + sequence_apply2< + rational, + + token<int_>, + one_of< + last_of<lit_c<'/'>, token<int_> >, + empty<boost::mpl::int_<1> > + > + > + rational_grammar; + +typedef build_parser<entire_input<rational_grammar> > rational_parser; + +#ifdef RATIONAL +# error RATIONAL already defined +#endif +#define RATIONAL(s) \ + (::rational_parser::apply<BOOST_METAPARSE_STRING(s)>::type::run()) + +#if BOOST_METAPARSE_STD < 2011 + +int main() +{ + std::cout << "Please use a compiler that supports constexpr" << std::endl; +} + +#else + +int main() +{ + const boost::rational<int> r1 = RATIONAL("1/3"); + const boost::rational<int> r2 = RATIONAL("4/4"); + const boost::rational<int> r3 = RATIONAL("1"); + const boost::rational<int> r4 = RATIONAL("13/11"); + + // Uncommenting the following line generates a compilation error. On a + // number of platforms the error report contains the following (or something + // similar): + // x__________________PARSING_FAILED__________________x<1, 3, digit_expected> + // where 1, 3 is the location of the error inside the string literal. +// const boost::rational<int> r5 = RATIONAL("7/"); + + std::cout + << r1 << std::endl + << r2 << std::endl + << r3 << std::endl + << r4 << std::endl; +} + +#endif + diff --git a/src/boost/libs/metaparse/example/regexp/Jamfile.v2 b/src/boost/libs/metaparse/example/regexp/Jamfile.v2 new file mode 100644 index 000000000..6650684fb --- /dev/null +++ b/src/boost/libs/metaparse/example/regexp/Jamfile.v2 @@ -0,0 +1 @@ +exe regexp : main.cpp ; diff --git a/src/boost/libs/metaparse/example/regexp/README b/src/boost/libs/metaparse/example/regexp/README new file mode 100644 index 000000000..57b68c848 --- /dev/null +++ b/src/boost/libs/metaparse/example/regexp/README @@ -0,0 +1,7 @@ +This example provides an interface in front of boost::xpressive. +A regular expression can be specified by a compile-time string +which is parsed (and verified) at compile-time. A boost::xpressive +object is constructed at runtime based on it. +This is just an example, it supports only a subset of the capabilities +of boost::xpressive. + diff --git a/src/boost/libs/metaparse/example/regexp/main.cpp b/src/boost/libs/metaparse/example/regexp/main.cpp new file mode 100644 index 000000000..cb8b8ab30 --- /dev/null +++ b/src/boost/libs/metaparse/example/regexp/main.cpp @@ -0,0 +1,158 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_reject_incomplete.hpp> +#include <boost/metaparse/foldl_reject_incomplete1.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/one_char_except_c.hpp> +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/always_c.hpp> +#include <boost/metaparse/build_parser.hpp> +#include <boost/metaparse/middle_of.hpp> +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/detail/iterator.hpp> +#include <boost/xpressive/xpressive.hpp> + +#include <boost/mpl/bool.hpp> +#include <boost/mpl/string.hpp> + +using boost::metaparse::foldl_reject_incomplete; +using boost::metaparse::foldl_reject_incomplete1; +using boost::metaparse::lit_c; +using boost::metaparse::transform; +using boost::metaparse::build_parser; +using boost::metaparse::one_of; +using boost::metaparse::always_c; +using boost::metaparse::middle_of; +using boost::metaparse::one_char_except_c; +using boost::metaparse::entire_input; + +using boost::mpl::c_str; +using boost::mpl::true_; +using boost::mpl::false_; + +using boost::xpressive::sregex; +using boost::xpressive::as_xpr; + +/* + * Results of parsing + */ + +template <class T> +struct has_value +{ + typedef T type; + static const sregex value; +}; + +template <class T> +const sregex has_value<T>::value = T::run(); + +struct r_epsilon : has_value<r_epsilon> +{ + static sregex run() + { + return as_xpr(""); + } +}; + +struct r_any_char : has_value<r_any_char> +{ + static sregex run() + { + return boost::xpressive::_; + } +}; + +struct r_char_lit +{ + template <class C> + struct apply : has_value<apply<C> > + { + static sregex run() + { + return as_xpr(C::type::value); + } + }; +}; + +struct r_append +{ + template <class A, class B> + struct apply : has_value<apply<B, A> > + { + static sregex run() + { + return A::type::run() >> B::type::run(); + } + }; +}; + +/* + * The grammar + * + * regexp ::= (bracket_expr | non_bracket_expr)* + * non_bracket_expr ::= '.' | char_lit + * bracket_expr ::= '(' regexp ')' + * char_lit ::= any character except: . ( ) + */ + +typedef + foldl_reject_incomplete1< + one_of< + always_c<'.', r_any_char>, + transform<one_char_except_c<'.', '(', ')'>, r_char_lit> + >, + r_epsilon, + r_append + > + non_bracket_expr; + +typedef middle_of<lit_c<'('>, non_bracket_expr, lit_c<')'> > bracket_expr; + +typedef + foldl_reject_incomplete< + one_of<bracket_expr, non_bracket_expr>, + r_epsilon, + r_append + > + regexp; + +typedef build_parser<entire_input<regexp> > regexp_parser; + +void test_string(const std::string& s) +{ + using boost::xpressive::regex_match; + using boost::xpressive::smatch; + using boost::mpl::apply_wrap1; + + using std::cout; + using std::endl; + +#if BOOST_METAPARSE_STD < 2011 + typedef boost::metaparse::string<'.','(','b','c',')'> regexp; +#else + typedef BOOST_METAPARSE_STRING(".(bc)") regexp; +#endif + + const sregex re = apply_wrap1<regexp_parser, regexp>::type::value; + smatch w; + + cout + << s << (regex_match(s, w, re) ? " matches " : " doesn't match ") + << c_str<regexp>::type::value + << endl; +} + +int main() +{ + test_string("abc"); + test_string("aba"); +} + + diff --git a/src/boost/libs/metaparse/index.html b/src/boost/libs/metaparse/index.html new file mode 100644 index 000000000..0146da0c8 --- /dev/null +++ b/src/boost/libs/metaparse/index.html @@ -0,0 +1,13 @@ +<html> +<head> +<meta http-equiv="refresh" content="0; URL=../../doc/html/metaparse.html"> +</head> +<body> +Automatic redirection failed, please go to +<a href="../../doc/html/metaparse.html">../../doc/html/metaparse.html</a>. <hr> +<p>© Copyright Beman Dawes, 2001</p> +<p>Distributed under the Boost Software License, Version 1.0. (See accompanying +file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy +at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p> +</body> +</html> diff --git a/src/boost/libs/metaparse/meta/libraries.json b/src/boost/libs/metaparse/meta/libraries.json new file mode 100644 index 000000000..b2b96642b --- /dev/null +++ b/src/boost/libs/metaparse/meta/libraries.json @@ -0,0 +1,8 @@ +{ + "key": "metaparse", + "name": "Metaparse", + "authors": ["Abel Sinkovics"], + "description": "A library for generating compile time parsers parsing embedded DSL code as part of the C++ compilation process", + "category": ["Metaprogramming"], + "maintainers": ["Abel Sinkovics <abel -at- elte.hu>"] +} diff --git a/src/boost/libs/metaparse/test/BOOST_METAPARSE_STRING.cpp b/src/boost/libs/metaparse/test/BOOST_METAPARSE_STRING.cpp new file mode 100644 index 000000000..f48d2863a --- /dev/null +++ b/src/boost/libs/metaparse/test/BOOST_METAPARSE_STRING.cpp @@ -0,0 +1,63 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 4 + +#include <boost/type_traits/is_same.hpp> + +#include "common.hpp" +#include "test_case.hpp" +#include "string_macros.hpp" + +#include <boost/metaparse/string.hpp> + +#ifndef BOOST_METAPARSE_V1_CONFIG_NO_BOOST_METAPARSE_STRING + +using boost::metaparse::string; +using boost::is_same; + +BOOST_METAPARSE_TEST_CASE(string_macro) +{ + BOOST_MPL_ASSERT(( + is_same<string<'a', 'b', 'c', 'd'>, BOOST_METAPARSE_STRING("abcd")> + )); +} + +#undef BOOST_METAPARSE_LIMIT_STRING_SIZE +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 8 + +BOOST_METAPARSE_TEST_CASE(string_macro_redefined_length_limit) +{ + BOOST_MPL_ASSERT(( + is_same<string<'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'>, + BOOST_METAPARSE_STRING("abcdefgh")> + )); +} + +#undef BOOST_METAPARSE_LIMIT_STRING_SIZE +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 127 + +BOOST_METAPARSE_TEST_CASE(creating_long_string_with_macro) +{ + BOOST_MPL_ASSERT(( + is_same< + string< + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_10, + BOOST_METAPARSE_TEST_CHARS_10, + '0', '1', '2', '3', '4', '5', '6' + >, + BOOST_METAPARSE_STRING( + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_10 + BOOST_METAPARSE_TEST_STRING_10 + "0123456" + ) + > + )); +} + +#endif + diff --git a/src/boost/libs/metaparse/test/Jamfile.v2 b/src/boost/libs/metaparse/test/Jamfile.v2 new file mode 100644 index 000000000..aa8eee886 --- /dev/null +++ b/src/boost/libs/metaparse/test/Jamfile.v2 @@ -0,0 +1,114 @@ +import testing ; + +project metaparse : + requirements + <toolset>gcc:<cxxflags>"-ftemplate-depth-300" + <toolset>clang:<cxxflags>"-ftemplate-depth-300" + + <library>/boost/test//boost_unit_test_framework/<link>static + ; + +test-suite metaparse-unit-tests : + [ compile BOOST_METAPARSE_STRING.cpp ] + [ compile accept.cpp ] + [ compile accept_when.cpp ] + [ compile back_inserter.cpp ] + [ compile all_headers.cpp ] + [ compile alphanum.cpp ] + [ compile always_c.cpp ] + [ compile always.cpp ] + [ compile at_c.cpp ] + [ compile build_parser.cpp ] + [ compile change_error_message.cpp ] + [ compile concat.cpp ] + [ run define_error.cpp ] + [ compile digit.cpp ] + [ compile digit_to_int.cpp ] + [ compile digit_val.cpp ] + [ compile empty.cpp ] + [ run empty_string.cpp ] + [ compile entire_input.cpp ] + [ compile except.cpp ] + [ compile fail_at_first_char_expected.cpp ] + [ compile fail.cpp ] + [ compile fail_tag.cpp ] + [ compile first_of.cpp ] + [ compile foldl1.cpp ] + [ compile foldl.cpp ] + [ compile foldl_reject_incomplete1.cpp ] + [ compile foldl_reject_incomplete.cpp ] + [ compile foldl_reject_incomplete_start_with_parser.cpp ] + [ compile foldl_start_with_parser.cpp ] + [ compile foldr1.cpp ] + [ compile foldr.cpp ] + [ compile foldr_reject_incomplete1.cpp ] + [ compile foldr_reject_incomplete.cpp ] + [ compile foldr_start_with_parser.cpp ] + [ compile front_inserter.cpp ] + [ compile grammar.cpp ] + [ compile has_type.cpp ] + [ compile if_.cpp ] + [ compile in_range_c.cpp ] + [ compile in_range.cpp ] + [ compile int_.cpp ] + [ compile int_to_digit.cpp ] + [ compile is_char_c.cpp ] + [ compile is_digit.cpp ] + [ compile is_error.cpp ] + [ compile is_lcase_letter.cpp ] + [ compile is_letter.cpp ] + [ compile is_ucase_letter.cpp ] + [ compile is_whitespace.cpp ] + [ compile iterate_c.cpp ] + [ compile iterate.cpp ] + [ compile keyword.cpp ] + [ compile last_of.cpp ] + [ compile letter.cpp ] + [ compile lit_c.cpp ] + [ compile lit.cpp ] + [ compile look_ahead.cpp ] + [ compile long_string.cpp ] + [ compile middle_of.cpp ] + [ compile next_digit.cpp ] + [ compile nth_of.cpp ] + [ compile one_char.cpp ] + [ compile one_char_except_c.cpp ] + [ compile one_char_except.cpp ] + [ compile one_of_c.cpp ] + [ compile one_of.cpp ] + [ compile optional.cpp ] + [ compile pop_back.cpp ] + [ compile pop_front.cpp ] + [ compile push_back_c.cpp ] + [ compile push_front_c.cpp ] + [ compile range_c.cpp ] + [ compile range.cpp ] + [ compile reject.cpp ] + [ compile repeated1.cpp ] + [ compile repeated.cpp ] + [ compile repeated_one_of1.cpp ] + [ compile repeated_one_of.cpp ] + [ compile repeated_reject_incomplete1.cpp ] + [ compile repeated_reject_incomplete.cpp ] + [ compile return_.cpp ] + [ compile returns.cpp ] + [ compile sequence.cpp ] + [ compile sequence_apply.cpp ] + [ compile size.cpp ] + [ compile source_position.cpp ] + [ compile space.cpp ] + [ compile spaces.cpp ] + [ run string.cpp ] + [ compile string_iterator_tag.cpp ] + [ compile string_tag.cpp ] + [ compile swap.cpp ] + [ compile token.cpp ] + [ compile-fail too_long_string.cpp ] + [ compile transform.cpp ] + [ compile transform_error.cpp ] + [ compile transform_error_message.cpp ] + [ compile unless_error.cpp ] + [ compile unpaired.cpp ] + [ compile update_c.cpp ] + [ compile version.cpp ] + ; diff --git a/src/boost/libs/metaparse/test/accept.cpp b/src/boost/libs/metaparse/test/accept.cpp new file mode 100644 index 000000000..e091ee63a --- /dev/null +++ b/src/boost/libs/metaparse/test/accept.cpp @@ -0,0 +1,71 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/accept.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +namespace +{ + template <class T> + struct returns + { + typedef T type; + }; + + template <class T> + struct gets_foo + { + typedef typename T::foo type; + }; +} + +BOOST_METAPARSE_TEST_CASE(accept) +{ + using boost::metaparse::accept; + using boost::metaparse::start; + using boost::metaparse::string; + using boost::metaparse::get_result; + using boost::metaparse::get_position; + using boost::metaparse::get_remaining; + + using boost::is_same; + + typedef string<'H','e','l','l','o'> s; + + // test_accept_is_metaprogramming_value + BOOST_MPL_ASSERT(( + is_same<accept<int, s, start>, accept<int, s, start>::type> + )); + + // test_accept_is_not_lazy + BOOST_MPL_ASSERT(( + is_same< + accept<gets_foo<int>, s, start>, + accept<gets_foo<int>, returns<s>, returns<start> >::type + > + )); + + // test_get_result_of_accept + BOOST_MPL_ASSERT((is_same<int, get_result<accept<int, s, start> >::type>)); + + // test_get_remaining_of_accept + BOOST_MPL_ASSERT((is_same<s, get_remaining<accept<int, s, start> >::type>)); + + // test_get_position_of_accept + BOOST_MPL_ASSERT(( + is_same<start, get_position<accept<int, s, start> >::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/accept_when.cpp b/src/boost/libs/metaparse/test/accept_when.cpp new file mode 100644 index 000000000..c705597ca --- /dev/null +++ b/src/boost/libs/metaparse/test/accept_when.cpp @@ -0,0 +1,69 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/accept_when.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/util/is_digit.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/metaparse/util/is_digit.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(accept_when) +{ + using boost::metaparse::is_error; + using boost::metaparse::accept_when; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::metaparse::util::is_digit; + + using boost::mpl::apply; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_with_text + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + accept_when<one_char, is_digit<>, test_failure>, + str_hello, + start + > + > + )); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + accept_when<one_char, is_digit<>, test_failure>, + str_1983, + start + > + >::type, + char_1 + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<accept_when<one_char, is_digit<>, test_failure>, str_, start> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/all_headers.cpp b/src/boost/libs/metaparse/test/all_headers.cpp new file mode 100644 index 000000000..14dedd04b --- /dev/null +++ b/src/boost/libs/metaparse/test/all_headers.cpp @@ -0,0 +1,8 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse.hpp> +#include <boost/metaparse.hpp> + diff --git a/src/boost/libs/metaparse/test/alphanum.cpp b/src/boost/libs/metaparse/test/alphanum.cpp new file mode 100644 index 000000000..2febacb46 --- /dev/null +++ b/src/boost/libs/metaparse/test/alphanum.cpp @@ -0,0 +1,50 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/alphanum.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/digit.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(alphanum) +{ + using boost::metaparse::get_result; + using boost::metaparse::alphanum; + using boost::metaparse::start; + using boost::metaparse::digit; + using boost::metaparse::is_error; + + using boost::mpl::list_c; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + typedef list_c<char, '.', '.', ','> other_string; + + // test_with_text + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<alphanum, str_hello, start> >::type, char_h> + )); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<digit, str_1983, start> >::type, char_1> + )); + + // test_with_non_alphanum + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, other_string, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/always.cpp b/src/boost/libs/metaparse/test/always.cpp new file mode 100644 index 000000000..ae93f996b --- /dev/null +++ b/src/boost/libs/metaparse/test/always.cpp @@ -0,0 +1,43 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/digit.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(always) +{ + using boost::metaparse::get_result; + using boost::metaparse::always; + using boost::metaparse::digit; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + typedef always<digit, int13> always_digit_13; + + // test_result + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<always_digit_13, str_1, start> >::type, + int13 + > + )); + + // test_fail + BOOST_MPL_ASSERT((is_error<apply_wrap2<always_digit_13, str_a, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/always_c.cpp b/src/boost/libs/metaparse/test/always_c.cpp new file mode 100644 index 000000000..f0801b3bf --- /dev/null +++ b/src/boost/libs/metaparse/test/always_c.cpp @@ -0,0 +1,41 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/always_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(always_c) +{ + using boost::metaparse::get_result; + using boost::metaparse::always_c; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_result + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<always_c<'1', int13>, str_1, start> >::type, + int13 + > + )); + + // test_fail + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<always_c<'1', int13>, str_a, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/at_c.cpp b/src/boost/libs/metaparse/test/at_c.cpp new file mode 100644 index 000000000..2323a711e --- /dev/null +++ b/src/boost/libs/metaparse/test/at_c.cpp @@ -0,0 +1,35 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/at_c.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(at_c) +{ + using boost::metaparse::v1::impl::at_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_first_char + BOOST_MPL_ASSERT((equal_to<char_<'h'>, at_c<hello, 0>::type>)); + + // test_middle_char + BOOST_MPL_ASSERT((equal_to<char_<'l'>, at_c<hello, 2>::type>)); + + // test_last_char + BOOST_MPL_ASSERT((equal_to<char_<'o'>, at_c<hello, 4>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/back_inserter.cpp b/src/boost/libs/metaparse/test/back_inserter.cpp new file mode 100644 index 000000000..333c9cd40 --- /dev/null +++ b/src/boost/libs/metaparse/test/back_inserter.cpp @@ -0,0 +1,26 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/deque.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(back_inserter) +{ + using boost::metaparse::v1::impl::back_inserter; + + using boost::mpl::equal; + using boost::mpl::deque; + + // test_inserts_at_the_back + BOOST_MPL_ASSERT(( + equal<deque<int, char>, back_inserter::apply<deque<int>, char>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/build_parser.cpp b/src/boost/libs/metaparse/test/build_parser.cpp new file mode 100644 index 000000000..e2f27ffea --- /dev/null +++ b/src/boost/libs/metaparse/test/build_parser.cpp @@ -0,0 +1,7 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/build_parser.hpp> + diff --git a/src/boost/libs/metaparse/test/change_error_message.cpp b/src/boost/libs/metaparse/test/change_error_message.cpp new file mode 100644 index 000000000..6c9eb6d40 --- /dev/null +++ b/src/boost/libs/metaparse/test/change_error_message.cpp @@ -0,0 +1,7 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/change_error_message.hpp> + diff --git a/src/boost/libs/metaparse/test/common.hpp b/src/boost/libs/metaparse/test/common.hpp new file mode 100644 index 000000000..21dccb499 --- /dev/null +++ b/src/boost/libs/metaparse/test/common.hpp @@ -0,0 +1,110 @@ +#ifndef BOOST_PARSER_TEST_COMMON_H +#define BOOST_PARSER_TEST_COMMON_H + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/lit.hpp> +#include <boost/metaparse/lit_c.hpp> + +#include <boost/mpl/list.hpp> +#include <boost/mpl/list_c.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/equal.hpp> + +#include <string> + +typedef boost::mpl::list_c<char> str_; +typedef boost::mpl::list_c<char, '0'> str_0; +typedef boost::mpl::list_c<char, '1'> str_1; +typedef boost::mpl::list_c<char, '1', '9', '8', '3'> str_1983; +typedef boost::mpl::list_c<char, 'a'> str_a; +typedef boost::mpl::list_c<char, 'a', 'b'> str_ab; +typedef boost::mpl::list_c<char, 'a', 'a', 'a', 'a', 'b'> str_aaaab; +typedef boost::mpl::list_c<char, 'a', 'c'> str_ac; +typedef boost::mpl::list_c<char, 'b'> str_b; +typedef boost::mpl::list_c<char, 'b', 'a'> str_ba; +typedef boost::mpl::list_c<char, 'b', 'a', 'a', 'a', 'a'> str_baaaa; +typedef boost::mpl::list_c<char, 'c'> str_c; +typedef boost::mpl::list_c<char, 'c', 'a'> str_ca; +typedef boost::mpl::list_c<char, 'h'> str_h; +typedef boost::mpl::list_c<char, 'e'> str_e; +typedef boost::mpl::list_c<char, 'l'> str_l; +typedef boost::mpl::list_c<char, 'b', 'e', 'l', 'l', 'o'> str_bello; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', 'l', 'o'> str_hello; +typedef boost::mpl::list_c<char, ' ', 'e', 'l', 'l', 'o'> str__ello; + +typedef boost::mpl::list_c<char, '0', 'e', 'l', 'l', 'o'> chars0; +typedef boost::mpl::list_c<char, 'h', '0', 'l', 'l', 'o'> chars1; +typedef boost::mpl::list_c<char, 'h', 'e', '0', 'l', 'o'> chars2; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', '0', 'o'> chars3; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', 'l', '0'> chars4; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', 'l', 'o'> chars5; + +typedef boost::mpl::char_<'0'> char_0; +typedef boost::mpl::char_<'1'> char_1; +typedef boost::mpl::char_<'7'> char_7; +typedef boost::mpl::char_<'9'> char_9; +typedef boost::mpl::char_<'a'> char_a; +typedef boost::mpl::char_<'b'> char_b; +typedef boost::mpl::char_<'e'> char_e; +typedef boost::mpl::char_<'h'> char_h; +typedef boost::mpl::char_<'k'> char_k; +typedef boost::mpl::char_<'K'> char_K; +typedef boost::mpl::char_<'l'> char_l; +typedef boost::mpl::char_<'o'> char_o; +typedef boost::mpl::char_<'x'> char_x; + +typedef boost::mpl::char_<' '> char_space; +typedef boost::mpl::char_<'\t'> char_tab; +typedef boost::mpl::char_<'\n'> char_new_line; +typedef boost::mpl::char_<'\r'> char_cret; + +typedef boost::mpl::int_<0> int0; +typedef boost::mpl::int_<1> int1; +typedef boost::mpl::int_<2> int2; +typedef boost::mpl::int_<3> int3; +typedef boost::mpl::int_<9> int9; +typedef boost::mpl::int_<10> int10; +typedef boost::mpl::int_<11> int11; +typedef boost::mpl::int_<12> int12; +typedef boost::mpl::int_<13> int13; +typedef boost::mpl::int_<14> int14; +typedef boost::mpl::int_<28> int28; + +typedef boost::metaparse::lit<char_e> lit_e; +typedef boost::metaparse::lit<char_h> lit_h; +typedef boost::metaparse::lit<char_l> lit_l; +typedef boost::metaparse::lit<char_x> lit_x; + +typedef boost::metaparse::lit_c<'e'> lit_c_e; +typedef boost::metaparse::lit_c<'h'> lit_c_h; + +typedef boost::mpl::list< > empty_list; + +typedef + boost::mpl::at<boost::mpl::vector<int, double>, int11> + can_not_be_instantiated; + +struct test_failure +{ + typedef test_failure type; + + static std::string get_value() { return "fail"; } +}; + +struct equal_sequences +{ + typedef equal_sequences type; + + template <class A, class B> + struct apply : boost::mpl::equal<typename A::type, typename B::type> {}; +}; + +#endif + diff --git a/src/boost/libs/metaparse/test/concat.cpp b/src/boost/libs/metaparse/test/concat.cpp new file mode 100644 index 000000000..c5af6b2fb --- /dev/null +++ b/src/boost/libs/metaparse/test/concat.cpp @@ -0,0 +1,48 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> + +#if BOOST_METAPARSE_STD >= 2011 + +#include <boost/metaparse/v1/cpp11/impl/concat.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(concat) +{ + using boost::metaparse::v1::impl::concat; + using boost::metaparse::string; + + using boost::mpl::equal_to; + + typedef string<> empty; + typedef string<'h','e','l','l','o'> hello; + + // test_empty_empty + BOOST_MPL_ASSERT((equal_to<empty, concat<empty, empty>::type>)); + + // test_empty_hello + BOOST_MPL_ASSERT((equal_to<hello, concat<empty, hello>::type>)); + + // test_hello_empty + BOOST_MPL_ASSERT((equal_to<hello, concat<hello, empty>::type>)); + + // test_hello_hello + BOOST_MPL_ASSERT(( + equal_to< + string<'h','e','l','l','o','h','e','l','l','o'>, + concat<hello, hello>::type + > + )); +} + +#endif + diff --git a/src/boost/libs/metaparse/test/define_error.cpp b/src/boost/libs/metaparse/test/define_error.cpp new file mode 100644 index 000000000..c61ec5d0c --- /dev/null +++ b/src/boost/libs/metaparse/test/define_error.cpp @@ -0,0 +1,28 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MODULE define_error + +#include <boost/metaparse/define_error.hpp> + +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/test/unit_test.hpp> + +namespace +{ + BOOST_METAPARSE_DEFINE_ERROR(test_error, "test error"); +} + +BOOST_AUTO_TEST_CASE(test_define_error) +{ + using boost::is_same; + + BOOST_MPL_ASSERT((is_same<test_error, test_error::type>)); + + BOOST_CHECK_EQUAL("test error", test_error::get_value()); +} + diff --git a/src/boost/libs/metaparse/test/digit.cpp b/src/boost/libs/metaparse/test/digit.cpp new file mode 100644 index 000000000..1d7a169a3 --- /dev/null +++ b/src/boost/libs/metaparse/test/digit.cpp @@ -0,0 +1,55 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/digit.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_message.hpp> + +#include <boost/metaparse/error/digit_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +#include <boost/type_traits/is_same.hpp> + +BOOST_METAPARSE_TEST_CASE(digit) +{ + using boost::metaparse::is_error; + using boost::metaparse::digit; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::get_message; + + using boost::metaparse::error::digit_expected; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + using boost::is_same; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<digit, str_1983, start> >::type, char_1> + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_, start> >)); + + // test_error_message_with_empty_string + BOOST_MPL_ASSERT(( + is_same<digit_expected, get_message<apply_wrap2<digit, str_, start> >::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/digit_to_int.cpp b/src/boost/libs/metaparse/test/digit_to_int.cpp new file mode 100644 index 000000000..9ee7f73b1 --- /dev/null +++ b/src/boost/libs/metaparse/test/digit_to_int.cpp @@ -0,0 +1,42 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/digit_to_int.hpp> +#include <boost/metaparse/error/digit_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(digit_to_int) +{ + using boost::metaparse::util::digit_to_int; + using boost::metaparse::error::digit_expected; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap1; + using boost::mpl::true_; + + using boost::is_same; + + // test0 + BOOST_MPL_ASSERT((equal_to<apply_wrap1<digit_to_int<>, char_0>::type, int0>)); + + // test9 + BOOST_MPL_ASSERT((equal_to<apply_wrap1<digit_to_int<>, char_9>::type, int9>)); + + // test_error + BOOST_MPL_ASSERT(( + is_same<digit_expected, apply_wrap1<digit_to_int<>, char_x>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/digit_val.cpp b/src/boost/libs/metaparse/test/digit_val.cpp new file mode 100644 index 000000000..347ca2cff --- /dev/null +++ b/src/boost/libs/metaparse/test/digit_val.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/digit_val.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(digit_val) +{ + using boost::metaparse::is_error; + using boost::metaparse::digit_val; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_val, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<digit_val, str_1983, start> >::type, int1> + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_val, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/empty.cpp b/src/boost/libs/metaparse/test/empty.cpp new file mode 100644 index 000000000..3e648070a --- /dev/null +++ b/src/boost/libs/metaparse/test/empty.cpp @@ -0,0 +1,39 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/empty.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(empty) +{ + using boost::metaparse::get_result; + using boost::metaparse::empty; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + typedef empty<int13> empty13; + + // test_accept_empty + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<empty13, str_, start> >::type, int13> + )); + + // test_reject_non_empty + BOOST_MPL_ASSERT((is_error<apply_wrap2<empty13, str_a, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/empty_string.cpp b/src/boost/libs/metaparse/test/empty_string.cpp new file mode 100644 index 000000000..ed4468bc5 --- /dev/null +++ b/src/boost/libs/metaparse/test/empty_string.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MODULE empty_string + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/empty_string.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/empty_string.hpp> +#endif + +#include <boost/test/unit_test.hpp> + +#include <string> + +BOOST_AUTO_TEST_CASE(test_empty_string) +{ + using boost::metaparse::v1::impl::empty_string; + using std::string; + + // test_value + BOOST_REQUIRE_EQUAL(string(), empty_string<>::value); +} + diff --git a/src/boost/libs/metaparse/test/entire_input.cpp b/src/boost/libs/metaparse/test/entire_input.cpp new file mode 100644 index 000000000..5b2067b39 --- /dev/null +++ b/src/boost/libs/metaparse/test/entire_input.cpp @@ -0,0 +1,57 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/get_message.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(entire_input) +{ + using boost::metaparse::get_result; + using boost::metaparse::entire_input; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::one_char; + using boost::metaparse::get_message; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + using boost::is_same; + + typedef entire_input<one_char> ei; + + // test_accept_entire_input + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<ei, str_h, start> >::type, char_h> + )); + + // test_reject_non_entire_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<ei, str_hello, start> >)); + + // test_predefined_error_message + BOOST_MPL_ASSERT(( + is_same< + test_failure, + get_message< + apply_wrap2<entire_input<one_char, test_failure>, str_hello, start> + >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/except.cpp b/src/boost/libs/metaparse/test/except.cpp new file mode 100644 index 000000000..1a6484221 --- /dev/null +++ b/src/boost/libs/metaparse/test/except.cpp @@ -0,0 +1,56 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/except.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(except) +{ + using boost::metaparse::is_error; + using boost::metaparse::except; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::fail; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test_with_good + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<except<one_char, int13, test_failure>, str_hello, start> + > + )); + + // test_with_bad + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + except<fail<test_failure>, int13, test_failure>, + str_hello, + start + > + >::type, + int13 + > + )); +} + + + diff --git a/src/boost/libs/metaparse/test/fail.cpp b/src/boost/libs/metaparse/test/fail.cpp new file mode 100644 index 000000000..1c05d8454 --- /dev/null +++ b/src/boost/libs/metaparse/test/fail.cpp @@ -0,0 +1,30 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(fail) +{ + using boost::metaparse::is_error; + using boost::metaparse::fail; + using boost::metaparse::start; + + using boost::mpl::apply_wrap2; + + // test_fail_for_non_empty_string + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<fail<test_failure>, str_hello, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/fail_at_first_char_expected.cpp b/src/boost/libs/metaparse/test/fail_at_first_char_expected.cpp new file mode 100644 index 000000000..95917d531 --- /dev/null +++ b/src/boost/libs/metaparse/test/fail_at_first_char_expected.cpp @@ -0,0 +1,42 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/fail_at_first_char_expected.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/keyword.hpp> + +#include <boost/mpl/assert.hpp> + +#include "common.hpp" + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(fail_at_first_char_expected) +{ + using boost::metaparse::fail_at_first_char_expected; + using boost::metaparse::is_error; + using boost::metaparse::start; + + typedef boost::metaparse::keyword<str_hello> accept_hello; + + // test_failure_at_first_char_is_ignored + BOOST_MPL_ASSERT_NOT(( + is_error<fail_at_first_char_expected<accept_hello>::apply<str_ab, start> > + )); + + // test_no_failure_is_error + BOOST_MPL_ASSERT(( + is_error< + fail_at_first_char_expected<accept_hello>::apply<str_hello, start> + > + )); + + // test_failure_at_second_char_is_not_ignored + BOOST_MPL_ASSERT(( + is_error< fail_at_first_char_expected<accept_hello>::apply<str_h, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/fail_tag.cpp b/src/boost/libs/metaparse/test/fail_tag.cpp new file mode 100644 index 000000000..b2ded6984 --- /dev/null +++ b/src/boost/libs/metaparse/test/fail_tag.cpp @@ -0,0 +1,41 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/start.hpp> + +#include "common.hpp" + +#include <boost/type_traits/is_same.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(fail_tag) +{ + using boost::metaparse::fail; + using boost::metaparse::get_message; + using boost::metaparse::get_position; + using boost::metaparse::start; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::is_same; + + typedef fail<test_failure> p; + typedef apply_wrap2<p, str_hello, start> failed_result; + + // test_getting_message_back + BOOST_MPL_ASSERT((is_same<test_failure, get_message<failed_result>::type>)); + + // test_getting_position + BOOST_MPL_ASSERT((equal_to<start, get_position<failed_result>::type>)); +} + diff --git a/src/boost/libs/metaparse/test/first_of.cpp b/src/boost/libs/metaparse/test/first_of.cpp new file mode 100644 index 000000000..cc04afcc0 --- /dev/null +++ b/src/boost/libs/metaparse/test/first_of.cpp @@ -0,0 +1,68 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/first_of.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(first_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::first_of; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_one_char + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<first_of<lit_h>, str_hello, start> >::type, + char_h + > + )); + + // test_two_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<first_of<lit_h, lit_e>, str_hello, start> >::type, + char_h + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<first_of<lit_x, lit_e>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<first_of<lit_h, lit_x>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<first_of<lit_h,lit_e>, str_,start> >)); + + // test_three_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<first_of<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + char_h + > + )); +} + diff --git a/src/boost/libs/metaparse/test/foldl.cpp b/src/boost/libs/metaparse/test/foldl.cpp new file mode 100644 index 000000000..8bfb9c346 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated : foldl<P, vector<>, back_inserter> {}; +} + +#define TEST_NAME foldl + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl1.cpp b/src/boost/libs/metaparse/test/foldl1.cpp new file mode 100644 index 000000000..231fa6b03 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl1.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl1.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl1; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated1 : foldl1<P, vector<>, back_inserter> {}; +} + +#define TEST_NAME foldl1 + +#include "repeated1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_reject_incomplete.cpp b/src/boost/libs/metaparse/test/foldl_reject_incomplete.cpp new file mode 100644 index 000000000..064556e80 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_reject_incomplete.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_reject_incomplete.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl_reject_incomplete; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated_reject_incomplete : + foldl_reject_incomplete<P, vector<>, back_inserter> + {}; +} + +#define TEST_NAME foldl_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_reject_incomplete1.cpp b/src/boost/libs/metaparse/test/foldl_reject_incomplete1.cpp new file mode 100644 index 000000000..7ec6ab540 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_reject_incomplete1.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_reject_incomplete1.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl_reject_incomplete1; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated_reject_incomplete1 : + foldl_reject_incomplete1<P, vector<>, back_inserter> + {}; +} + +#define TEST_NAME foldl_reject_incomplete1 + +#include "repeated_reject_incomplete1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_reject_incomplete_start_with_parser.cpp b/src/boost/libs/metaparse/test/foldl_reject_incomplete_start_with_parser.cpp new file mode 100644 index 000000000..9647fbbae --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_reject_incomplete_start_with_parser.cpp @@ -0,0 +1,97 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/return_.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct keep_state + { + typedef keep_state type; + + template <class S, class C> + struct apply : S {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(foldl_reject_incomplete_start_with_parser) +{ + using boost::metaparse::foldl_reject_incomplete_start_with_parser; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + using boost::metaparse::sequence; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::char_; + + typedef sequence<lit_c<'a'>, lit_c<'a'> > aa; + + typedef + foldl_reject_incomplete_start_with_parser<aa, lit_c<'b'>, keep_state> + p; + + // test_b + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_b, start> >::type, char_<'b'> > + )); + + // test_ba + BOOST_MPL_ASSERT(( is_error<apply_wrap2<p, str_ba, start> > )); + + // test_baaaa + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_baaaa, start> >::type, char_<'b'> > + )); + + // test_c + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_c, start> >)); + + // test_ca + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_ca, start> >)); +} + +// Test foldl_reject_incomplete_start_with_parser as a normal fold + +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::return_; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated_reject_incomplete : + foldl_reject_incomplete_start_with_parser< + P, + return_<vector<> >, + back_inserter + > + {}; +} + +#define TEST_NAME \ + foldl_reject_incomplete_start_with_parser_as_foldl_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_start_with_parser.cpp b/src/boost/libs/metaparse/test/foldl_start_with_parser.cpp new file mode 100644 index 000000000..a671cc43d --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_start_with_parser.cpp @@ -0,0 +1,88 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_start_with_parser.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/return_.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct keep_state + { + typedef keep_state type; + + template <class S, class C> + struct apply : S {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(foldl_start_with_parser) +{ + using boost::metaparse::foldl_start_with_parser; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::char_; + + typedef foldl_start_with_parser<lit_c<'a'>, lit_c<'b'>, keep_state> p; + + // test_b + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_b, start> >::type, char_<'b'> > + )); + + // test_ba + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_ba, start> >::type, char_<'b'> > + )); + + // test_baaaa + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_baaaa, start> >::type, char_<'b'> > + )); + + // test_c + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_c, start> >)); + + // test_ca + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_ca, start> >)); +} + +// Test foldl_start_with_parser as a normal fold + +using boost::metaparse::foldl_start_with_parser; +using boost::metaparse::return_; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated : + foldl_start_with_parser<P, return_<vector<> >, back_inserter> + {}; +} + +#define TEST_NAME foldl_start_with_parser_as_foldl + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr.cpp b/src/boost/libs/metaparse/test/foldr.cpp new file mode 100644 index 000000000..3071c60fd --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated : foldr<P, list<>, front_inserter> {}; +} + +#define TEST_NAME foldr + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr1.cpp b/src/boost/libs/metaparse/test/foldr1.cpp new file mode 100644 index 000000000..88542c7aa --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr1.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr1.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr1; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated1 : foldr1<P, list<>, front_inserter> {}; +} + +#define TEST_NAME foldr1 + +#include "repeated1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr_reject_incomplete.cpp b/src/boost/libs/metaparse/test/foldr_reject_incomplete.cpp new file mode 100644 index 000000000..c4392fb44 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr_reject_incomplete.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr_reject_incomplete.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr_reject_incomplete; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated_reject_incomplete : + foldr_reject_incomplete<P, list<>, front_inserter> + {}; +} + +#define TEST_NAME foldr_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr_reject_incomplete1.cpp b/src/boost/libs/metaparse/test/foldr_reject_incomplete1.cpp new file mode 100644 index 000000000..214a4b05d --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr_reject_incomplete1.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr_reject_incomplete1.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr_reject_incomplete1; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated_reject_incomplete1 : + foldr_reject_incomplete1<P, list<>, front_inserter> + {}; +} + +#define TEST_NAME foldr_reject_incomplete1 + +#include "repeated_reject_incomplete1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr_start_with_parser.cpp b/src/boost/libs/metaparse/test/foldr_start_with_parser.cpp new file mode 100644 index 000000000..621ee550e --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr_start_with_parser.cpp @@ -0,0 +1,67 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr_start_with_parser.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/fail.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct keep_state + { + typedef keep_state type; + + template <class S, class C> + struct apply : S {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(foldr_start_with_parser) +{ + using boost::metaparse::foldr_start_with_parser; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::char_; + + typedef foldr_start_with_parser<lit_c<'a'>, lit_c<'b'>, keep_state> p; + + // test_b + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_b, start> >::type, char_<'b'> > + )); + + // test_ab + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_ab, start> >::type, char_<'b'> > + )); + + // test_aaaab + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_aaaab, start> >::type, char_<'b'> > + )); + + // test_c + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_c, start> >)); + + // test_ac + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_ac, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/front_inserter.cpp b/src/boost/libs/metaparse/test/front_inserter.cpp new file mode 100644 index 000000000..6e30ebbe5 --- /dev/null +++ b/src/boost/libs/metaparse/test/front_inserter.cpp @@ -0,0 +1,26 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/deque.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(front_inserter) +{ + using boost::metaparse::v1::impl::front_inserter; + + using boost::mpl::equal; + using boost::mpl::deque; + + // test_inserts_at_the_front + BOOST_MPL_ASSERT(( + equal<deque<int, char>, front_inserter::apply<deque<char>, int>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/grammar.cpp b/src/boost/libs/metaparse/test/grammar.cpp new file mode 100644 index 000000000..390151154 --- /dev/null +++ b/src/boost/libs/metaparse/test/grammar.cpp @@ -0,0 +1,420 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/grammar.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/string.hpp> + +#include "test_case.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +using boost::mpl::char_; + +namespace +{ + struct next_char + { + typedef next_char type; + + template <class C> + struct apply + { + typedef char_<C::type::value + 1> type; + }; + }; +} + +BOOST_METAPARSE_TEST_CASE(grammar) +{ + using boost::metaparse::grammar; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::string; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::equal; + using boost::mpl::vector; + + // import + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::import<string<'S'>, lit_c<'x'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // rename_import + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::import<string<'I'>, lit_c<'x'> >::type + ::rule<string<'S',' ',':',':','=',' ','I'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // char + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','x','\''> >::type, + string<'x'>, + start + > + >::type + > + )); + + // char_failure + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','x','\''> >::type, + string<'y'>, + start + > + > + )); + + // char_n + BOOST_MPL_ASSERT(( + equal_to< + char_<'\n'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','n','\''> >::type, + string<'\n'>, + start + > + >::type + > + )); + + // char_r + BOOST_MPL_ASSERT(( + equal_to< + char_<'\r'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','r','\''> >::type, + string<'\r'>, + start + > + >::type + > + )); + + // char_t + BOOST_MPL_ASSERT(( + equal_to< + char_<'\t'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','t','\''> >::type, + string<'\t'>, + start + > + >::type + > + )); + + // backslash + BOOST_MPL_ASSERT(( + equal_to< + char_<'\\'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','\\','\''> >::type, + string<'\\'>, + start + > + >::type + > + )); + + // char_\' + BOOST_MPL_ASSERT(( + equal_to< + char_<'\''>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','\'','\''> >::type, + string<'\''>, + start + > + >::type + > + )); + + // rename_rule + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // sequence + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'>, char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R',' ','R'> >::type, + string<'x','x'>, + start + > + >::type + > + )); + + // sequence_first_fail + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R',' ','R'> >::type, + string<'y','x'>, + start + > + > + )); + + // sequence_second_fail + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R',' ','R'> >::type, + string<'x','y'>, + start + > + > + )); + + // selection 1 + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'Y',' ',':',':','=',' ','\'','y','\''> >::type + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','|','Y'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // selection 2 + BOOST_MPL_ASSERT(( + equal_to< + char_<'y'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'Y',' ',':',':','=',' ','\'','y','\''> >::type + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','|','Y'> >::type, + string<'y'>, + start + > + >::type + > + )); + + // selection_fail + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'Y',' ',':',':','=',' ','\'','y','\''> >::type + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','|','Y'> >::type, + string<'z'>, + start + > + > + )); + + // repeated_0 + BOOST_MPL_ASSERT(( + equal< + vector<>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','*'> >::type, + string<'y'>, + start + > + >::type + > + )); + + // repeated_1 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','*'> >::type, + string<'x','y'>, + start + > + >::type + > + )); + + // repeated_2 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'>, char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','*'> >::type, + string<'x','x','y'>, + start + > + >::type + > + )); + + // bracket + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule< + string<'S',' ',':',':','=',' ','(','\'','x','\'',')'> + >::type, + string<'x'>, + start + > + >::type + > + )); + + // semantic_action + BOOST_MPL_ASSERT(( + equal_to< + char_<'y'>, + get_result< + apply_wrap2< + grammar<> + ::rule< + string<'S',' ',':',':','=',' ','\'','x','\''>, + next_char + >::type, + string<'x'>, + start + > + >::type + > + )); + + // repeated+_0 + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','+'> >::type, + string<'y'>, + start + > + > + )); + + // repeated+_1 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','+'> >::type, + string<'x','y'>, + start + > + >::type + > + )); + + // repeated+_2 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'>, char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','+'> >::type, + string<'x','x','y'>, + start + > + >::type + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/has_type.cpp b/src/boost/libs/metaparse/test/has_type.cpp new file mode 100644 index 000000000..1edd2a1f2 --- /dev/null +++ b/src/boost/libs/metaparse/test/has_type.cpp @@ -0,0 +1,32 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/has_type.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/not.hpp> + +#include "test_case.hpp" + +namespace +{ + struct nullary_metafunction + { + typedef int type; + }; +} + +BOOST_METAPARSE_TEST_CASE(has_type) +{ + using boost::metaparse::v1::impl::has_type; + using boost::mpl::not_; + + // test_int_has_no_type + BOOST_MPL_ASSERT((not_<has_type<int>::type>)); + + // test_nullary_metafunction_has_type + BOOST_MPL_ASSERT((has_type<nullary_metafunction>)); +} + diff --git a/src/boost/libs/metaparse/test/if_.cpp b/src/boost/libs/metaparse/test/if_.cpp new file mode 100644 index 000000000..e4611090a --- /dev/null +++ b/src/boost/libs/metaparse/test/if_.cpp @@ -0,0 +1,46 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/if_.hpp> +#include <boost/metaparse/digit.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(if) +{ + using boost::metaparse::get_result; + using boost::metaparse::if_; + using boost::metaparse::digit; + using boost::metaparse::start; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_true + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<if_<digit, int11, int13>, str_1, start> >::type, + int11 + > + )); + + // test_false + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<if_<digit, int11, int13>, str_a, start> >::type, + int13 + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/in_range.cpp b/src/boost/libs/metaparse/test/in_range.cpp new file mode 100644 index 000000000..8a0ed9ec7 --- /dev/null +++ b/src/boost/libs/metaparse/test/in_range.cpp @@ -0,0 +1,35 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/in_range.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_in_range) +{ + using boost::metaparse::util::in_range; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_int_in_range + BOOST_MPL_ASSERT((apply_wrap1<in_range<int10, int13>, int12>)); + + // test_lower_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range<int10, int13>, int10>)); + + // test_upper_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range<int10, int13>, int13>)); + + // test_int_not_in_range + BOOST_MPL_ASSERT((not_<apply_wrap1<in_range<int10, int13>, int14> >)); +} + diff --git a/src/boost/libs/metaparse/test/in_range_c.cpp b/src/boost/libs/metaparse/test/in_range_c.cpp new file mode 100644 index 000000000..49f4310cf --- /dev/null +++ b/src/boost/libs/metaparse/test/in_range_c.cpp @@ -0,0 +1,36 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/in_range_c.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_in_range_c) +{ + using boost::metaparse::util::in_range_c; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_int_in_range + BOOST_MPL_ASSERT((apply_wrap1<in_range_c<char, 'a', 'g'>, char_e>)); + + // test_lower_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range_c<char, 'a', 'g'>, char_a>)); + + // test_upper_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range_c<int, 10, 13>, int13>)); + + // test_int_not_in_range + BOOST_MPL_ASSERT((not_<apply_wrap1<in_range_c<int, 10, 13>, int14> >)); + +} + diff --git a/src/boost/libs/metaparse/test/int_.cpp b/src/boost/libs/metaparse/test/int_.cpp new file mode 100644 index 000000000..ab1cae671 --- /dev/null +++ b/src/boost/libs/metaparse/test/int_.cpp @@ -0,0 +1,53 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(int) +{ + using boost::metaparse::is_error; + using boost::metaparse::int_; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<int_, str_hello, start> >)); + + // test_with_zero + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<int_, str_0, start> >::type, int0> + )); + + // test_with_one_digit + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<int_, str_1, start> >::type, int1> + )); + + // test_with_big_number + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<int_, str_1983, start> >::type, + boost::mpl::int_<1983> + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<int_, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/int_to_digit.cpp b/src/boost/libs/metaparse/test/int_to_digit.cpp new file mode 100644 index 000000000..a0223f37b --- /dev/null +++ b/src/boost/libs/metaparse/test/int_to_digit.cpp @@ -0,0 +1,33 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/int_to_digit.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(int_to_digit) +{ + using boost::metaparse::util::int_to_digit; + + using boost::mpl::char_; + using boost::mpl::int_; + using boost::mpl::equal_to; + + // test0 + BOOST_MPL_ASSERT((equal_to<char_<'0'>, int_to_digit<int_<0> >::type>)); + + // test5 + BOOST_MPL_ASSERT((equal_to<char_<'5'>, int_to_digit<int_<5> >::type>)); + + // test9 + BOOST_MPL_ASSERT((equal_to<char_<'9'>, int_to_digit<int_<9> >::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/is_char_c.cpp b/src/boost/libs/metaparse/test/is_char_c.cpp new file mode 100644 index 000000000..46f579018 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_char_c.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/is_char_c.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(is_char_c) +{ + using boost::metaparse::v1::impl::is_char_c; + + using boost::mpl::char_; + + // test_for_the_same_char + BOOST_MPL_ASSERT(( is_char_c<'x'>::apply<char_<'x'> > )); + + // test_for_another_char + BOOST_MPL_ASSERT_NOT(( is_char_c<'x'>::apply<char_<'y'> > )); +} + diff --git a/src/boost/libs/metaparse/test/is_digit.cpp b/src/boost/libs/metaparse/test/is_digit.cpp new file mode 100644 index 000000000..3242c4b42 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_digit.cpp @@ -0,0 +1,30 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_digit.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_digit) +{ + using boost::metaparse::util::is_digit; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_digit + BOOST_MPL_ASSERT((apply_wrap1<is_digit<>, char_7>)); + + // test_non_digit + BOOST_MPL_ASSERT((not_<apply_wrap1<is_digit<>, char_a> >)); +} + + diff --git a/src/boost/libs/metaparse/test/is_error.cpp b/src/boost/libs/metaparse/test/is_error.cpp new file mode 100644 index 000000000..98dc3b0f5 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_error.cpp @@ -0,0 +1,31 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/fail.hpp> + +#include "common.hpp" + +#include <boost/mpl/not.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(is_error) +{ + using boost::metaparse::is_error; + using boost::metaparse::fail; + + using boost::mpl::not_; + using boost::mpl::apply_wrap2; + + // test_not_error + BOOST_MPL_ASSERT((not_<is_error<int13> >)); + + // test_error + BOOST_MPL_ASSERT((is_error<apply_wrap2<fail<int11>, int1, int13> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_lcase_letter.cpp b/src/boost/libs/metaparse/test/is_lcase_letter.cpp new file mode 100644 index 000000000..15b7a910e --- /dev/null +++ b/src/boost/libs/metaparse/test/is_lcase_letter.cpp @@ -0,0 +1,29 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_lcase_letter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_lcase_letter) +{ + using boost::metaparse::util::is_lcase_letter; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_letter + BOOST_MPL_ASSERT((apply_wrap1<is_lcase_letter<>, char_k>)); + + // test_non_letter + BOOST_MPL_ASSERT((not_<apply_wrap1<is_lcase_letter<>, char_K> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_letter.cpp b/src/boost/libs/metaparse/test/is_letter.cpp new file mode 100644 index 000000000..f2ab7932b --- /dev/null +++ b/src/boost/libs/metaparse/test/is_letter.cpp @@ -0,0 +1,32 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_letter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_letter) +{ + using boost::metaparse::util::is_letter; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_lcase_letter + BOOST_MPL_ASSERT((apply_wrap1<is_letter<>, char_k>)); + + // test_ucase_letter + BOOST_MPL_ASSERT((apply_wrap1<is_letter<>, char_K>)); + + // test_not_letter + BOOST_MPL_ASSERT((not_<apply_wrap1<is_letter<>, char_7> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_ucase_letter.cpp b/src/boost/libs/metaparse/test/is_ucase_letter.cpp new file mode 100644 index 000000000..5e92f7f8a --- /dev/null +++ b/src/boost/libs/metaparse/test/is_ucase_letter.cpp @@ -0,0 +1,29 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_ucase_letter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_ucase_letter) +{ + using boost::metaparse::util::is_ucase_letter; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_letter + BOOST_MPL_ASSERT((apply_wrap1<is_ucase_letter<>, char_K>)); + + // test_non_letter + BOOST_MPL_ASSERT((not_<apply_wrap1<is_ucase_letter<>, char_k> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_whitespace.cpp b/src/boost/libs/metaparse/test/is_whitespace.cpp new file mode 100644 index 000000000..08c20f439 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_whitespace.cpp @@ -0,0 +1,32 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_whitespace.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_whitespace) +{ + using boost::metaparse::util::is_whitespace; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_space + BOOST_MPL_ASSERT((apply_wrap1<is_whitespace<>, char_space>)); + + // test_tab + BOOST_MPL_ASSERT((apply_wrap1<is_whitespace<>, char_tab>)); + + // test_non_whitespace + BOOST_MPL_ASSERT((not_<apply_wrap1<is_whitespace<>, char_a> >)); +} + diff --git a/src/boost/libs/metaparse/test/iterate.cpp b/src/boost/libs/metaparse/test/iterate.cpp new file mode 100644 index 000000000..b237b93c5 --- /dev/null +++ b/src/boost/libs/metaparse/test/iterate.cpp @@ -0,0 +1,73 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/iterate.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(iterate) +{ + using boost::metaparse::is_error; + using boost::metaparse::iterate; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + using boost::mpl::list; + using boost::mpl::vector_c; + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<iterate<one_char, int13>, str_, start> > + )); + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int0>, str_hello, start> >::type, + list<> + > + )); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int1>, str_hello, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int2>, str_hello, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int3>, str_hello, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/iterate_c.cpp b/src/boost/libs/metaparse/test/iterate_c.cpp new file mode 100644 index 000000000..6ff4ee201 --- /dev/null +++ b/src/boost/libs/metaparse/test/iterate_c.cpp @@ -0,0 +1,73 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/iterate_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(iterate_c) +{ + using boost::metaparse::is_error; + using boost::metaparse::iterate_c; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + using boost::mpl::list; + using boost::mpl::vector_c; + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<iterate_c<one_char, 13>, str_, start> > + )); + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 0>, str_hello, start> >::type, + list<> + > + )); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 1>, str_hello, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 2>, str_hello, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 3>, str_hello, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/keyword.cpp b/src/boost/libs/metaparse/test/keyword.cpp new file mode 100644 index 000000000..1e4fd5189 --- /dev/null +++ b/src/boost/libs/metaparse/test/keyword.cpp @@ -0,0 +1,91 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::keyword; + + using boost::mpl::list_c; + + typedef + list_c<char, 'h','e','l','l','o',' ','w','o','r','l','d'> + str_hello_world; + + typedef list_c<char, 'h','e','l','l','x'> str_hellx; + typedef list_c<char, 'h','x','l','l','o'> str_hxllo; + + typedef keyword<str_hello> keyword_hello; +} + +BOOST_METAPARSE_TEST_CASE(keyword) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_remaining; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + + // test_result_type + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<keyword<str_hello, char_l>, str_hello, start> + >::type, + char_l + > + )); + + // test_empty_keyword + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<keyword<str_, char_l>, str_hello, start> >::type, + char_l + > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_, start> >)); + + // test_itself + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<keyword_hello, str_hello, start> >::type, + str_ + > + )); + + // test_more_than_itself + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<keyword_hello, str_hello_world, start> >::type, + list_c<char, ' ', 'w', 'o', 'r', 'l', 'd'> + > + )); + + // test_no_match_at_end + BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hellx, start> >)); + + // test_no_match_in_the_middle + BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hxllo, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/last_of.cpp b/src/boost/libs/metaparse/test/last_of.cpp new file mode 100644 index 000000000..e06ddaa70 --- /dev/null +++ b/src/boost/libs/metaparse/test/last_of.cpp @@ -0,0 +1,71 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(last_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::last_of; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_one_char + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<last_of<lit_h>, str_hello, start> >::type, + char_h + > + )); + + // test_two_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<last_of<lit_h, lit_e>, str_hello, start> >::type, + char_e + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<last_of<lit_x, lit_e>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<last_of<lit_h, lit_x>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<last_of<lit_h, lit_e>, str_, start> > + )); + + // test_three_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<last_of<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + char_l + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/letter.cpp b/src/boost/libs/metaparse/test/letter.cpp new file mode 100644 index 000000000..bee753687 --- /dev/null +++ b/src/boost/libs/metaparse/test/letter.cpp @@ -0,0 +1,41 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(letter) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_with_text + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<letter, str_hello, start> >::type, char_h> + )); + + // test_with_number + BOOST_MPL_ASSERT((is_error<apply_wrap2<letter, str_1983, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<letter, str_, start> >)); +} + + diff --git a/src/boost/libs/metaparse/test/lit.cpp b/src/boost/libs/metaparse/test/lit.cpp new file mode 100644 index 000000000..6af0c29ab --- /dev/null +++ b/src/boost/libs/metaparse/test/lit.cpp @@ -0,0 +1,74 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(lit) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::get_message; + + using boost::metaparse::error::literal_expected; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + using boost::is_same; + + // test_accept + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<lit_h, str_hello, start> >::type, char_h> + )); + + // test_reject + BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_h, str_bello, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_h, str_, start> >)); + + // test_error_with_empty_string + BOOST_MPL_ASSERT(( + is_same< + literal_expected<'h'>, + get_message<apply_wrap2<lit_h, str_, start> >::type + > + )); + + // test_remaining_string + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + lit_e, + get_remaining<apply_wrap2<lit_h, str_hello, start> >::type, + get_position<apply_wrap2<lit_h, str_hello, start> >::type + > + >::type, + char_e + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/lit_c.cpp b/src/boost/libs/metaparse/test/lit_c.cpp new file mode 100644 index 000000000..c1848477e --- /dev/null +++ b/src/boost/libs/metaparse/test/lit_c.cpp @@ -0,0 +1,74 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(lit_c) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::get_message; + + using boost::metaparse::error::literal_expected; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + using boost::is_same; + + // test_accept + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<lit_c_h, str_hello, start> >::type, char_h> + )); + + // test_reject + BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_c_h, str_bello, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error< apply_wrap2<lit_c_h, str_, start> >)); + + // test_error_with_empty_string + BOOST_MPL_ASSERT(( + is_same< + literal_expected<'h'>, + get_message<apply_wrap2<lit_c_h, str_, start> >::type + > + )); + + // test_remaining_string + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + lit_c_e, + get_remaining<apply_wrap2<lit_c_h, str_hello, start> >::type, + get_position<apply_wrap2<lit_c_h, str_hello, start> >::type + > + >::type, + char_e + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/long_string.cpp b/src/boost/libs/metaparse/test/long_string.cpp new file mode 100644 index 000000000..4ef518782 --- /dev/null +++ b/src/boost/libs/metaparse/test/long_string.cpp @@ -0,0 +1,56 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> + +#if BOOST_METAPARSE_STD >= 2011 + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 1024 +#include <boost/metaparse/string.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "common.hpp" +#include "test_case.hpp" +#include "string_macros.hpp" + +#ifndef BOOST_METAPARSE_V1_CONFIG_NO_BOOST_METAPARSE_STRING + +using boost::metaparse::string; +using boost::is_same; + +BOOST_METAPARSE_TEST_CASE(creating_very_long_string) +{ +// The Oracle Studio limit is 127 characters +#ifndef __SUNPRO_CC + BOOST_MPL_ASSERT(( + is_same< + string< + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_10, + '0', '1' + >, + BOOST_METAPARSE_STRING( + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_10 + "01" + ) + > + )); +#endif +} + +#endif + +#endif + diff --git a/src/boost/libs/metaparse/test/look_ahead.cpp b/src/boost/libs/metaparse/test/look_ahead.cpp new file mode 100644 index 000000000..060062329 --- /dev/null +++ b/src/boost/libs/metaparse/test/look_ahead.cpp @@ -0,0 +1,60 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/look_ahead.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/digit_val.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(look_ahead) +{ + + using boost::metaparse::get_result; + using boost::metaparse::look_ahead; + using boost::metaparse::digit_val; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::fail; + using boost::metaparse::get_remaining; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + + // test_returns_result + BOOST_MPL_ASSERT(( + equal_to< + int1, + get_result<apply_wrap2<look_ahead<digit_val>, str_1983, start> >::type + > + )); + + // test_returns_error + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<look_ahead<fail<int13> >, str_1983, start> > + )); + + // test_doesnt_process_input + BOOST_MPL_ASSERT(( + equal< + str_1983, + get_remaining<apply_wrap2<look_ahead<digit_val>, str_1983, start> >::type + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/middle_of.cpp b/src/boost/libs/metaparse/test/middle_of.cpp new file mode 100644 index 000000000..afc308ba2 --- /dev/null +++ b/src/boost/libs/metaparse/test/middle_of.cpp @@ -0,0 +1,81 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/middle_of.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/error/unpaired.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(middle_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::middle_of; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_message; + + using boost::metaparse::error::unpaired; + using boost::metaparse::error::literal_expected; + + using boost::is_same; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_three_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + char_e + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_x, lit_e, lit_l>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_h, lit_x, lit_l>, str_hello, start> > + )); + + // test_third_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start> > + )); + + // test_error_message_when_third_fails + BOOST_MPL_ASSERT(( + is_same< + unpaired<1, 1, literal_expected<'x'> >, + get_message< + apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start> + >::type + > + )); + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_, start> > + )); +} + + diff --git a/src/boost/libs/metaparse/test/next_digit.cpp b/src/boost/libs/metaparse/test/next_digit.cpp new file mode 100644 index 000000000..376b61698 --- /dev/null +++ b/src/boost/libs/metaparse/test/next_digit.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/next_digit.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/int.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(next_digit) +{ + using boost::metaparse::v1::impl::next_digit; + + using boost::mpl::equal_to; + using boost::mpl::int_; + + BOOST_MPL_ASSERT((equal_to<int_< 0>, next_digit::apply<int_<0>, int_<0> > >)); + BOOST_MPL_ASSERT((equal_to<int_<10>, next_digit::apply<int_<1>, int_<0> > >)); + BOOST_MPL_ASSERT((equal_to<int_<13>, next_digit::apply<int_<1>, int_<3> > >)); +} + diff --git a/src/boost/libs/metaparse/test/nth_of.cpp b/src/boost/libs/metaparse/test/nth_of.cpp new file mode 100644 index 000000000..aa9884213 --- /dev/null +++ b/src/boost/libs/metaparse/test/nth_of.cpp @@ -0,0 +1,97 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/nth_of.hpp> +#include <boost/metaparse/nth_of_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/start.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(nth_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::nth_of_c; + using boost::metaparse::start; + using boost::metaparse::nth_of; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + namespace mpl = boost::mpl; + namespace mp = boost::metaparse; + + // test_first_of_one + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<nth_of_c<0, lit_h>, str_hello, start> >::type, + char_h + > + )); + + // test_first_of_two + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<nth_of_c<0, lit_h, lit_e>, str_hello, start> + >::type, + char_h + > + )); + + // test_second_of_two + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<nth_of<int1, lit_h, lit_e>, str_hello, start> + >::type, + char_e + > + )); + + // test_nothing + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_x, lit_e>, str_hello, start> > + )); + + // test_first_of_none + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<0>, str_hello, start> > + )); + + // test_n_is_less_than_zero + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<-1, lit_h, lit_e>, str_hello, start> > + )); + + // test_n_is_greater_than_the_number_of_parsers + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<2, lit_h, lit_e>, str_hello, start> > + )); + + // test_error_before_the_nth + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_x, lit_e, lit_l>, str_hello, start> > + )); + + // test_error_at_the_nth + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_h, lit_x, lit_l>, str_hello, start> > + )); + + // test_error_after_the_nth + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_h, lit_e, lit_x>, str_hello, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/one_char.cpp b/src/boost/libs/metaparse/test/one_char.cpp new file mode 100644 index 000000000..5eff7521d --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char.cpp @@ -0,0 +1,16 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_char.hpp> + +namespace +{ + typedef boost::metaparse::one_char oc; +} + +#define TEST_NAME one_char + +#include "one_char_test.hpp" + diff --git a/src/boost/libs/metaparse/test/one_char_except.cpp b/src/boost/libs/metaparse/test/one_char_except.cpp new file mode 100644 index 000000000..b8b540316 --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_except.cpp @@ -0,0 +1,19 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_char_except.hpp> + +#include "common.hpp" + +namespace +{ + typedef boost::metaparse::one_char_except<char_0, char_1> oc; +} + +#define TEST_NAME test_one_char_except + +#include "one_char_except_test.hpp" + + diff --git a/src/boost/libs/metaparse/test/one_char_except_c.cpp b/src/boost/libs/metaparse/test/one_char_except_c.cpp new file mode 100644 index 000000000..a84097804 --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_except_c.cpp @@ -0,0 +1,18 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_char_except_c.hpp> + +#include "common.hpp" + +namespace +{ + typedef boost::metaparse::one_char_except_c<'0', '1'> oc; +} + +#define TEST_NAME one_char_except_c + +#include "one_char_except_test.hpp" + diff --git a/src/boost/libs/metaparse/test/one_char_except_test.hpp b/src/boost/libs/metaparse/test/one_char_except_test.hpp new file mode 100644 index 000000000..47ab60cad --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_except_test.hpp @@ -0,0 +1,33 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/is_error.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/preprocessor/cat.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(BOOST_PP_CAT(TEST_NAME, _except)) +{ + using boost::metaparse::is_error; + using boost::metaparse::start; + + using boost::mpl::apply_wrap2; + + // rejects_except_char + BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_0, start> >)); + + // rejects_other_except_char + BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_1, start> >)); +} + +#include "one_char_test.hpp" + diff --git a/src/boost/libs/metaparse/test/one_char_test.hpp b/src/boost/libs/metaparse/test/one_char_test.hpp new file mode 100644 index 000000000..033415b50 --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_test.hpp @@ -0,0 +1,103 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010 - 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_line.hpp> +#include <boost/metaparse/iterate_c.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::start; + + using boost::mpl::list_c; + using boost::mpl::apply_wrap2; + + typedef list_c<char, 'a','\n','b'> unix_multi_line_text; + typedef list_c<char, 'a','\r','\n','b'> dos_multi_line_text; + typedef list_c<char, 'a','\r','b'> mac_multi_line_text; + + typedef apply_wrap2<oc, str_hello, start> parse_first_char; +} + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::is_error; + using boost::metaparse::iterate_c; + using boost::metaparse::get_line; + + using boost::mpl::equal_to; + + // test_for_non_empty_string + BOOST_MPL_ASSERT((equal_to<get_result<parse_first_char>::type, char_h>)); + + // test_for_non_empty_string_second + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + oc, + get_remaining<parse_first_char>::type, + get_position<parse_first_char>::type + > + >::type, + char_e + > + )); + + // test_for_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_, start> >)); + + // test_unix_multi_line_text + BOOST_MPL_ASSERT(( + equal_to< + int2, + get_line< + get_position< + apply_wrap2<iterate_c<oc, 2>, unix_multi_line_text, start> + > + > + > + )); + + // test_dos_multi_line_text + BOOST_MPL_ASSERT(( + equal_to< + int2, + get_line< + get_position<apply_wrap2<iterate_c<oc, 3>, dos_multi_line_text, start> > + > + > + )); + + // test_mac_multi_line_text + BOOST_MPL_ASSERT(( + equal_to< + int2, + get_line< + get_position<apply_wrap2<iterate_c<oc, 2>, mac_multi_line_text, start> > + > + > + )); +} + + + diff --git a/src/boost/libs/metaparse/test/one_of.cpp b/src/boost/libs/metaparse/test/one_of.cpp new file mode 100644 index 000000000..b7890f00d --- /dev/null +++ b/src/boost/libs/metaparse/test/one_of.cpp @@ -0,0 +1,158 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/next_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(one_of) +{ + using boost::metaparse::is_error; + using boost::metaparse::one_of; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::one_char; + using boost::metaparse::fail; + using boost::metaparse::sequence; + using boost::metaparse::get_position; + using boost::metaparse::next_char; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + typedef fail<test_failure> test_fail; + typedef sequence<one_char, test_fail> test_fail_later; + + // test_1_with_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type, + char_h + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of<test_fail>, str_hello, start> > + )); + + // test_2_with_two_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, test_fail>, str_hello, start> + >::type, + char_h + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<test_fail, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_2_with_two_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> > + )); + + + + + + // test + BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of< >, str_hello, start> >)); + + // test_with_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type, + char_h + > + )); + + // test_with_bad + BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of<test_fail>,str_hello,start> >)); + + // test_with_two_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_with_first_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, test_fail>, str_hello, start> + >::type, + char_h + > + )); + + // test_with_second_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<test_fail, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_with_two_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> > + )); + + // test_error_is_the_last_error + BOOST_MPL_ASSERT(( + equal_to< + next_char<start, char_h>::type, + get_position< + apply_wrap2< + one_of<test_fail, test_fail_later>, + str_hello, + start + > + >::type + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/one_of_c.cpp b/src/boost/libs/metaparse/test/one_of_c.cpp new file mode 100644 index 000000000..010cb5b8f --- /dev/null +++ b/src/boost/libs/metaparse/test/one_of_c.cpp @@ -0,0 +1,75 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_of_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(one_of_c) +{ + using boost::metaparse::is_error; + using boost::metaparse::one_of_c; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test0 + BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of_c< >, str_hello, start> >)); + + // test_1_with_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'h'>, str_hello, start> >::type, + char_h + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of_c<'x'>, str_hello, start> > + )); + + // test_2_with_two_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'h', 'x'>, str_hello, start> >::type, + char_h + > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'h', 'x'>, str_hello, start> >::type, + char_h + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'x', 'h'>, str_hello, start> >::type, + char_h + > + )); + + // test_2_with_two_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of_c<'x', 'y'>, str_hello, start> > + )); +} + + diff --git a/src/boost/libs/metaparse/test/optional.cpp b/src/boost/libs/metaparse/test/optional.cpp new file mode 100644 index 000000000..4bba83b26 --- /dev/null +++ b/src/boost/libs/metaparse/test/optional.cpp @@ -0,0 +1,55 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/optional.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/start.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(optional) +{ + using boost::metaparse::optional; + using boost::metaparse::lit_c; + using boost::metaparse::string; + using boost::metaparse::get_result; + using boost::metaparse::start; + + using boost::mpl::equal_to; + + using boost::is_same; + + typedef optional<lit_c<'x'>, double> optional_x; + + // test_optional_parser_succeeds + BOOST_MPL_ASSERT(( + equal_to< + boost::mpl::char_<'x'>, + get_result<optional_x::apply<string<'x'>, start> >::type + > + )); + + // test_optional_parser_fails + BOOST_MPL_ASSERT(( + is_same<double, get_result<optional_x::apply<string<'y'>, start> >::type> + )); + + // test_optional_parser_default_value + BOOST_MPL_ASSERT(( + is_same< + void, + get_result<optional<lit_c<'x'> >::apply<string<'y'>, start> >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/pop_back.cpp b/src/boost/libs/metaparse/test/pop_back.cpp new file mode 100644 index 000000000..b74c83b61 --- /dev/null +++ b/src/boost/libs/metaparse/test/pop_back.cpp @@ -0,0 +1,38 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/pop_back.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/pop_back.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(pop_back) +{ + using boost::metaparse::v1::impl::pop_back; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_pop_back + BOOST_MPL_ASSERT((equal_to<string<'h','e','l','l'>, pop_back<hello>::type>)); + + // test_pop_back_one_element + BOOST_MPL_ASSERT((equal_to<string<>, pop_back<string<'x'> >::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/pop_front.cpp b/src/boost/libs/metaparse/test/pop_front.cpp new file mode 100644 index 000000000..988ec8227 --- /dev/null +++ b/src/boost/libs/metaparse/test/pop_front.cpp @@ -0,0 +1,38 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/pop_front.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/pop_front.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(pop_front) +{ + using boost::metaparse::v1::impl::pop_front; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_pop_front + BOOST_MPL_ASSERT((equal_to<string<'e','l','l','o'>, pop_front<hello>::type>)); + + // test_pop_front_one_element + BOOST_MPL_ASSERT((equal_to<string<>, pop_front<string<'x'> >::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/push_back_c.cpp b/src/boost/libs/metaparse/test/push_back_c.cpp new file mode 100644 index 000000000..0927197ed --- /dev/null +++ b/src/boost/libs/metaparse/test/push_back_c.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/push_back_c.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/push_back_c.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(push_back_c) +{ + using boost::metaparse::v1::impl::push_back_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_push_back + BOOST_MPL_ASSERT(( + equal_to<hello, push_back_c<string<'h','e','l','l'>, 'o'>::type> + )); + + // test_push_back_to_empty + BOOST_MPL_ASSERT((equal_to<string<'x'>, push_back_c<string<>, 'x'>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/push_front_c.cpp b/src/boost/libs/metaparse/test/push_front_c.cpp new file mode 100644 index 000000000..9ac65865c --- /dev/null +++ b/src/boost/libs/metaparse/test/push_front_c.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/push_front_c.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/push_front_c.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(push_front_c) +{ + using boost::metaparse::v1::impl::push_front_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_push_front + BOOST_MPL_ASSERT(( + equal_to<hello, push_front_c<string<'e','l','l','o'>, 'h'>::type> + )); + + // test_push_front_to_empty + BOOST_MPL_ASSERT((equal_to<string<'x'>, push_front_c<string<>, 'x'>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/range.cpp b/src/boost/libs/metaparse/test/range.cpp new file mode 100644 index 000000000..9c93c06e6 --- /dev/null +++ b/src/boost/libs/metaparse/test/range.cpp @@ -0,0 +1,47 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/range.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(range) +{ + using boost::metaparse::is_error; + using boost::metaparse::range; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef range<char_<'0'>, char_<'9'> > digit_range; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<digit_range, str_1983, start> >::type, + char_1 + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/range_c.cpp b/src/boost/libs/metaparse/test/range_c.cpp new file mode 100644 index 000000000..1a734cfd5 --- /dev/null +++ b/src/boost/libs/metaparse/test/range_c.cpp @@ -0,0 +1,47 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/range_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(range_c) +{ + using boost::metaparse::is_error; + using boost::metaparse::range_c; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef range_c<'0', '9'> digit_range; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<digit_range, str_1983, start> >::type, + char_1 + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/reject.cpp b/src/boost/libs/metaparse/test/reject.cpp new file mode 100644 index 000000000..5dfe2ad1f --- /dev/null +++ b/src/boost/libs/metaparse/test/reject.cpp @@ -0,0 +1,58 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/reject.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/get_position.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +namespace +{ + template <class T> + struct returns + { + typedef T type; + }; + + template <class T> + struct get_foo + { + typedef typename T::foo type; + }; +} + +BOOST_METAPARSE_TEST_CASE(reject) +{ + using boost::metaparse::reject; + using boost::metaparse::start; + using boost::metaparse::get_message; + using boost::metaparse::get_position; + + using boost::is_same; + + // test_reject_is_metaprogramming_value + BOOST_MPL_ASSERT((is_same<reject<int, start>, reject<int, start>::type>)); + + // test_reject_is_not_lazy + BOOST_MPL_ASSERT(( + is_same< + reject<get_foo<int>, start>, + reject<get_foo<int>, returns<start> >::type + > + )); + + // test_get_message_of_reject + BOOST_MPL_ASSERT((is_same<int, get_message<reject<int, start> >::type>)); + + // test_get_position_of_reject + BOOST_MPL_ASSERT((is_same<start, get_position<reject<int, start> >::type>)); +} + diff --git a/src/boost/libs/metaparse/test/repeated.cpp b/src/boost/libs/metaparse/test/repeated.cpp new file mode 100644 index 000000000..f7b57da1b --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> + +using boost::metaparse::repeated; + +#define TEST_NAME repeated + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated1.cpp b/src/boost/libs/metaparse/test/repeated1.cpp new file mode 100644 index 000000000..c1d47b23a --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated1.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated1.hpp> + +using boost::metaparse::repeated1; + +#define TEST_NAME repeated1 + +#include "repeated1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated1_test.hpp b/src/boost/libs/metaparse/test/repeated1_test.hpp new file mode 100644 index 000000000..848b23221 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated1_test.hpp @@ -0,0 +1,99 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::apply_wrap2; + using boost::mpl::list; + using boost::mpl::vector_c; + using boost::mpl::vector; + + typedef repeated1<letter> repeated1_letter; + typedef always<one_char, int> always_int; + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<repeated1_letter, str_, start> >)); + + // test0 + BOOST_MPL_ASSERT((is_error<apply_wrap2<repeated1_letter, chars0, start> >)); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars1, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars2, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars3, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); + + // test4 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars4, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l'> + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars5, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1<always_int>, str_ca, start> >::type, + vector<int, int> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/repeated_one_of.cpp b/src/boost/libs/metaparse/test/repeated_one_of.cpp new file mode 100644 index 000000000..488ae46ae --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_one_of.cpp @@ -0,0 +1,106 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_one_of.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(repeated_one_of) +{ + using boost::metaparse::fail; + using boost::metaparse::get_result; + using boost::metaparse::repeated_one_of; + using boost::metaparse::start; + using boost::metaparse::one_char; + using boost::metaparse::keyword; + + using boost::mpl::equal; + using boost::mpl::apply_wrap2; + using boost::mpl::list; + using boost::mpl::vector_c; + + typedef fail<test_failure> test_fail; + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_one_of< >, str_hello, start> >::type, + list<> + > + )); + + // test_good_sequence + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<test_fail>, str_hello, start> + >::type, + list< > + > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<one_char, test_fail>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<test_fail, one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + typedef keyword<str_h, char_h> keyword_h; + typedef keyword<str_e, char_e> keyword_e; + typedef keyword<str_l, char_l> keyword_l; + + // test_accept_any_argument + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2< + repeated_one_of<keyword_h, keyword_e, keyword_l>, + str_hello, + start + > + >::type, + list<char_h, char_e, char_l, char_l> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_one_of1.cpp b/src/boost/libs/metaparse/test/repeated_one_of1.cpp new file mode 100644 index 000000000..a4ba3013e --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_one_of1.cpp @@ -0,0 +1,100 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_one_of1.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(repeated_one_of1) +{ + using boost::metaparse::fail; + using boost::metaparse::is_error; + using boost::metaparse::repeated_one_of1; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::one_char; + using boost::metaparse::keyword; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + using boost::mpl::list; + using boost::mpl::vector_c; + + typedef fail<test_failure> test_fail; + + // test0 + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<repeated_one_of1< >, str_hello, start> > + )); + + // test_good_sequence + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of1<one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<repeated_one_of1<test_fail>, str_hello, start> > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of1<one_char, test_fail>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of1<test_fail, one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + typedef keyword<str_h, char_h> keyword_h; + typedef keyword<str_e, char_e> keyword_e; + typedef keyword<str_l, char_l> keyword_l; + + // test_accept_any_argument + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2< + repeated_one_of1<keyword_h, keyword_e, keyword_l>, + str_hello, + start + > + >::type, + list<char_h, char_e, char_l, char_l> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete.cpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete.cpp new file mode 100644 index 000000000..3bf61c970 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_reject_incomplete.hpp> + +using boost::metaparse::repeated_reject_incomplete; + +#define TEST_NAME repeated_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete1.cpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete1.cpp new file mode 100644 index 000000000..145d3866d --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete1.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_reject_incomplete1.hpp> + +using boost::metaparse::repeated_reject_incomplete1; + +#define TEST_NAME repeated_reject_incomplete1 + +#include "repeated_reject_incomplete1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete1_test.hpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete1_test.hpp new file mode 100644 index 000000000..5e3fda368 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete1_test.hpp @@ -0,0 +1,173 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::sequence; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::size; + + typedef sequence<letter, letter> letter_pair; + typedef + repeated_reject_incomplete1<letter_pair> + repeated_reject_incomplete1_letter_pair; + typedef always<one_char, int> always_int; + + typedef boost::mpl::vector_c<char, 'h','e','l','l','o','w','0'> chars6; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','0'> + chars8; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','l','d','0'> + chars10; + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete1_letter_pair, str_, start> + > + )); + + // test0 + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars0, start> + > + )); + + // test1_pair + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars2, start> + >::type, + vector<vector_c<char, 'h', 'e'> >, + equal_sequences + > + )); + + // test_with_a_failing_item + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars3, start> + > + )); + + // test2_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars4, start> + >::type, + vector<vector_c<char, 'h','e'>, vector_c<char, 'l','l'> >, + equal_sequences + > + )); + + // test3_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars6, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'> + >, + equal_sequences + > + )); + + // test4_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars8, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'> + >, + equal_sequences + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars10, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'>, + vector_c<char, 'l','d'> + >, + equal_sequences + > + )); + + // test_length + BOOST_MPL_ASSERT(( + equal_to< + size< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars6, start> + >::type + >::type, + int3 + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1<always_int>, str_ca, start> + >::type, + vector<int, int> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete_test.hpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete_test.hpp new file mode 100644 index 000000000..5f21b2f16 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete_test.hpp @@ -0,0 +1,176 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::sequence; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::size; + + typedef sequence<letter, letter> letter_pair; + typedef + repeated_reject_incomplete<letter_pair> + repeated_reject_incomplete_letter_pair; + typedef always<one_char, int> always_int; + + typedef boost::mpl::vector_c<char, 'h','e','l','l','o','w','0'> chars6; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','0'> + chars8; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','l','d','0'> + chars10; + + // test_empty_input + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, str_, start> + >::type, + vector<> + > + )); + + // test0 + BOOST_MPL_ASSERT_NOT(( + is_error< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars0, start> + > + )); + + // test_with_a_failing_item + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars1, start> + > + )); + + // test1_pair + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars2, start> + >::type, + vector<vector_c<char, 'h', 'e'> >, + equal_sequences + > + )); + + // test2_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars4, start> + >::type, + vector<vector_c<char, 'h','e'>, vector_c<char, 'l','l'> >, + equal_sequences + > + )); + + // test3_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars6, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'> + >, + equal_sequences + > + )); + + // test4_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars8, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'> + >, + equal_sequences + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars10, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'>, + vector_c<char, 'l','d'> + >, + equal_sequences + > + )); + + // test_length + BOOST_MPL_ASSERT(( + equal_to< + size< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars6, start> + >::type + >::type, + int3 + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete<always_int>, str_ca, start> + >::type, + vector<int, int> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_test.hpp b/src/boost/libs/metaparse/test/repeated_test.hpp new file mode 100644 index 000000000..0f2405136 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_test.hpp @@ -0,0 +1,117 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::one_char; + using boost::metaparse::always; + + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::list; + using boost::mpl::size; + + typedef repeated<letter> repeated_letter; + typedef always<one_char, int> always_int; + + // test_empty_input + BOOST_MPL_ASSERT(( + equal<get_result<apply_wrap2<repeated_letter, str_, start> >::type, list<> > + )); + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars0, start> >::type, + list<> + > + )); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars1, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars2, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars3, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); + + // test4 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars4, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l'> + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars5, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_length + BOOST_MPL_ASSERT(( + equal_to< + size< + get_result<apply_wrap2<repeated_letter, chars3, start> >::type + >::type, + int3 + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated<always_int>, str_ca, start> >::type, + vector<int, int> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/return_.cpp b/src/boost/libs/metaparse/test/return_.cpp new file mode 100644 index 000000000..8c60fba88 --- /dev/null +++ b/src/boost/libs/metaparse/test/return_.cpp @@ -0,0 +1,61 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/return_.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::return_; + + using boost::mpl::apply_wrap2; + + typedef apply_wrap2<return_<int1>, int2, int3> acc; + + typedef return_<char_x> return_x; +} + +BOOST_METAPARSE_TEST_CASE(return) +{ + using boost::metaparse::get_result; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::start; + + using boost::mpl::equal_to; + + // test_for_non_empty_string + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<return_x, str_hello, start> >::type, char_x> + )); + + // test_for_empty_string + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<return_x, str_, start> >::type, char_x> + )); + + + // test_get_result + BOOST_MPL_ASSERT((equal_to<int1, get_result<acc>::type>)); + + // test_get_remaining + BOOST_MPL_ASSERT((equal_to<int2, get_remaining<acc>::type>)); + + // test_get_position + BOOST_MPL_ASSERT((equal_to<int3, get_position<acc>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/returns.cpp b/src/boost/libs/metaparse/test/returns.cpp new file mode 100644 index 000000000..47f5ed82d --- /dev/null +++ b/src/boost/libs/metaparse/test/returns.cpp @@ -0,0 +1,23 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/returns.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(returns) +{ + using boost::metaparse::v1::impl::returns; + + using boost::is_same; + + // test_returns_evaluates_to_its_argument + BOOST_MPL_ASSERT((is_same<int, returns<int>::type>)); +} + diff --git a/src/boost/libs/metaparse/test/sequence.cpp b/src/boost/libs/metaparse/test/sequence.cpp new file mode 100644 index 000000000..bc2757784 --- /dev/null +++ b/src/boost/libs/metaparse/test/sequence.cpp @@ -0,0 +1,115 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(sequence) +{ + using boost::metaparse::get_result; + using boost::metaparse::sequence; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::apply_wrap2; + using boost::mpl::list; + using boost::mpl::equal_to; + using boost::mpl::at_c; + using boost::mpl::vector_c; + using boost::mpl::vector; + + typedef always<one_char, int> always_int; + + // test_no_parser + BOOST_MPL_ASSERT(( + equal<get_result<apply_wrap2<sequence<>, str_hello, start> >::type, list<> > + )); + + // test_one_parser + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<sequence<lit_h>, str_hello, start> >::type, + vector_c<char, 'h'> + > + )); + + // test_one_failing_parser + BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_e>, str_hello, start> >)); + + // test_two_chars + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<sequence<lit_h, lit_e>, str_hello, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<sequence<lit_x, lit_e>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<sequence<lit_h, lit_x>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_h,lit_e>, str_,start> >)); + + // test_three_chars + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); + + // test_indexing_in_result + BOOST_MPL_ASSERT(( + equal_to< + at_c< + get_result< + apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + 1 + >::type, + char_e + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<sequence<always_int, always_int>, str_ca, start> + >::type, + vector<int, int> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/sequence_apply.cpp b/src/boost/libs/metaparse/test/sequence_apply.cpp new file mode 100644 index 000000000..4d4cd5c6c --- /dev/null +++ b/src/boost/libs/metaparse/test/sequence_apply.cpp @@ -0,0 +1,162 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/sequence_apply.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/preprocessor/repetition/repeat_from_to.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/enum.hpp> +#include <boost/preprocessor/tuple/eat.hpp> +#include <boost/preprocessor/cat.hpp> + +#include "test_case.hpp" + +namespace +{ +#ifdef BOOST_METAPARSE_C_VALUE +# error BOOST_METAPARSE_C_VALUE already defined +#endif +#define BOOST_METAPARSE_C_VALUE(z, n, unused) BOOST_PP_CAT(C, n)::value + +#ifdef BOOST_METAPARSE_TEMPLATE +# error BOOST_METAPARSE_TEMPLATE already defined +#endif +#define BOOST_METAPARSE_TEMPLATE(z, n, unused) \ + template <BOOST_PP_ENUM(n, char BOOST_PP_TUPLE_EAT(3), ~)> \ + struct BOOST_PP_CAT(template_c, n) \ + { \ + typedef BOOST_PP_CAT(template_c, n) type; \ + }; \ + \ + template <BOOST_PP_ENUM_PARAMS(n, class C)> \ + struct BOOST_PP_CAT(template, n) \ + { \ + typedef \ + BOOST_PP_CAT(template_c, n)< \ + BOOST_PP_ENUM(n, BOOST_METAPARSE_C_VALUE, ~) \ + > \ + type; \ + }; + + BOOST_PP_REPEAT_FROM_TO(1, 4, BOOST_METAPARSE_TEMPLATE, ~) + +#undef BOOST_METAPARSE_TEMPLATE +#undef BOOST_METAPARSE_C_VALUE + + template <class T> struct has_no_type {}; + + // "is_same<T::type::type, double_eval<T>::type>" - helper tool to avoid + // writing type::type (which is interpreted as the constructor of ::type by + // msvc-7.1) + template <class T> struct double_eval : T::type {}; +} + +BOOST_METAPARSE_TEST_CASE(sequence_apply) +{ + using boost::metaparse::get_result; + using boost::metaparse::sequence_apply1; + using boost::metaparse::sequence_apply2; + using boost::metaparse::sequence_apply3; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::list; + using boost::mpl::equal_to; + using boost::mpl::at_c; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::char_; + + using boost::is_same; + + typedef always<one_char, int> always_int; + + // test_one_parser + BOOST_MPL_ASSERT(( + is_same< + template_c1<'h'>, + double_eval< + get_result< + sequence_apply1<template1, lit_h>::apply<str_hello, start> + > + >::type + > + )); + + // test_one_failing_parser + BOOST_MPL_ASSERT(( + is_error<sequence_apply1<template1, lit_e>::apply<str_hello, start> > + )); + + // test_two_chars + BOOST_MPL_ASSERT(( + is_same< + template_c2<'h', 'e'>, + double_eval< + get_result< + sequence_apply2<template2, lit_h, lit_e>::apply<str_hello, start> + > + >::type + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<sequence_apply2<template2, lit_x, lit_e>::apply<str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<sequence_apply2<template2, lit_h, lit_x>::apply<str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<sequence_apply2<template2, lit_h, lit_e>::apply<str_,start> > + )); + + // test_three_chars + BOOST_MPL_ASSERT(( + is_same< + template_c3<'h', 'e', 'l'>, + double_eval< + get_result< + sequence_apply3<template3, lit_h, lit_e, lit_l> + ::apply<str_hello, start> + > + >::type + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + is_same< + has_no_type<int>, + get_result< + sequence_apply1<has_no_type, always_int>::apply<str_ca, start> + >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/size.cpp b/src/boost/libs/metaparse/test/size.cpp new file mode 100644 index 000000000..62ae0a6ae --- /dev/null +++ b/src/boost/libs/metaparse/test/size.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/size.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/size.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(size) +{ + using boost::metaparse::v1::impl::size; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::int_; + + // test_0 + BOOST_MPL_ASSERT((equal_to<int_<0>, size<string<> >::type>)); + + // test_1_ + BOOST_MPL_ASSERT((equal_to<int_<1>, size<string<'x'> >::type>)); + + // test_5 + BOOST_MPL_ASSERT((equal_to<int_<4>, size<string<'1','2','3','4'> >::type>)); + +} + + diff --git a/src/boost/libs/metaparse/test/source_position.cpp b/src/boost/libs/metaparse/test/source_position.cpp new file mode 100644 index 000000000..4715bc582 --- /dev/null +++ b/src/boost/libs/metaparse/test/source_position.cpp @@ -0,0 +1,339 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/source_position.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/next_char.hpp> +#include <boost/metaparse/next_line.hpp> +#include <boost/metaparse/get_prev_char.hpp> +#include <boost/metaparse/get_line.hpp> +#include <boost/metaparse/get_col.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/not_equal_to.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/less.hpp> +#include <boost/mpl/greater.hpp> +#include <boost/mpl/greater_equal.hpp> +#include <boost/mpl/less_equal.hpp> +#include <boost/mpl/not.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::source_position; + using boost::metaparse::next_char; + using boost::metaparse::start; + + typedef source_position<int11, int13, int1> sp; + typedef next_char<start, char_0> next0; + } + +BOOST_METAPARSE_TEST_CASE(source_position) +{ + using boost::metaparse::get_line; + using boost::metaparse::get_col; + using boost::metaparse::get_prev_char; + using boost::metaparse::next_line; + + using boost::mpl::equal_to; + using boost::mpl::not_equal_to; + + using boost::mpl::not_; + using boost::mpl::less; + using boost::mpl::greater; + using boost::mpl::greater_equal; + using boost::mpl::less_equal; + + // test_get_line + BOOST_MPL_ASSERT((equal_to<int11, get_line<sp>::type>)); + + // test_get_col + BOOST_MPL_ASSERT((equal_to<int13, get_col<sp>::type>)); + + // test_get_prev_char + BOOST_MPL_ASSERT((equal_to<int1, get_prev_char<sp>::type>)); + + // test_line_of_start + BOOST_MPL_ASSERT((equal_to<int1, get_line<start>::type>)); + + // test_col_of_start + BOOST_MPL_ASSERT((equal_to<int1, get_col<start>::type>)); + + // test_next_chars_char + BOOST_MPL_ASSERT((equal_to<int2, get_col<next0>::type>)); + + // test_next_chars_line + BOOST_MPL_ASSERT((equal_to<int1, get_line<next0>::type>)); + + // test_next_lines_char + BOOST_MPL_ASSERT(( + equal_to<int1, get_col<next_line<next0, char_0> >::type> + )); + + // test_next_lines_line + BOOST_MPL_ASSERT(( + equal_to<int2, get_line<next_line<start, char_0> >::type> + )); + + // test_next_chars_prev_char + BOOST_MPL_ASSERT(( + equal_to<char_1, get_prev_char< next_char<start, char_1> >::type> + )); + + // test_next_lines_prev_char + BOOST_MPL_ASSERT(( + equal_to<char_1, get_prev_char<next_line<start, char_1> >::type> + )); + + // test_equal_source_positions + BOOST_MPL_ASSERT((equal_to<sp, sp>)); + + // test_equal_source_positions_when_prev_char_is_different + BOOST_MPL_ASSERT(( + not_< + equal_to< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + >::type + > + )); + + // test_not_equal_source_positions_when_line_is_different + BOOST_MPL_ASSERT(( + not_equal_to< + source_position<int11, int13, char_a>, + source_position<int13, int13, char_a> + > + )); + + // test_not_equal_source_positions_when_col_is_different + BOOST_MPL_ASSERT(( + not_equal_to< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_is_not_less_than_itself + BOOST_MPL_ASSERT(( + not_< + less< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_earlier_in_the_same_line_is_less + BOOST_MPL_ASSERT(( + less< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_in_the_same_line_is_not_less + BOOST_MPL_ASSERT(( + not_< + less< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + >::type + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_less + BOOST_MPL_ASSERT(( + less< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + > + )); + + // test_source_position_earlier_line_is_less + BOOST_MPL_ASSERT(( + less< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_line_is_not_less + BOOST_MPL_ASSERT(( + not_< + less< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_is_greater_equal_to_itself + BOOST_MPL_ASSERT(( + greater_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_earlier_in_the_same_line_is_not_greater_equal + BOOST_MPL_ASSERT(( + not_< + greater_equal< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_in_the_same_line_is_greater_equal + BOOST_MPL_ASSERT(( + greater_equal< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_not_greater_equal + BOOST_MPL_ASSERT(( + not_< + greater_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + >::type + > + )); + + // test_source_position_earlier_line_is_not_greater_equal + BOOST_MPL_ASSERT(( + not_< + greater_equal< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_line_is_greater_equal + BOOST_MPL_ASSERT(( + greater_equal< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_is_not_greater_than_itself + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_earlier_in_the_same_line_is_not_greater + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_in_the_same_line_is_greater + BOOST_MPL_ASSERT(( + greater< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_not_greater + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + >::type + > + )); + + // test_source_position_earlier_line_is_not_greater + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_line_is_greater + BOOST_MPL_ASSERT(( + greater< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_is_less_equal_to_itself + BOOST_MPL_ASSERT(( + less_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_earlier_in_the_same_line_is_less_equal + BOOST_MPL_ASSERT(( + less_equal< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_in_the_same_line_is_not_less_equal + BOOST_MPL_ASSERT(( + not_< + less_equal< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + >::type + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_less_equal + BOOST_MPL_ASSERT(( + less_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + > + )); + + // test_source_position_earlier_line_is_less_equal + BOOST_MPL_ASSERT(( + less_equal< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_line_is_not_less_equal + BOOST_MPL_ASSERT(( + not_< + less_equal< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/space.cpp b/src/boost/libs/metaparse/test/space.cpp new file mode 100644 index 000000000..5ae594cb2 --- /dev/null +++ b/src/boost/libs/metaparse/test/space.cpp @@ -0,0 +1,79 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/space.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::mpl::list_c; + + typedef list_c<char, '\t', 'e', 'l', 'l', 'o'> str_with_t; + typedef list_c<char, '\n', 'e', 'l', 'l', 'o'> str_with_n; + typedef list_c<char, '\r', 'e', 'l', 'l', 'o'> str_with_r; +} + +BOOST_METAPARSE_TEST_CASE(space) +{ + using boost::metaparse::is_error; + using boost::metaparse::space; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::char_; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<space, str_hello, start> >)); + + // test_with_space + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str__ello, start> >::type, + char_<' '> + > + )); + + // test_with_tab + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str_with_t, start> >::type, + char_<'\t'> + > + )); + + // test_with_line_feed + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str_with_n, start> >::type, + char_<'\n'> + > + )); + + // test_with_c_return + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str_with_r, start> >::type, + char_<'\r'> + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<space, str_, start> >)); +} + + diff --git a/src/boost/libs/metaparse/test/spaces.cpp b/src/boost/libs/metaparse/test/spaces.cpp new file mode 100644 index 000000000..1dbfe0fb3 --- /dev/null +++ b/src/boost/libs/metaparse/test/spaces.cpp @@ -0,0 +1,70 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/spaces.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::mpl::list_c; + + typedef list_c<char, 'e', 'l', 'l', 'o'> str_ello; + typedef + list_c<char, ' ', '\t', '\n', '\r', 'e', 'l', 'l', 'o'> + str_____ello; + +} + +BOOST_METAPARSE_TEST_CASE(spaces) +{ + using boost::metaparse::is_error; + using boost::metaparse::spaces; + using boost::metaparse::start; + using boost::metaparse::get_remaining; + + using boost::mpl::apply_wrap2; + using boost::mpl::not_; + using boost::mpl::equal; + + // test_reject_no_space + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<spaces, str_hello, start> > + )); + + // test_accept_one_space + BOOST_MPL_ASSERT(( + not_<is_error<apply_wrap2<spaces, str__ello, start> > > + )); + + // test_accept_only_space + BOOST_MPL_ASSERT(( + equal<get_remaining<apply_wrap2<spaces, str__ello, start> >::type, str_ello> + )); + + // test_accept_all_spaces + BOOST_MPL_ASSERT((not_<is_error<apply_wrap2<spaces, str_____ello,start> > >)); + + // test_consume_all_spaces + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<spaces, str_____ello, start> >::type, + str_ello + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/string.cpp b/src/boost/libs/metaparse/test/string.cpp new file mode 100644 index 000000000..779946eca --- /dev/null +++ b/src/boost/libs/metaparse/test/string.cpp @@ -0,0 +1,166 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MODULE string + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 64 + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/begin_end.hpp> +#include <boost/mpl/deref.hpp> +#include <boost/mpl/advance.hpp> +#include <boost/mpl/next.hpp> +#include <boost/mpl/prior.hpp> +#include <boost/mpl/distance.hpp> +#include <boost/mpl/clear.hpp> +#include <boost/mpl/empty.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/pop_front.hpp> +#include <boost/mpl/pop_back.hpp> +#include <boost/mpl/push_front.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/string.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/test/unit_test.hpp> + +#include <string> + +BOOST_AUTO_TEST_CASE(test_string) +{ + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::char_; + using boost::mpl::int_; + using boost::mpl::at; + using boost::mpl::at_c; + using boost::mpl::size; + using boost::mpl::back; + using boost::mpl::deref; + using boost::mpl::advance; + using boost::mpl::next; + using boost::mpl::prior; + using boost::mpl::distance; + using boost::mpl::clear; + using boost::mpl::empty; + using boost::mpl::front; + using boost::mpl::is_sequence; + using boost::mpl::pop_front; + using boost::mpl::pop_back; + using boost::mpl::begin; + using boost::mpl::end; + using boost::mpl::c_str; + using boost::mpl::push_front; + using boost::mpl::push_back; + + using namespace boost; + + // string type + /////////////////////// + + typedef metaparse::string<'H','e','l','l','o'> hello; + typedef metaparse::string<> empty_string; + + typedef begin<hello>::type begin_hello; + typedef end<hello>::type end_hello; + + // test_value_of_empty_string + BOOST_REQUIRE_EQUAL(std::string(), c_str<empty_string>::type::value); + + // test_value + BOOST_REQUIRE_EQUAL(std::string("Hello"), c_str<hello>::type::value); + + // equal_to + BOOST_MPL_ASSERT((equal_to<hello, hello>)); + BOOST_MPL_ASSERT_NOT((equal_to<hello, empty_string>)); + + // at + BOOST_MPL_ASSERT((equal_to<char_<'e'>, at<hello, int_<1> >::type>)); + BOOST_MPL_ASSERT((equal_to<char_<'e'>, at_c<hello, 1>::type>)); + + // size + BOOST_MPL_ASSERT((equal_to<int_<5>, size<hello>::type>)); + + // is_sequence + BOOST_MPL_ASSERT((is_sequence<hello>)); + + // front + BOOST_MPL_ASSERT((equal_to<char_<'H'>, front<hello>::type>)); + + // push_front + BOOST_MPL_ASSERT(( + equal_to< + metaparse::string<'x','H','e','l','l','o'>, + push_front<hello, char_<'x'> >::type + > + )); + + // back + BOOST_MPL_ASSERT((equal_to<char_<'o'>, back<hello>::type>)); + + // push_back + BOOST_MPL_ASSERT(( + equal_to< + metaparse::string<'H','e','l','l','o', 'x'>, + push_back<hello, char_<'x'> >::type + > + )); + + // clear + BOOST_MPL_ASSERT((equal_to<empty_string, clear<hello>::type>)); + + // empty + BOOST_MPL_ASSERT_NOT((empty<hello>::type)); + BOOST_MPL_ASSERT((empty<empty_string>::type)); + + // string_iterator + BOOST_MPL_ASSERT((equal_to<begin_hello, begin_hello>)); + BOOST_MPL_ASSERT_NOT((equal_to<begin_hello, end_hello>)); + BOOST_MPL_ASSERT(( + equal_to<begin<empty_string>::type, end<empty_string>::type> + )); + + BOOST_MPL_ASSERT((equal_to<char_<'H'>, deref<begin_hello>::type>)); + BOOST_MPL_ASSERT((equal_to<end_hello, advance<begin_hello, int_<5> >::type>)); + BOOST_MPL_ASSERT(( + equal_to<char_<'e'>, deref<next<begin_hello>::type>::type> + )); + BOOST_MPL_ASSERT((equal_to<char_<'o'>, deref<prior<end_hello>::type>::type>)); + + BOOST_MPL_ASSERT((equal_to<int_<5>, distance<begin_hello, end_hello>::type>)); + + // pop_front + BOOST_MPL_ASSERT(( + equal_to<metaparse::string<'e','l','l','o'>, pop_front<hello>::type> + )); + + // pop_back + BOOST_MPL_ASSERT(( + equal_to<metaparse::string<'H','e','l','l'>, pop_back<hello>::type> + )); + +#if BOOST_METAPARSE_STD >= 2011 + // BOOST_METAPARSE_STRING macro + /////////////////////// + + // test_empty_string + BOOST_MPL_ASSERT((equal<BOOST_METAPARSE_STRING(""), empty_string>)); + + // test_string_creation + BOOST_MPL_ASSERT((equal<BOOST_METAPARSE_STRING("Hello"), hello>)); +#endif + +} + diff --git a/src/boost/libs/metaparse/test/string_iterator_tag.cpp b/src/boost/libs/metaparse/test/string_iterator_tag.cpp new file mode 100644 index 000000000..49b4d7587 --- /dev/null +++ b/src/boost/libs/metaparse/test/string_iterator_tag.cpp @@ -0,0 +1,23 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/string_iterator_tag.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(string_iterator_tag) +{ + using boost::metaparse::v1::impl::string_iterator_tag; + + using boost::is_same; + + // test_metaprogramming_value + BOOST_MPL_ASSERT((is_same<string_iterator_tag, string_iterator_tag::type>)); +} + diff --git a/src/boost/libs/metaparse/test/string_macros.hpp b/src/boost/libs/metaparse/test/string_macros.hpp new file mode 100644 index 000000000..5f0926f3c --- /dev/null +++ b/src/boost/libs/metaparse/test/string_macros.hpp @@ -0,0 +1,82 @@ +#ifndef BOOST_METAPARSE_TEST_STRING_MACROS_HPP +#define BOOST_METAPARSE_TEST_STRING_MACROS_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifdef BOOST_METAPARSE_TEST_CHARS_10 +# error BOOST_METAPARSE_TEST_CHARS_10 already defined +#endif +#define BOOST_METAPARSE_TEST_CHARS_10 \ + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' + +#ifdef BOOST_METAPARSE_TEST_CHARS_100 +# error BOOST_METAPARSE_TEST_CHARS_100 already defined +#endif +#define BOOST_METAPARSE_TEST_CHARS_100 \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10 + +#ifdef BOOST_METAPARSE_TEST_CHARS_1000 +# error BOOST_METAPARSE_TEST_CHARS_1000 already defined +#endif +#define BOOST_METAPARSE_TEST_CHARS_1000 \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100 + + +#ifdef BOOST_METAPARSE_TEST_STRING_10 +# error BOOST_METAPARSE_TEST_STRING_10 already defined +#endif +#define BOOST_METAPARSE_TEST_STRING_10 "0123456789" + +#ifdef BOOST_METAPARSE_TEST_STRING_100 +# error BOOST_METAPARSE_TEST_STRING_100 already defined +#endif +#define BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 + +#ifdef BOOST_METAPARSE_TEST_STRING_1000 +# error BOOST_METAPARSE_TEST_STRING_1000 already defined +#endif +#define BOOST_METAPARSE_TEST_STRING_1000 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 + +#endif + diff --git a/src/boost/libs/metaparse/test/string_tag.cpp b/src/boost/libs/metaparse/test/string_tag.cpp new file mode 100644 index 000000000..73f44803e --- /dev/null +++ b/src/boost/libs/metaparse/test/string_tag.cpp @@ -0,0 +1,23 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/string_tag.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(string_tag) +{ + using boost::metaparse::string_tag; + + using boost::is_same; + + // test_metaprogramming_value + BOOST_MPL_ASSERT((is_same<string_tag, string_tag::type>)); +} + diff --git a/src/boost/libs/metaparse/test/swap.cpp b/src/boost/libs/metaparse/test/swap.cpp new file mode 100644 index 000000000..8c366569f --- /dev/null +++ b/src/boost/libs/metaparse/test/swap.cpp @@ -0,0 +1,52 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/swap.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct returns_first + { + typedef returns_first type; + + template <class A, class> + struct apply + { + typedef A type; + }; + }; + + struct returns_second + { + typedef returns_second type; + + template <class, class B> + struct apply + { + typedef B type; + }; + }; +} + +BOOST_METAPARSE_TEST_CASE(swap) +{ + using boost::metaparse::v1::swap; + using boost::is_same; + + BOOST_MPL_ASSERT(( + is_same<double, swap<returns_first>::apply<int, double>::type> + )); + + BOOST_MPL_ASSERT(( + is_same<int, swap<returns_second>::apply<int, double>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/test_case.hpp b/src/boost/libs/metaparse/test/test_case.hpp new file mode 100644 index 000000000..f60db17ac --- /dev/null +++ b/src/boost/libs/metaparse/test/test_case.hpp @@ -0,0 +1,18 @@ +#ifndef BOOST_METAPARSE_TEST_TEST_CASE_HPP +#define BOOST_METAPARSE_TEST_TEST_CASE_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/preprocessor/cat.hpp> + +#ifdef BOOST_METAPARSE_TEST_CASE +# error BOOST_METAPARSE_TEST_CASE already defined +#endif +#define BOOST_METAPARSE_TEST_CASE(name) \ + void BOOST_PP_CAT(metaparse_test_case_, name)() + +#endif + diff --git a/src/boost/libs/metaparse/test/token.cpp b/src/boost/libs/metaparse/test/token.cpp new file mode 100644 index 000000000..94ef6d7f8 --- /dev/null +++ b/src/boost/libs/metaparse/test/token.cpp @@ -0,0 +1,74 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::keyword; + using boost::metaparse::token; + + using boost::mpl::list_c; + + typedef list_c<char, 'h', 'e', 'l', 'l', 'o', ' ', '\t'> str_hello_t; + + typedef keyword<str_hello, int13> test_parser; + typedef token<test_parser> a_test_token; +} + +BOOST_METAPARSE_TEST_CASE(token) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::get_remaining; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + + // test_no_space + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<a_test_token, str_hello, start> >::type, + get_result<apply_wrap2<test_parser, str_hello, start> >::type + > + )); + + // test_spaces + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<a_test_token, str_hello_t, start> >::type, + get_result<apply_wrap2<test_parser, str_hello, start> >::type + > + )); + + // test_spaces_consumed + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<a_test_token, str_hello_t, start> >::type, + str_ + > + )); + + // test_fail + BOOST_MPL_ASSERT((is_error<apply_wrap2<a_test_token, str_, start> >)); +} + + diff --git a/src/boost/libs/metaparse/test/too_long_string.cpp b/src/boost/libs/metaparse/test/too_long_string.cpp new file mode 100644 index 000000000..738d523aa --- /dev/null +++ b/src/boost/libs/metaparse/test/too_long_string.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 4 +#include <boost/metaparse/string.hpp> + +namespace +{ + typedef BOOST_METAPARSE_STRING("abcde") too_long; +} + diff --git a/src/boost/libs/metaparse/test/transform.cpp b/src/boost/libs/metaparse/test/transform.cpp new file mode 100644 index 000000000..3b21f75bc --- /dev/null +++ b/src/boost/libs/metaparse/test/transform.cpp @@ -0,0 +1,79 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/always.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::repeated; + using boost::metaparse::one_char; + + using boost::mpl::always; + + typedef always<char_x> f; + typedef repeated<one_char> repeated_one_char; + + struct get_front + { + typedef get_front type; + + template <class C> + struct apply : boost::mpl::front<C> {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(transform) +{ + using boost::metaparse::get_result; + using boost::metaparse::transform; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_normal_case + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<transform<lit_h, f>, str_hello, start> >::type, + char_x + > + )); + + // test_parser_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<transform<lit_x, f>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<transform<lit_h, f>, str_, start> >)); + + // test_tranformation_functions_arg + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<transform<repeated_one_char, get_front>, str_hello, start> + >::type, + char_h + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/transform_error.cpp b/src/boost/libs/metaparse/test/transform_error.cpp new file mode 100644 index 000000000..2a9a52c84 --- /dev/null +++ b/src/boost/libs/metaparse/test/transform_error.cpp @@ -0,0 +1,65 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/transform_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/reject.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_position.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +using boost::metaparse::reject; +using boost::metaparse::get_position; + +namespace +{ + struct new_message + { + typedef new_message type; + }; + + struct change_message + { + typedef change_message type; + + template <class E> + struct apply : reject<new_message, get_position<E> > {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(transform_error) +{ + using boost::metaparse::transform_error; + using boost::metaparse::start; + using boost::metaparse::string; + using boost::metaparse::lit_c; + + using boost::is_same; + + typedef string<'H','e','l','l','o'> s; + + // test_transform_error_does_not_change_accept + BOOST_MPL_ASSERT(( + is_same< + lit_c<'H'>::apply<s, start>::type, + transform_error<lit_c<'H'>, change_message>::apply<s, start>::type + > + )); + + // test_transform_is_called + BOOST_MPL_ASSERT(( + is_same< + reject<new_message, start>, + transform_error<lit_c<'x'>, change_message>::apply<s, start>::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/transform_error_message.cpp b/src/boost/libs/metaparse/test/transform_error_message.cpp new file mode 100644 index 000000000..23cf3def7 --- /dev/null +++ b/src/boost/libs/metaparse/test/transform_error_message.cpp @@ -0,0 +1,68 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/transform_error_message.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/reject.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +using boost::metaparse::reject; +using boost::metaparse::get_position; + +namespace +{ + template <class OldMsg> + struct new_message + { + typedef new_message type; + }; + + struct change_message + { + typedef change_message type; + + template <class Msg> + struct apply : new_message<Msg> {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(transform_error_message) +{ + using boost::metaparse::transform_error_message; + using boost::metaparse::start; + using boost::metaparse::string; + using boost::metaparse::lit_c; + using boost::metaparse::error::literal_expected; + + using boost::is_same; + + typedef string<'H','e','l','l','o'> s; + + // test_transform_error_message_does_not_change_accept + BOOST_MPL_ASSERT(( + is_same< + lit_c<'H'>::apply<s, start>::type, + transform_error_message<lit_c<'H'>, change_message>::apply<s, start>::type + > + )); + + // test_transform_is_called + BOOST_MPL_ASSERT(( + is_same< + reject<new_message<literal_expected<'x'> >, start>, + transform_error_message<lit_c<'x'>, change_message>::apply<s, start>::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/unless_error.cpp b/src/boost/libs/metaparse/test/unless_error.cpp new file mode 100644 index 000000000..b8315adda --- /dev/null +++ b/src/boost/libs/metaparse/test/unless_error.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/unless_error.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/fail.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::mpl::apply_wrap2; + using boost::metaparse::fail; + + typedef apply_wrap2<fail<int1>, int11, int2> err; +} + +BOOST_METAPARSE_TEST_CASE(util_unless_error) +{ + using boost::metaparse::is_error; + using boost::metaparse::unless_error; + + using boost::mpl::equal_to; + + // test_error + BOOST_MPL_ASSERT((is_error<unless_error<err, int13> >)); + + // test_not_error + BOOST_MPL_ASSERT((equal_to<int13, unless_error<int11, int13>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/unpaired.cpp b/src/boost/libs/metaparse/test/unpaired.cpp new file mode 100644 index 000000000..f0e4c4309 --- /dev/null +++ b/src/boost/libs/metaparse/test/unpaired.cpp @@ -0,0 +1,36 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/error/unpaired.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +namespace +{ + struct some_tmp_value + { + typedef some_tmp_value type; + }; +} + +BOOST_METAPARSE_TEST_CASE(unpaired) +{ + using boost::metaparse::error::unpaired; + + using boost::is_same; + + // test_unpaired_currying + BOOST_MPL_ASSERT(( + is_same< + unpaired<1, 2, some_tmp_value>, + unpaired<1, 2>::apply<some_tmp_value>::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/update_c.cpp b/src/boost/libs/metaparse/test/update_c.cpp new file mode 100644 index 000000000..94f9ab0c4 --- /dev/null +++ b/src/boost/libs/metaparse/test/update_c.cpp @@ -0,0 +1,43 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD < 2011 + +#include <boost/metaparse/v1/cpp98/impl/update_c.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(update_c) +{ + using boost::metaparse::v1::impl::update_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + + typedef string<'h','e','l','l','o'> hello; + + // test_update_first_char + BOOST_MPL_ASSERT(( + equal_to<string<'x','e','l','l','o'>, update_c<hello, 0, 'x'>::type> + )); + + // test_update_middle_char + BOOST_MPL_ASSERT(( + equal_to<string<'h','e','x','l','o'>, update_c<hello, 2, 'x'>::type> + )); + + // test_update_last_char + BOOST_MPL_ASSERT(( + equal_to<string<'h','e','l','l','x'>, update_c<hello, 4, 'x'>::type> + )); +} + +#endif + diff --git a/src/boost/libs/metaparse/test/version.cpp b/src/boost/libs/metaparse/test/version.cpp new file mode 100644 index 000000000..9eec59082 --- /dev/null +++ b/src/boost/libs/metaparse/test/version.cpp @@ -0,0 +1,20 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/version.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/bool.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(version) +{ + using boost::mpl::bool_; + + // test_version_number + BOOST_MPL_ASSERT((bool_<BOOST_METAPARSE_VERSION == 10000000>)); +} + diff --git a/src/boost/libs/metaparse/tools/benchmark/README.md b/src/boost/libs/metaparse/tools/benchmark/README.md new file mode 100644 index 000000000..b2fbf2446 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/README.md @@ -0,0 +1,14 @@ +This directory contains benchmarks for the library. + +The characters to use in the benchmarks and their distribution is coming from +`chars.py`. This is an automatically generated file and can be regenerated using +`char_stat.py`. It represents the distribution of characters of the Boost 1.61.0 +header files. + +To regenerate the benchmarks: + +* Generate the source files by running `generate.py`. Unless specified + otherwise, it will generate the source files found in `src` to `generated`. +* Run the benchmarks by running `benchmark.py`. Unless specified otherwise, it + will benchmark the compilation of the source files in `generated` and generate + the diagrams into the library's documentation. diff --git a/src/boost/libs/metaparse/tools/benchmark/benchmark.py b/src/boost/libs/metaparse/tools/benchmark/benchmark.py new file mode 100755 index 000000000..46d3ef9fa --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/benchmark.py @@ -0,0 +1,354 @@ +#!/usr/bin/python +"""Utility to benchmark the generated source files""" + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import argparse +import os +import subprocess +import json +import math +import platform +import matplotlib +import random +import re +import time +import psutil +import PIL + +matplotlib.use('Agg') +import matplotlib.pyplot # pylint:disable=I0011,C0411,C0412,C0413 + + +def benchmark_command(cmd, progress): + """Benchmark one command execution""" + full_cmd = '/usr/bin/time --format="%U %M" {0}'.format(cmd) + print '{0:6.2f}% Running {1}'.format(100.0 * progress, full_cmd) + (_, err) = subprocess.Popen( + ['/bin/sh', '-c', full_cmd], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ).communicate('') + + values = err.strip().split(' ') + if len(values) == 2: + try: + return (float(values[0]), float(values[1])) + except: # pylint:disable=I0011,W0702 + pass # Handled by the code after the "if" + + print err + raise Exception('Error during benchmarking') + + +def benchmark_file( + filename, compiler, include_dirs, (progress_from, progress_to), + iter_count, extra_flags = ''): + """Benchmark one file""" + time_sum = 0 + mem_sum = 0 + for nth_run in xrange(0, iter_count): + (time_spent, mem_used) = benchmark_command( + '{0} -std=c++11 {1} -c {2} {3}'.format( + compiler, + ' '.join('-I{0}'.format(i) for i in include_dirs), + filename, + extra_flags + ), + ( + progress_to * nth_run + progress_from * (iter_count - nth_run) + ) / iter_count + ) + os.remove(os.path.splitext(os.path.basename(filename))[0] + '.o') + time_sum = time_sum + time_spent + mem_sum = mem_sum + mem_used + + return { + "time": time_sum / iter_count, + "memory": mem_sum / (iter_count * 1024) + } + + +def compiler_info(compiler): + """Determine the name + version of the compiler""" + (out, err) = subprocess.Popen( + ['/bin/sh', '-c', '{0} -v'.format(compiler)], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ).communicate('') + + gcc_clang = re.compile('(gcc|clang) version ([0-9]+(\\.[0-9]+)*)') + + for line in (out + err).split('\n'): + mtch = gcc_clang.search(line) + if mtch: + return mtch.group(1) + ' ' + mtch.group(2) + + return compiler + + +def string_char(char): + """Turn the character into one that can be part of a filename""" + return '_' if char in [' ', '~', '(', ')', '/', '\\'] else char + + +def make_filename(string): + """Turn the string into a filename""" + return ''.join(string_char(c) for c in string) + + +def files_in_dir(path, extension): + """Enumartes the files in path with the given extension""" + ends = '.{0}'.format(extension) + return (f for f in os.listdir(path) if f.endswith(ends)) + + +def format_time(seconds): + """Format a duration""" + minute = 60 + hour = minute * 60 + day = hour * 24 + week = day * 7 + + result = [] + for name, dur in [ + ('week', week), ('day', day), ('hour', hour), + ('minute', minute), ('second', 1) + ]: + if seconds > dur: + value = seconds // dur + result.append( + '{0} {1}{2}'.format(int(value), name, 's' if value > 1 else '') + ) + seconds = seconds % dur + return ' '.join(result) + + +def benchmark(src_dir, compiler, include_dirs, iter_count): + """Do the benchmarking""" + + files = list(files_in_dir(src_dir, 'cpp')) + random.shuffle(files) + has_string_templates = True + string_template_file_cnt = sum(1 for file in files if 'bmp' in file) + file_count = len(files) + string_template_file_cnt + + started_at = time.time() + result = {} + for filename in files: + progress = len(result) + result[filename] = benchmark_file( + os.path.join(src_dir, filename), + compiler, + include_dirs, + (float(progress) / file_count, float(progress + 1) / file_count), + iter_count + ) + if 'bmp' in filename and has_string_templates: + try: + temp_result = benchmark_file( + os.path.join(src_dir, filename), + compiler, + include_dirs, + (float(progress + 1) / file_count, float(progress + 2) / file_count), + iter_count, + '-Xclang -fstring-literal-templates' + ) + result[filename.replace('bmp', 'slt')] = temp_result + except: + has_string_templates = False + file_count -= string_template_file_cnt + print 'Stopping the benchmarking of string literal templates' + + elapsed = time.time() - started_at + total = float(file_count * elapsed) / len(result) + print 'Elapsed time: {0}, Remaining time: {1}'.format( + format_time(elapsed), + format_time(total - elapsed) + ) + return result + + +def plot(values, mode_names, title, (xlabel, ylabel), out_file): + """Plot a diagram""" + matplotlib.pyplot.clf() + for mode, mode_name in mode_names.iteritems(): + vals = values[mode] + matplotlib.pyplot.plot( + [x for x, _ in vals], + [y for _, y in vals], + label=mode_name + ) + matplotlib.pyplot.title(title) + matplotlib.pyplot.xlabel(xlabel) + matplotlib.pyplot.ylabel(ylabel) + if len(mode_names) > 1: + matplotlib.pyplot.legend() + matplotlib.pyplot.savefig(out_file) + + +def mkdir_p(path): + """mkdir -p path""" + try: + os.makedirs(path) + except OSError: + pass + + +def configs_in(src_dir): + """Enumerate all configs in src_dir""" + for filename in files_in_dir(src_dir, 'json'): + with open(os.path.join(src_dir, filename), 'rb') as in_f: + yield json.load(in_f) + + +def byte_to_gb(byte): + """Convert bytes to GB""" + return byte / (1024.0 * 1024 * 1024) + + +def join_images(img_files, out_file): + """Join the list of images into the out file""" + images = [PIL.Image.open(f) for f in img_files] + joined = PIL.Image.new( + 'RGB', + (sum(i.size[0] for i in images), max(i.size[1] for i in images)) + ) + left = 0 + for img in images: + joined.paste(im=img, box=(left, 0)) + left = left + img.size[0] + joined.save(out_file) + + +def plot_temp_diagrams(config, results, temp_dir): + """Plot temporary diagrams""" + display_name = { + 'time': 'Compilation time (s)', + 'memory': 'Compiler memory usage (MB)', + } + + files = config['files'] + img_files = [] + + if any('slt' in result for result in results) and 'bmp' in files.values()[0]: + config['modes']['slt'] = 'Using BOOST_METAPARSE_STRING with string literal templates' + for f in files.values(): + f['slt'] = f['bmp'].replace('bmp', 'slt') + + for measured in ['time', 'memory']: + mpts = sorted(int(k) for k in files.keys()) + img_files.append(os.path.join(temp_dir, '_{0}.png'.format(measured))) + plot( + { + m: [(x, results[files[str(x)][m]][measured]) for x in mpts] + for m in config['modes'].keys() + }, + config['modes'], + display_name[measured], + (config['x_axis_label'], display_name[measured]), + img_files[-1] + ) + return img_files + + +def plot_diagram(config, results, images_dir, out_filename): + """Plot one diagram""" + img_files = plot_temp_diagrams(config, results, images_dir) + join_images(img_files, out_filename) + for img_file in img_files: + os.remove(img_file) + + +def plot_diagrams(results, configs, compiler, out_dir): + """Plot all diagrams specified by the configs""" + compiler_fn = make_filename(compiler) + total = psutil.virtual_memory().total # pylint:disable=I0011,E1101 + memory = int(math.ceil(byte_to_gb(total))) + + images_dir = os.path.join(out_dir, 'images') + + for config in configs: + out_prefix = '{0}_{1}'.format(config['name'], compiler_fn) + + plot_diagram( + config, + results, + images_dir, + os.path.join(images_dir, '{0}.png'.format(out_prefix)) + ) + + with open( + os.path.join(out_dir, '{0}.qbk'.format(out_prefix)), + 'wb' + ) as out_f: + qbk_content = """{0} +Measured on a {2} host with {3} GB memory. Compiler used: {4}. + +[$images/metaparse/{1}.png [width 100%]] +""".format(config['desc'], out_prefix, platform.platform(), memory, compiler) + out_f.write(qbk_content) + + +def main(): + """The main function of the script""" + desc = 'Benchmark the files generated by generate.py' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument( + '--src', + dest='src_dir', + default='generated', + help='The directory containing the sources to benchmark' + ) + parser.add_argument( + '--out', + dest='out_dir', + default='../../doc', + help='The output directory' + ) + parser.add_argument( + '--include', + dest='include', + default='include', + help='The directory containing the headeres for the benchmark' + ) + parser.add_argument( + '--boost_headers', + dest='boost_headers', + default='../../../..', + help='The directory containing the Boost headers (the boost directory)' + ) + parser.add_argument( + '--compiler', + dest='compiler', + default='g++', + help='The compiler to do the benchmark with' + ) + parser.add_argument( + '--repeat_count', + dest='repeat_count', + type=int, + default=5, + help='How many times a measurement should be repeated.' + ) + + args = parser.parse_args() + + compiler = compiler_info(args.compiler) + results = benchmark( + args.src_dir, + args.compiler, + [args.include, args.boost_headers], + args.repeat_count + ) + + plot_diagrams(results, configs_in(args.src_dir), compiler, args.out_dir) + + +if __name__ == '__main__': + main() diff --git a/src/boost/libs/metaparse/tools/benchmark/char_stat.py b/src/boost/libs/metaparse/tools/benchmark/char_stat.py new file mode 100755 index 000000000..be5935dd6 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/char_stat.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +"""Utility to generate character statistics about a number of source files""" + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import argparse +import os + + +def count_characters(root, out): + """Count the occurrances of the different characters in the files""" + if os.path.isfile(root): + with open(root, 'rb') as in_f: + for line in in_f: + for char in line: + if char not in out: + out[char] = 0 + out[char] = out[char] + 1 + elif os.path.isdir(root): + for filename in os.listdir(root): + count_characters(os.path.join(root, filename), out) + + +def generate_statistics(root): + """Generate the statistics from all files in root (recursively)""" + out = dict() + count_characters(root, out) + return out + + +def main(): + """The main function of the script""" + desc = 'Generate character statistics from a source tree' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument( + '--src', + dest='src', + required=True, + help='The root of the source tree' + ) + parser.add_argument( + '--out', + dest='out', + default='chars.py', + help='The output filename' + ) + + args = parser.parse_args() + + stats = generate_statistics(args.src) + with open(args.out, 'wb') as out_f: + out_f.write('CHARS={0}\n'.format(stats)) + + +if __name__ == '__main__': + main() diff --git a/src/boost/libs/metaparse/tools/benchmark/chars.py b/src/boost/libs/metaparse/tools/benchmark/chars.py new file mode 100644 index 000000000..95357f1eb --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/chars.py @@ -0,0 +1 @@ +CHARS={' ': 22284371, '\xa3': 2, '$': 4917, '\xa7': 3, '(': 898226, '\xab': 2, ',': 2398845, '\xaf': 2, '0': 624709, '\xb3': 5, '4': 402093, '\xb7': 2, '8': 274327, '\xbb': 2, '<': 906955, '\xbf': 2, '@': 16983, '\xc3': 13, 'D': 291316, '\xc7': 2, 'H': 146671, '\xcb': 2, 'L': 404004, '\xcf': 2, 'P': 717827, '\xd3': 2, 'T': 1426865, '\xd7': 2, 'X': 80953, '\xdb': 2, '\\': 80171, '\xdf': 5, '`': 12213, '\xe3': 2, 'd': 1713185, '\xe7': 2, 'h': 787023, '\xeb': 2, 'l': 2141123, '\xef': 2, 'p': 3018561, '\xf3': 2, 't': 5917113, '\xf7': 2, 'x': 383286, '\xfb': 2, '|': 18625, '\xff': 2, '\x80': 20, '\x9c': 10, '#': 242175, '\xa4': 2, "'": 24359, '\xa8': 2, '+': 62328, '\xac': 2, '/': 1496052, '\xb0': 2, '3': 522407, '\xb4': 2, '7': 281951, '\xb8': 2, ';': 938670, '\xbc': 2, '?': 6554, '\xc0': 2, 'C': 430333, '\xc4': 2, 'G': 143243, '\xc8': 2, 'K': 90732, '\xcc': 2, 'O': 875785, '\xd0': 2, 'S': 702347, '\xd4': 2, 'W': 52216, '\xd8': 2, '[': 66305, '\xdc': 2, '_': 2992229, '\xe0': 2, 'c': 2083806, '\xe4': 2, 'g': 684087, '\xe8': 2, 'k': 165087, '\xec': 2, 'o': 3158786, '\xf0': 2, 's': 2967238, '\xf4': 2, 'w': 247018, '\xf8': 3, '{': 243686, '\xfc': 2, '\n': 2276992, '\x9d': 10, '\xa1': 2, '"': 50327, '\xa5': 2, '&': 418128, '\xa9': 4, '*': 332039, '\xad': 5, '.': 391026, '\xb1': 5, '2': 823421, '\xb5': 2, '6': 322046, '\xb9': 2, ':': 2683679, '\xbd': 2, '>': 915244, '\xc1': 2, 'B': 412447, '\xc5': 2, 'F': 174215, '\xc9': 2, 'J': 11028, '\xcd': 2, 'N': 431761, '\xd1': 2, 'R': 370532, '\xd5': 2, 'V': 120889, '\xd9': 2, 'Z': 14849, '\xdd': 2, '^': 1667, '\xe1': 2, 'b': 645436, '\xe5': 2, 'f': 1305489, '\xe9': 30, 'j': 31303, '\xed': 3, 'n': 3384988, '\xf1': 2, 'r': 2870950, '\xf5': 2, 'v': 519257, '\xf9': 2, 'z': 96213, '\xfd': 2, '~': 13463, '\t': 2920, '\r': 2276968, '!': 72758, '\xa2': 2, '%': 7081, '\xa6': 2, ')': 899122, '\xaa': 2, '-': 325139, '\xae': 2, '1': 1292007, '\xb2': 2, '5': 326024, '\xb6': 2, '9': 258472, '\xba': 4, '=': 626629, '\xbe': 2, 'A': 1040447, '\xc2': 2, 'E': 657368, '\xc6': 2, 'I': 569518, '\xca': 2, 'M': 211683, '\xce': 2, 'Q': 21541, '\xd2': 2, 'U': 218558, '\xd6': 2, 'Y': 64741, '\xda': 2, ']': 65379, '\xde': 2, 'a': 4007230, '\xe2': 22, 'e': 7280723, '\xe6': 2, 'i': 2971166, '\xea': 2, 'm': 1989243, '\xee': 2, 'q': 63623, '\xf2': 2, 'u': 1297465, '\xf6': 30, 'y': 1819692, '\xfa': 2, '}': 242894, '\xfe': 2} diff --git a/src/boost/libs/metaparse/tools/benchmark/generate.py b/src/boost/libs/metaparse/tools/benchmark/generate.py new file mode 100755 index 000000000..52526c827 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/generate.py @@ -0,0 +1,299 @@ +#!/usr/bin/python +"""Utility to generate files to benchmark""" + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import argparse +import os +import string +import random +import re +import json + +import Cheetah.Template +import chars + + +def regex_to_error_msg(regex): + """Format a human-readable error message from a regex""" + return re.sub('([^\\\\])[()]', '\\1', regex) \ + .replace('[ \t]*$', '') \ + .replace('^', '') \ + .replace('$', '') \ + .replace('[ \t]*', ' ') \ + .replace('[ \t]+', ' ') \ + .replace('[0-9]+', 'X') \ + \ + .replace('\\[', '[') \ + .replace('\\]', ']') \ + .replace('\\(', '(') \ + .replace('\\)', ')') \ + .replace('\\.', '.') + + +def mkdir_p(path): + """mkdir -p path""" + try: + os.makedirs(path) + except OSError: + pass + + +def in_comment(regex): + """Builds a regex matching "regex" in a comment""" + return '^[ \t]*//[ \t]*' + regex + '[ \t]*$' + + +def random_chars(number): + """Generate random characters""" + char_map = { + k: v for k, v in chars.CHARS.iteritems() + if not format_character(k).startswith('\\x') + } + + char_num = sum(char_map.values()) + return ( + format_character(nth_char(char_map, random.randint(0, char_num - 1))) + for _ in xrange(0, number) + ) + + +def random_string(length): + """Generate a random string or character list depending on the mode""" + return \ + 'BOOST_METAPARSE_STRING("{0}")'.format(''.join(random_chars(length))) + + +class Mode(object): + """Represents a generation mode""" + + def __init__(self, name): + self.name = name + if name == 'BOOST_METAPARSE_STRING': + self.identifier = 'bmp' + elif name == 'manual': + self.identifier = 'man' + else: + raise Exception('Invalid mode: {0}'.format(name)) + + def description(self): + """The description of the mode""" + if self.identifier == 'bmp': + return 'Using BOOST_METAPARSE_STRING' + elif self.identifier == 'man': + return 'Generating strings manually' + + def convert_from(self, base): + """Convert a BOOST_METAPARSE_STRING mode document into one with + this mode""" + if self.identifier == 'bmp': + return base + elif self.identifier == 'man': + result = [] + prefix = 'BOOST_METAPARSE_STRING("' + while True: + bmp_at = base.find(prefix) + if bmp_at == -1: + return ''.join(result) + base + else: + result.append( + base[0:bmp_at] + '::boost::metaparse::string<' + ) + new_base = '' + was_backslash = False + comma = '' + for i in xrange(bmp_at + len(prefix), len(base)): + if was_backslash: + result.append( + '{0}\'\\{1}\''.format(comma, base[i]) + ) + was_backslash = False + comma = ',' + elif base[i] == '"': + new_base = base[i+2:] + break + elif base[i] == '\\': + was_backslash = True + else: + result.append('{0}\'{1}\''.format(comma, base[i])) + comma = ',' + base = new_base + result.append('>') + + +class Template(object): + """Represents a loaded template""" + + def __init__(self, name, content): + self.name = name + self.content = content + + def instantiate(self, value_of_n): + """Instantiates the template""" + template = Cheetah.Template.Template( + self.content, + searchList={'n': value_of_n} + ) + template.random_string = random_string + return str(template) + + def range(self): + """Returns the range for N""" + match = self._match(in_comment( + 'n[ \t]+in[ \t]*\\[([0-9]+)\\.\\.([0-9]+)\\),[ \t]+' + 'step[ \t]+([0-9]+)' + )) + return range( + int(match.group(1)), + int(match.group(2)), + int(match.group(3)) + ) + + def property(self, name): + """Parses and returns a property""" + return self._get_line(in_comment(name + ':[ \t]*(.*)')) + + def modes(self): + """Returns the list of generation modes""" + return [Mode(s.strip()) for s in self.property('modes').split(',')] + + def _match(self, regex): + """Find the first line matching regex and return the match object""" + cregex = re.compile(regex) + for line in self.content.splitlines(): + match = cregex.match(line) + if match: + return match + raise Exception('No "{0}" line in {1}.cpp'.format( + regex_to_error_msg(regex), + self.name + )) + + def _get_line(self, regex): + """Get a line based on a regex""" + return self._match(regex).group(1) + + +def load_file(path): + """Returns the content of the file""" + with open(path, 'rb') as in_file: + return in_file.read() + + +def templates_in(path): + """Enumerate the templates found in path""" + ext = '.cpp' + return ( + Template(f[0:-len(ext)], load_file(os.path.join(path, f))) + for f in os.listdir(path) if f.endswith(ext) + ) + + +def nth_char(char_map, index): + """Returns the nth character of a character->occurrence map""" + for char in char_map: + if index < char_map[char]: + return char + index = index - char_map[char] + return None + + +def format_character(char): + """Returns the C-formatting of the character""" + if \ + char in string.ascii_letters \ + or char in string.digits \ + or char in [ + '_', '.', ':', ';', ' ', '!', '?', '+', '-', '/', '=', '<', + '>', '$', '(', ')', '@', '~', '`', '|', '#', '[', ']', '{', + '}', '&', '*', '^', '%']: + return char + elif char in ['"', '\'', '\\']: + return '\\{0}'.format(char) + elif char == '\n': + return '\\n' + elif char == '\r': + return '\\r' + elif char == '\t': + return '\\t' + else: + return '\\x{:02x}'.format(ord(char)) + + +def write_file(filename, content): + """Create the file with the given content""" + print 'Generating {0}'.format(filename) + with open(filename, 'wb') as out_f: + out_f.write(content) + + +def out_filename(template, n_val, mode): + """Determine the output filename""" + return '{0}_{1}_{2}.cpp'.format(template.name, n_val, mode.identifier) + + +def main(): + """The main function of the script""" + desc = 'Generate files to benchmark' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument( + '--src', + dest='src_dir', + default='src', + help='The directory containing the templates' + ) + parser.add_argument( + '--out', + dest='out_dir', + default='generated', + help='The output directory' + ) + parser.add_argument( + '--seed', + dest='seed', + default='13', + help='The random seed (to ensure consistent regeneration)' + ) + + args = parser.parse_args() + + random.seed(int(args.seed)) + + mkdir_p(args.out_dir) + + for template in templates_in(args.src_dir): + modes = template.modes() + + n_range = template.range() + for n_value in n_range: + base = template.instantiate(n_value) + for mode in modes: + write_file( + os.path.join( + args.out_dir, + out_filename(template, n_value, mode) + ), + mode.convert_from(base) + ) + write_file( + os.path.join(args.out_dir, '{0}.json'.format(template.name)), + json.dumps({ + 'files': { + n: { + m.identifier: out_filename(template, n, m) + for m in modes + } for n in n_range + }, + 'name': template.name, + 'x_axis_label': template.property('x_axis_label'), + 'desc': template.property('desc'), + 'modes': {m.identifier: m.description() for m in modes} + }) + ) + + +if __name__ == '__main__': + main() diff --git a/src/boost/libs/metaparse/tools/benchmark/include/benchmark_util.hpp b/src/boost/libs/metaparse/tools/benchmark/include/benchmark_util.hpp new file mode 100644 index 000000000..eba88c925 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/include/benchmark_util.hpp @@ -0,0 +1,281 @@ +// Copyright Szabolcs Toth (thszabi@gmail.com) 2016. +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/string.hpp> + +template <char C> +struct to_upper_char; + +template <> struct to_upper_char<-128> : boost::mpl::char_<95> {}; +template <> struct to_upper_char<-127> : boost::mpl::char_<96> {}; +template <> struct to_upper_char<-126> : boost::mpl::char_<97> {}; +template <> struct to_upper_char<-125> : boost::mpl::char_<98> {}; +template <> struct to_upper_char<-124> : boost::mpl::char_<99> {}; +template <> struct to_upper_char<-123> : boost::mpl::char_<100> {}; +template <> struct to_upper_char<-122> : boost::mpl::char_<101> {}; +template <> struct to_upper_char<-121> : boost::mpl::char_<102> {}; +template <> struct to_upper_char<-120> : boost::mpl::char_<103> {}; +template <> struct to_upper_char<-119> : boost::mpl::char_<104> {}; +template <> struct to_upper_char<-118> : boost::mpl::char_<105> {}; +template <> struct to_upper_char<-117> : boost::mpl::char_<106> {}; +template <> struct to_upper_char<-116> : boost::mpl::char_<107> {}; +template <> struct to_upper_char<-115> : boost::mpl::char_<108> {}; +template <> struct to_upper_char<-114> : boost::mpl::char_<109> {}; +template <> struct to_upper_char<-113> : boost::mpl::char_<110> {}; +template <> struct to_upper_char<-112> : boost::mpl::char_<111> {}; +template <> struct to_upper_char<-111> : boost::mpl::char_<112> {}; +template <> struct to_upper_char<-110> : boost::mpl::char_<113> {}; +template <> struct to_upper_char<-109> : boost::mpl::char_<114> {}; +template <> struct to_upper_char<-108> : boost::mpl::char_<115> {}; +template <> struct to_upper_char<-107> : boost::mpl::char_<116> {}; +template <> struct to_upper_char<-106> : boost::mpl::char_<117> {}; +template <> struct to_upper_char<-105> : boost::mpl::char_<118> {}; +template <> struct to_upper_char<-104> : boost::mpl::char_<119> {}; +template <> struct to_upper_char<-103> : boost::mpl::char_<120> {}; +template <> struct to_upper_char<-102> : boost::mpl::char_<121> {}; +template <> struct to_upper_char<-101> : boost::mpl::char_<122> {}; +template <> struct to_upper_char<-100> : boost::mpl::char_<123> {}; +template <> struct to_upper_char<-99> : boost::mpl::char_<124> {}; +template <> struct to_upper_char<-98> : boost::mpl::char_<125> {}; +template <> struct to_upper_char<-97> : boost::mpl::char_<126> {}; +template <> struct to_upper_char<-96> : boost::mpl::char_<127> {}; +template <> struct to_upper_char<-95> : boost::mpl::char_<-127> {}; +template <> struct to_upper_char<-94> : boost::mpl::char_<-126> {}; +template <> struct to_upper_char<-93> : boost::mpl::char_<-125> {}; +template <> struct to_upper_char<-92> : boost::mpl::char_<-124> {}; +template <> struct to_upper_char<-91> : boost::mpl::char_<-123> {}; +template <> struct to_upper_char<-90> : boost::mpl::char_<-122> {}; +template <> struct to_upper_char<-89> : boost::mpl::char_<-121> {}; +template <> struct to_upper_char<-88> : boost::mpl::char_<-120> {}; +template <> struct to_upper_char<-87> : boost::mpl::char_<-119> {}; +template <> struct to_upper_char<-86> : boost::mpl::char_<-118> {}; +template <> struct to_upper_char<-85> : boost::mpl::char_<-117> {}; +template <> struct to_upper_char<-84> : boost::mpl::char_<-116> {}; +template <> struct to_upper_char<-83> : boost::mpl::char_<-115> {}; +template <> struct to_upper_char<-82> : boost::mpl::char_<-114> {}; +template <> struct to_upper_char<-81> : boost::mpl::char_<-113> {}; +template <> struct to_upper_char<-80> : boost::mpl::char_<-112> {}; +template <> struct to_upper_char<-79> : boost::mpl::char_<-111> {}; +template <> struct to_upper_char<-78> : boost::mpl::char_<-110> {}; +template <> struct to_upper_char<-77> : boost::mpl::char_<-109> {}; +template <> struct to_upper_char<-76> : boost::mpl::char_<-108> {}; +template <> struct to_upper_char<-75> : boost::mpl::char_<-107> {}; +template <> struct to_upper_char<-74> : boost::mpl::char_<-106> {}; +template <> struct to_upper_char<-73> : boost::mpl::char_<-105> {}; +template <> struct to_upper_char<-72> : boost::mpl::char_<-104> {}; +template <> struct to_upper_char<-71> : boost::mpl::char_<-103> {}; +template <> struct to_upper_char<-70> : boost::mpl::char_<-102> {}; +template <> struct to_upper_char<-69> : boost::mpl::char_<-101> {}; +template <> struct to_upper_char<-68> : boost::mpl::char_<-100> {}; +template <> struct to_upper_char<-67> : boost::mpl::char_<-99> {}; +template <> struct to_upper_char<-66> : boost::mpl::char_<-98> {}; +template <> struct to_upper_char<-65> : boost::mpl::char_<-97> {}; +template <> struct to_upper_char<-64> : boost::mpl::char_<-96> {}; +template <> struct to_upper_char<-63> : boost::mpl::char_<-95> {}; +template <> struct to_upper_char<-62> : boost::mpl::char_<-94> {}; +template <> struct to_upper_char<-61> : boost::mpl::char_<-93> {}; +template <> struct to_upper_char<-60> : boost::mpl::char_<-92> {}; +template <> struct to_upper_char<-59> : boost::mpl::char_<-91> {}; +template <> struct to_upper_char<-58> : boost::mpl::char_<-90> {}; +template <> struct to_upper_char<-57> : boost::mpl::char_<-89> {}; +template <> struct to_upper_char<-56> : boost::mpl::char_<-88> {}; +template <> struct to_upper_char<-55> : boost::mpl::char_<-87> {}; +template <> struct to_upper_char<-54> : boost::mpl::char_<-86> {}; +template <> struct to_upper_char<-53> : boost::mpl::char_<-85> {}; +template <> struct to_upper_char<-52> : boost::mpl::char_<-84> {}; +template <> struct to_upper_char<-51> : boost::mpl::char_<-83> {}; +template <> struct to_upper_char<-50> : boost::mpl::char_<-82> {}; +template <> struct to_upper_char<-49> : boost::mpl::char_<-81> {}; +template <> struct to_upper_char<-48> : boost::mpl::char_<-80> {}; +template <> struct to_upper_char<-47> : boost::mpl::char_<-79> {}; +template <> struct to_upper_char<-46> : boost::mpl::char_<-78> {}; +template <> struct to_upper_char<-45> : boost::mpl::char_<-77> {}; +template <> struct to_upper_char<-44> : boost::mpl::char_<-76> {}; +template <> struct to_upper_char<-43> : boost::mpl::char_<-75> {}; +template <> struct to_upper_char<-42> : boost::mpl::char_<-74> {}; +template <> struct to_upper_char<-41> : boost::mpl::char_<-73> {}; +template <> struct to_upper_char<-40> : boost::mpl::char_<-72> {}; +template <> struct to_upper_char<-39> : boost::mpl::char_<-71> {}; +template <> struct to_upper_char<-38> : boost::mpl::char_<-70> {}; +template <> struct to_upper_char<-37> : boost::mpl::char_<-69> {}; +template <> struct to_upper_char<-36> : boost::mpl::char_<-68> {}; +template <> struct to_upper_char<-35> : boost::mpl::char_<-67> {}; +template <> struct to_upper_char<-34> : boost::mpl::char_<-66> {}; +template <> struct to_upper_char<-33> : boost::mpl::char_<-65> {}; +template <> struct to_upper_char<-32> : boost::mpl::char_<-64> {}; +template <> struct to_upper_char<-31> : boost::mpl::char_<-63> {}; +template <> struct to_upper_char<-30> : boost::mpl::char_<-62> {}; +template <> struct to_upper_char<-29> : boost::mpl::char_<-61> {}; +template <> struct to_upper_char<-28> : boost::mpl::char_<-60> {}; +template <> struct to_upper_char<-27> : boost::mpl::char_<-59> {}; +template <> struct to_upper_char<-26> : boost::mpl::char_<-58> {}; +template <> struct to_upper_char<-25> : boost::mpl::char_<-57> {}; +template <> struct to_upper_char<-24> : boost::mpl::char_<-56> {}; +template <> struct to_upper_char<-23> : boost::mpl::char_<-55> {}; +template <> struct to_upper_char<-22> : boost::mpl::char_<-54> {}; +template <> struct to_upper_char<-21> : boost::mpl::char_<-53> {}; +template <> struct to_upper_char<-20> : boost::mpl::char_<-52> {}; +template <> struct to_upper_char<-19> : boost::mpl::char_<-51> {}; +template <> struct to_upper_char<-18> : boost::mpl::char_<-50> {}; +template <> struct to_upper_char<-17> : boost::mpl::char_<-49> {}; +template <> struct to_upper_char<-16> : boost::mpl::char_<-48> {}; +template <> struct to_upper_char<-15> : boost::mpl::char_<-47> {}; +template <> struct to_upper_char<-14> : boost::mpl::char_<-46> {}; +template <> struct to_upper_char<-13> : boost::mpl::char_<-45> {}; +template <> struct to_upper_char<-12> : boost::mpl::char_<-44> {}; +template <> struct to_upper_char<-11> : boost::mpl::char_<-43> {}; +template <> struct to_upper_char<-10> : boost::mpl::char_<-42> {}; +template <> struct to_upper_char<-9> : boost::mpl::char_<-41> {}; +template <> struct to_upper_char<-8> : boost::mpl::char_<-40> {}; +template <> struct to_upper_char<-7> : boost::mpl::char_<-39> {}; +template <> struct to_upper_char<-6> : boost::mpl::char_<-38> {}; +template <> struct to_upper_char<-5> : boost::mpl::char_<-37> {}; +template <> struct to_upper_char<-4> : boost::mpl::char_<-36> {}; +template <> struct to_upper_char<-3> : boost::mpl::char_<-35> {}; +template <> struct to_upper_char<-2> : boost::mpl::char_<-34> {}; +template <> struct to_upper_char<-1> : boost::mpl::char_<-33> {}; +template <> struct to_upper_char<0> : boost::mpl::char_<-32> {}; +template <> struct to_upper_char<1> : boost::mpl::char_<-31> {}; +template <> struct to_upper_char<2> : boost::mpl::char_<-30> {}; +template <> struct to_upper_char<3> : boost::mpl::char_<-29> {}; +template <> struct to_upper_char<4> : boost::mpl::char_<-28> {}; +template <> struct to_upper_char<5> : boost::mpl::char_<-27> {}; +template <> struct to_upper_char<6> : boost::mpl::char_<-26> {}; +template <> struct to_upper_char<7> : boost::mpl::char_<-25> {}; +template <> struct to_upper_char<8> : boost::mpl::char_<-24> {}; +template <> struct to_upper_char<9> : boost::mpl::char_<-23> {}; +template <> struct to_upper_char<10> : boost::mpl::char_<-22> {}; +template <> struct to_upper_char<11> : boost::mpl::char_<-21> {}; +template <> struct to_upper_char<12> : boost::mpl::char_<-20> {}; +template <> struct to_upper_char<13> : boost::mpl::char_<-19> {}; +template <> struct to_upper_char<14> : boost::mpl::char_<-18> {}; +template <> struct to_upper_char<15> : boost::mpl::char_<-17> {}; +template <> struct to_upper_char<16> : boost::mpl::char_<-16> {}; +template <> struct to_upper_char<17> : boost::mpl::char_<-15> {}; +template <> struct to_upper_char<18> : boost::mpl::char_<-14> {}; +template <> struct to_upper_char<19> : boost::mpl::char_<-13> {}; +template <> struct to_upper_char<20> : boost::mpl::char_<-12> {}; +template <> struct to_upper_char<21> : boost::mpl::char_<-11> {}; +template <> struct to_upper_char<22> : boost::mpl::char_<-10> {}; +template <> struct to_upper_char<23> : boost::mpl::char_<-9> {}; +template <> struct to_upper_char<24> : boost::mpl::char_<-8> {}; +template <> struct to_upper_char<25> : boost::mpl::char_<-7> {}; +template <> struct to_upper_char<26> : boost::mpl::char_<-6> {}; +template <> struct to_upper_char<27> : boost::mpl::char_<-5> {}; +template <> struct to_upper_char<28> : boost::mpl::char_<-4> {}; +template <> struct to_upper_char<29> : boost::mpl::char_<-3> {}; +template <> struct to_upper_char<30> : boost::mpl::char_<-2> {}; +template <> struct to_upper_char<31> : boost::mpl::char_<-1> {}; +template <> struct to_upper_char<32> : boost::mpl::char_<0> {}; +template <> struct to_upper_char<33> : boost::mpl::char_<1> {}; +template <> struct to_upper_char<34> : boost::mpl::char_<2> {}; +template <> struct to_upper_char<35> : boost::mpl::char_<3> {}; +template <> struct to_upper_char<36> : boost::mpl::char_<4> {}; +template <> struct to_upper_char<37> : boost::mpl::char_<5> {}; +template <> struct to_upper_char<38> : boost::mpl::char_<6> {}; +template <> struct to_upper_char<39> : boost::mpl::char_<7> {}; +template <> struct to_upper_char<40> : boost::mpl::char_<8> {}; +template <> struct to_upper_char<41> : boost::mpl::char_<9> {}; +template <> struct to_upper_char<42> : boost::mpl::char_<10> {}; +template <> struct to_upper_char<43> : boost::mpl::char_<11> {}; +template <> struct to_upper_char<44> : boost::mpl::char_<12> {}; +template <> struct to_upper_char<45> : boost::mpl::char_<13> {}; +template <> struct to_upper_char<46> : boost::mpl::char_<14> {}; +template <> struct to_upper_char<47> : boost::mpl::char_<15> {}; +template <> struct to_upper_char<48> : boost::mpl::char_<16> {}; +template <> struct to_upper_char<49> : boost::mpl::char_<17> {}; +template <> struct to_upper_char<50> : boost::mpl::char_<18> {}; +template <> struct to_upper_char<51> : boost::mpl::char_<19> {}; +template <> struct to_upper_char<52> : boost::mpl::char_<20> {}; +template <> struct to_upper_char<53> : boost::mpl::char_<21> {}; +template <> struct to_upper_char<54> : boost::mpl::char_<22> {}; +template <> struct to_upper_char<55> : boost::mpl::char_<23> {}; +template <> struct to_upper_char<56> : boost::mpl::char_<24> {}; +template <> struct to_upper_char<57> : boost::mpl::char_<25> {}; +template <> struct to_upper_char<58> : boost::mpl::char_<26> {}; +template <> struct to_upper_char<59> : boost::mpl::char_<27> {}; +template <> struct to_upper_char<60> : boost::mpl::char_<28> {}; +template <> struct to_upper_char<61> : boost::mpl::char_<29> {}; +template <> struct to_upper_char<62> : boost::mpl::char_<30> {}; +template <> struct to_upper_char<63> : boost::mpl::char_<31> {}; +template <> struct to_upper_char<64> : boost::mpl::char_<32> {}; +template <> struct to_upper_char<65> : boost::mpl::char_<33> {}; +template <> struct to_upper_char<66> : boost::mpl::char_<34> {}; +template <> struct to_upper_char<67> : boost::mpl::char_<35> {}; +template <> struct to_upper_char<68> : boost::mpl::char_<36> {}; +template <> struct to_upper_char<69> : boost::mpl::char_<37> {}; +template <> struct to_upper_char<70> : boost::mpl::char_<38> {}; +template <> struct to_upper_char<71> : boost::mpl::char_<39> {}; +template <> struct to_upper_char<72> : boost::mpl::char_<40> {}; +template <> struct to_upper_char<73> : boost::mpl::char_<41> {}; +template <> struct to_upper_char<74> : boost::mpl::char_<42> {}; +template <> struct to_upper_char<75> : boost::mpl::char_<43> {}; +template <> struct to_upper_char<76> : boost::mpl::char_<44> {}; +template <> struct to_upper_char<77> : boost::mpl::char_<45> {}; +template <> struct to_upper_char<78> : boost::mpl::char_<46> {}; +template <> struct to_upper_char<79> : boost::mpl::char_<47> {}; +template <> struct to_upper_char<80> : boost::mpl::char_<48> {}; +template <> struct to_upper_char<81> : boost::mpl::char_<49> {}; +template <> struct to_upper_char<82> : boost::mpl::char_<50> {}; +template <> struct to_upper_char<83> : boost::mpl::char_<51> {}; +template <> struct to_upper_char<84> : boost::mpl::char_<52> {}; +template <> struct to_upper_char<85> : boost::mpl::char_<53> {}; +template <> struct to_upper_char<86> : boost::mpl::char_<54> {}; +template <> struct to_upper_char<87> : boost::mpl::char_<55> {}; +template <> struct to_upper_char<88> : boost::mpl::char_<56> {}; +template <> struct to_upper_char<89> : boost::mpl::char_<57> {}; +template <> struct to_upper_char<90> : boost::mpl::char_<58> {}; +template <> struct to_upper_char<91> : boost::mpl::char_<59> {}; +template <> struct to_upper_char<92> : boost::mpl::char_<60> {}; +template <> struct to_upper_char<93> : boost::mpl::char_<61> {}; +template <> struct to_upper_char<94> : boost::mpl::char_<62> {}; +template <> struct to_upper_char<95> : boost::mpl::char_<63> {}; +template <> struct to_upper_char<96> : boost::mpl::char_<64> {}; +template <> struct to_upper_char<97> : boost::mpl::char_<65> {}; +template <> struct to_upper_char<98> : boost::mpl::char_<66> {}; +template <> struct to_upper_char<99> : boost::mpl::char_<67> {}; +template <> struct to_upper_char<100> : boost::mpl::char_<68> {}; +template <> struct to_upper_char<101> : boost::mpl::char_<69> {}; +template <> struct to_upper_char<102> : boost::mpl::char_<70> {}; +template <> struct to_upper_char<103> : boost::mpl::char_<71> {}; +template <> struct to_upper_char<104> : boost::mpl::char_<72> {}; +template <> struct to_upper_char<105> : boost::mpl::char_<73> {}; +template <> struct to_upper_char<106> : boost::mpl::char_<74> {}; +template <> struct to_upper_char<107> : boost::mpl::char_<75> {}; +template <> struct to_upper_char<108> : boost::mpl::char_<76> {}; +template <> struct to_upper_char<109> : boost::mpl::char_<77> {}; +template <> struct to_upper_char<110> : boost::mpl::char_<78> {}; +template <> struct to_upper_char<111> : boost::mpl::char_<79> {}; +template <> struct to_upper_char<112> : boost::mpl::char_<80> {}; +template <> struct to_upper_char<113> : boost::mpl::char_<81> {}; +template <> struct to_upper_char<114> : boost::mpl::char_<82> {}; +template <> struct to_upper_char<115> : boost::mpl::char_<83> {}; +template <> struct to_upper_char<116> : boost::mpl::char_<84> {}; +template <> struct to_upper_char<117> : boost::mpl::char_<85> {}; +template <> struct to_upper_char<118> : boost::mpl::char_<86> {}; +template <> struct to_upper_char<119> : boost::mpl::char_<87> {}; +template <> struct to_upper_char<120> : boost::mpl::char_<88> {}; +template <> struct to_upper_char<121> : boost::mpl::char_<89> {}; +template <> struct to_upper_char<122> : boost::mpl::char_<90> {}; +template <> struct to_upper_char<123> : boost::mpl::char_<91> {}; +template <> struct to_upper_char<124> : boost::mpl::char_<92> {}; +template <> struct to_upper_char<125> : boost::mpl::char_<93> {}; +template <> struct to_upper_char<126> : boost::mpl::char_<94> {}; +template <> struct to_upper_char<127> : boost::mpl::char_<95> {}; + +template <class S> +struct to_upper; + +template <char... Cs> +struct to_upper<boost::metaparse::string<Cs...>> : + boost::metaparse::string<to_upper_char<Cs>::value...> +{}; + +#define CAT_IMPL(a, b) a ## b +#define CAT(a, b) CAT_IMPL(a, b) + +#define TEST_STRING(...) to_upper< __VA_ARGS__ >::type CAT(v, __LINE__); + diff --git a/src/boost/libs/metaparse/tools/benchmark/src/length128.cpp b/src/boost/libs/metaparse/tools/benchmark/src/length128.cpp new file mode 100644 index 000000000..768485f19 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/src/length128.cpp @@ -0,0 +1,18 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// n in [0..2048), step 2 +// x_axis_label: Length of the 128 strings +// desc: 128 strings with increasing length. +// modes: BOOST_METAPARSE_STRING, manual + +\#define BOOST_METAPARSE_LIMIT_STRING_SIZE $n + +\#include <benchmark_util.hpp> + +#for j in range(0, 128) +TEST_STRING($random_string($n)) +#end for + diff --git a/src/boost/libs/metaparse/tools/benchmark/src/max_length.cpp b/src/boost/libs/metaparse/tools/benchmark/src/max_length.cpp new file mode 100644 index 000000000..5ea79beb3 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/src/max_length.cpp @@ -0,0 +1,21 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// n in [1..2048), step 2 +// x_axis_label: Maximum length of strings +// desc: 100 one character long strings with increasing maximum length. +// modes: BOOST_METAPARSE_STRING + +\#define BOOST_METAPARSE_LIMIT_STRING_SIZE $n + +\#include <benchmark_util.hpp> + +#for j in range(0, 10) +TEST_STRING(BOOST_METAPARSE_STRING("\x0$j")) +#end for +#for j in range(10, 100) +TEST_STRING(BOOST_METAPARSE_STRING("\x$j")) +#end for + diff --git a/src/boost/libs/metaparse/tools/benchmark/src/number.cpp b/src/boost/libs/metaparse/tools/benchmark/src/number.cpp new file mode 100644 index 000000000..f15bdd230 --- /dev/null +++ b/src/boost/libs/metaparse/tools/benchmark/src/number.cpp @@ -0,0 +1,18 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// n in [0..1024), step 2 +// x_axis_label: Number of strings +// desc: Increasing number of strings with 64 length. +// modes: BOOST_METAPARSE_STRING, manual + +\#define BOOST_METAPARSE_LIMIT_STRING_SIZE 32 + +\#include <benchmark_util.hpp> + +#for j in range(0, $n) +TEST_STRING($random_string(32)) +#end for + diff --git a/src/boost/libs/metaparse/tools/build_environment.py b/src/boost/libs/metaparse/tools/build_environment.py new file mode 100755 index 000000000..b104fb35b --- /dev/null +++ b/src/boost/libs/metaparse/tools/build_environment.py @@ -0,0 +1,134 @@ +#!/usr/bin/python + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import os +import subprocess +import json +import argparse + + +def load_json(filename): + with open(filename, 'r') as f: + return json.load(f) + + +class ChildProcess: + def __init__(self, cmd, cwd = os.getcwd()): + self.cmd = cmd + self.cwd = cwd + + def run(self, cmd): + cmd_string = ' '.join(cmd) + print 'Running {0}'.format(cmd_string) + proc = subprocess.Popen( + self.cmd + cmd, + cwd = self.cwd, + stdout = subprocess.PIPE + ) + out = proc.communicate()[0] + if proc.returncode == 0: + return out + else: + raise Exception( + 'Command {0} exited with {1}'.format( + cmd_string, + proc.returncode + ) + ) + + def in_dir(self, cwd): + return ChildProcess(self.cmd, cwd) + + def in_subdir(self, subdir): + return self.in_dir(os.path.join(self.cwd, subdir)) + + +def head_of_master(submodule, git, ref): + git.run(['fetch']) + return git.run(['show-ref', ref]).split()[0] + + +def build_environment(submodules_file, out_dir, git, repo, action, ref): + submodules = load_json(submodules_file) + git.run(['clone', repo, out_dir]) + git_in_boost = git.in_dir(out_dir) + + git_in_boost.run( + ['submodule', 'init', '--'] + [k for k in submodules.keys() if k != ''] + ) + git_in_boost.run(['submodule', 'update']) + if action == 'update': + with open(submodules_file, 'w') as f: + f.write(json.dumps( + dict([ + (k, head_of_master(k, git_in_boost.in_subdir(k), ref)) + for k, v in submodules.iteritems() + ]), + sort_keys=True, + indent=2 + )) + elif action == 'checkout': + for name, commit in submodules.iteritems(): + git_in_boost.in_subdir(name).run(['checkout', commit]) + else: + raise Exception('Invalid action {0}'.format(action)) + + +def main(): + """The main function of the utility""" + parser = argparse.ArgumentParser( + description='Manage the build environment of Boost.Metaparse' + ) + parser.add_argument( + '--dep_json', + required=True, + help='The json file describing the dependencies' + ) + parser.add_argument( + '--git', + required=False, + default='git', + help='The git command to use' + ) + parser.add_argument( + '--out', + required=False, + default='boost', + help='The directory to clone into' + ) + parser.add_argument( + '--action', + required=True, + choices=['update', 'checkout'], + help='The action to do with the dependencies' + ) + parser.add_argument( + '--boost_repository', + required=False, + default='https://github.com/boostorg/boost.git', + help='The Boost repository to clone' + ) + parser.add_argument( + '--ref', + required=False, + default='origin/master', + help='The reference to set to in update' + ) + args = parser.parse_args() + + build_environment( + args.dep_json, + args.out, + ChildProcess([args.git]), + args.boost_repository, + args.action, + args.ref + ) + + +if __name__ == '__main__': + main() diff --git a/src/boost/libs/metaparse/tools/deps.json b/src/boost/libs/metaparse/tools/deps.json new file mode 100644 index 000000000..60e9e5a72 --- /dev/null +++ b/src/boost/libs/metaparse/tools/deps.json @@ -0,0 +1,60 @@ +{ + "": "0438955e7ac39cbb270bb803b3199353c50bf837", + "libs/algorithm": "ea13506795980290842d43d6e8b34c75cf7f362a", + "libs/align": "1f829685e08d4c6b8c96e08b043bf8e03d27ae49", + "libs/any": "3b7c34998d7364aa312a46f6578622ae79d0378f", + "libs/array": "9678f6aa3bee620a91d536cdba92bf0d4b7e02fc", + "libs/assert": "066d8933c4061fb865210de71b4df16839bc1c8d", + "libs/bind": "4300db5db83be5804785b4bf581f9abbcb193caf", + "libs/chrono": "621b6faaf19d5c0b5ffd0a313e696b81495316a4", + "libs/concept_check": "504ea0b18d02e32c223ec8cbaa036806e3ffe6e3", + "libs/config": "74bcf32eca2a81fb8cccb06b81addae3815581fe", + "libs/container": "08e768f1d89289f0783b5bab9ea9f2eb0753ed70", + "libs/conversion": "da8b2fe695cffda506059b49a4782ede01fba10f", + "libs/core": "3add966877646d0c6f43e0ec37587f52d2a757d9", + "libs/detail": "b0a2809915964f504adfad818794fc418a2e39e9", + "libs/exception": "e5e4652b75792d18e595aa2aba1ee1c5c7c69611", + "libs/filesystem": "26540a5338240ca0fae31dba432ff654c0ca93c4", + "libs/foreach": "a19bc0a6dd02249ded12d90cd38f28c8294bd64d", + "libs/function": "42f2a7c714a2c1254b0eb77c9fea870a47f32e80", + "libs/functional": "df98d4fd1ca9d8842da2653fb235ee3dcb2d5e73", + "libs/fusion": "53ba3de15aef744e72d86e91269e2cd90cff8140", + "libs/integer": "14020f6f6c99891aac407618f0c19d383524f02d", + "libs/io": "5458fd86d5a8e667513d34ea50b18883eae5ea14", + "libs/iostreams": "a5b52f079b29dd8fe61ff13d896ec24c48248d49", + "libs/iterator": "22dd100dfded2e8e450b8a079ff2b482f46a9ccc", + "libs/lexical_cast": "038e80ec7a7f34f61379c8885f386b230ef09624", + "libs/math": "e7ca10d04e070ca1c18cc0d5dc21ae1218baf36e", + "libs/move": "87ba5a1fcd6a87d37bb57679b15c63fbcfab88a1", + "libs/mpl": "f023a68f786652749a0809584af1f205f0c2c820", + "libs/numeric/conversion": "f4c6bd971154449e9c76f3f0573799cea772d70a", + "libs/optional": "ede89602f7553a0c76700a57ee519b7f0e4a0d3f", + "libs/predef": "e98eff209ba64fc772cb78b8f67637c08bb97e91", + "libs/preprocessor": "4e29a160b9260c6708d41ce895b499a28c31d5d6", + "libs/program_options": "fae2d4c57b6c70e19e00cd6b93f4ef4f4c6681e2", + "libs/proto": "990af3a70015e037e09103f5d6dbc4eeb833594e", + "libs/range": "0e931f4a80521acb00ff76c03237b0804b2cc572", + "libs/ratio": "d7773512aa7c123309d0f50fe55ab6b6c724357c", + "libs/rational": "d64b2c1b71d1f766cc4f3122462ac063135781c2", + "libs/smart_ptr": "4db7219c32022e025b228f7a487b91b5914aede6", + "libs/spirit": "25c00abf36a1bdce32177632d7e0bbcb03869051", + "libs/static_assert": "87f3be4a8fe6fa32646aa01782dda29e6eeb0b4c", + "libs/system": "e5da5ce2cfef69630687434b292507af9fda83d9", + "libs/test": "b3d233a360e104c146619d5fc93149d361cfef59", + "libs/throw_exception": "c89a2db1122302e90ebad9cec0b49d77283a6566", + "libs/timer": "65d06352434dcb7812c866014f4f05e337bfa900", + "libs/tokenizer": "1d204ae9798edf38caf7e6107099c5edff905a3c", + "libs/tuple": "d77e569c899f7eb3d1f255889e739d586ba5900f", + "libs/type_index": "1ff942f3297e83bbf915bd0a943dbd54e2d332de", + "libs/type_traits": "a0140edf50b5e527bc17fe170c7ad3f7a9e85b32", + "libs/typeof": "6aea11f3df0689b6e5c2035e42bfa5df237df0b5", + "libs/unordered": "84dd473a5dfbb5bc7f353fd3448e00da7425f2aa", + "libs/utility": "1caa745dd72b2cffebafa904658fde0e9cac1232", + "libs/wave": "421a43e9fb9b914c0651e89051523033dc987b36", + "libs/winapi": "463842aa4a45fae68375da6ad441d3c97fab8330", + "libs/xpressive": "2f5bf84198c48f8561918cf0241c5c7af0991981", + "tools/boostbook": "22c94baebb4ea7d7b0b47e0e1017e69623874569", + "tools/build": "9a8453e3b586cc3dd88d609040bd7ae8529bfea1", + "tools/inspect": "b0386f5c64da235d8912bb45dfa55475f2ef7545", + "tools/quickbook": "08663596f8fd32046c346ebded75dcdc505c9bbe" +} diff --git a/src/boost/libs/metaparse/tools/generate_all.py b/src/boost/libs/metaparse/tools/generate_all.py new file mode 100755 index 000000000..66a5267da --- /dev/null +++ b/src/boost/libs/metaparse/tools/generate_all.py @@ -0,0 +1,295 @@ +#!/usr/bin/python + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import sys +import argparse +import re +import os + +def remove_last_dot(s): + if s.endswith('.'): + return s[:-1] + else: + return s + +def remove_newline(s): + return re.sub('[\r\n]', '', s) + +def is_definition(s): + cmd = s.strip() + + def_prefixes = ['#include ', 'using ', 'struct ', 'template '] + return any([cmd.startswith(s) for s in def_prefixes]) or cmd.endswith(';') + +def prefix_lines(prefix, s): + return '\n'.join(['%s%s' % (prefix, l) for l in s.split('\n')]) + +def protect_metashell(s): + if s.startswith('#include <metashell'): + return '#ifdef __METASHELL\n%s\n#endif' % (s) + else: + return s + +def parse_md(qbk): + sections = [] + defs = [] + current_section = '' + in_cpp_snippet = False + numbered_section_header = re.compile('^\[section *([0-9.]+)') + metashell_command = re.compile('^> [^ ]') + metashell_prompt = re.compile('^(\.\.\.|)>') + msh_cmd = '' + for l in qbk: + if l.startswith(' '): + ll = l[2:] + if not in_cpp_snippet: + in_msh_cpp_snippet = True + if in_msh_cpp_snippet: + if metashell_command.match(ll) or msh_cmd != '': + cmd = metashell_prompt.sub('', remove_newline(ll)) + if msh_cmd != '': + msh_cmd = msh_cmd + '\n' + msh_cmd = msh_cmd + cmd + if msh_cmd.endswith('\\'): + msh_cmd = msh_cmd[:-1].strip() + ' ' + else: + if not is_definition(msh_cmd): + msh_cmd = '// query:\n%s' % (prefix_lines('// ', msh_cmd)) + defs.append((current_section, protect_metashell(msh_cmd.strip()))) + msh_cmd = '' + elif not in_cpp_snippet: + in_msh_cpp_snippet = False + in_cpp_snippet = True + else: + in_cpp_snippet = False + m = numbered_section_header.match(l) + if m: + current_section = remove_last_dot(m.group(1)).replace('.', '_') + sections.append(current_section) + + sections.sort(key = lambda s: [int(n) for n in s.split('_')]) + return (sections, defs) + +def delete_old_headers(path): + for f in os.listdir(path): + if f.endswith('.hpp'): + os.remove(os.path.join(path, f)) + +def gen_headers(sections, defs, path): + files = {} + + prev_section = '' + for s in sections: + prev_name = prev_section.replace('_', '.') + include_guard = 'BOOST_METAPARSE_GETTING_STARTED_%s_HPP' % (s) + if prev_section == '': + prev_include = '' + else: + prev_include = \ + '// Definitions before section {0}\n'.format(prev_name) + \ + '#include "{0}.hpp"\n'.format(prev_section) + \ + '\n' + + files[os.path.join(path, s + '.hpp')] = \ + '#ifndef {0}\n'.format(include_guard) + \ + '#define {0}\n'.format(include_guard) + \ + '\n' + \ + '// Automatically generated header file\n' + \ + '\n' + \ + prev_include + \ + '// Definitions of section {0}\n'.format(prev_name) + \ + '\n'.join( \ + ['%s\n' % (d) for (sec, d) in defs if sec == prev_section] \ + ) + \ + '\n' + \ + '#endif\n' + \ + '\n' + prev_section = s + return files + +def remove_metashell_protection(s): + prefix = '#ifdef __METASHELL\n' + suffix = '#endif' + return \ + s[len(prefix):-len(suffix)] \ + if s.startswith(prefix) and s.endswith(suffix) \ + else s + +def make_code_snippet(s): + return '\n'.join([' {0}'.format(l) for l in s.split('\n')]) + +def what_we_have_so_far_docs(doc_dir, qbk, defs, sections): + files = {} + so_far = '' + sections_with_definition = [] + for s in sections: + if so_far != '': + files[os.path.join(doc_dir, 'before_{0}.qbk'.format(s))] = \ + '[#before_{0}]\n[\'Definitions before section {1}]\n\n{2}\n'.format( + s, + s.replace('_', '.') + '.', + so_far + ) + sections_with_definition.append(s) + + so_far = so_far + '\n'.join([ + '{0}\n'.format(make_code_snippet(remove_metashell_protection(d))) + for (sec, d) in defs + if sec == s and not d.startswith('//') + ]) + + is_section = re.compile('^\[section (([0-9]\.)+)') + note_prefix = \ + '[note Note that you can find everything that has been included and' \ + ' defined so far [link before_' + + in_definitions_before_each_section = False + + result = [] + for l in qbk: + if in_definitions_before_each_section: + if l.strip() == '[endsect]': + in_definitions_before_each_section = False + result.append(l) + elif l.strip() == '[section Definitions before each section]': + in_definitions_before_each_section = True + result.append(l) + result.append('\n') + for s in sections_with_definition: + result.append('[include before_{0}.qbk]\n'.format(s)) + result.append('\n') + elif not l.startswith(note_prefix): + result.append(l) + m = is_section.match(l) + if m: + section_number = m.group(1).replace('.', '_')[:-1] + if section_number in sections_with_definition: + result.append('{0}{1} here].]\n'.format(note_prefix, section_number)) + + return (files, result) + +def strip_not_finished_line(s): + s = s.strip() + return s[:-1] if s.endswith('\\') else s + +def make_copy_paste_friendly(lines): + result = [] + for l in lines: + if l.startswith('> '): + result.append(l[2:]) + elif l.startswith('...> '): + result[-1] = strip_not_finished_line(result[-1]) + l[5:].lstrip() + return result + +def extract_code_snippets(qbk, fn_base): + code_prefix = ' ' + + files = {} + + result = [] + in_cpp_code = False + counter = 0 + in_copy_paste_friendly_examples = False + skip_empty_lines = False + for l in qbk: + if l.strip() != '' or not skip_empty_lines: + skip_empty_lines = False + if in_copy_paste_friendly_examples: + if 'endsect' in l: + in_copy_paste_friendly_examples = False + result.append('\n') + result.extend([ + '[include {0}_{1}.qbk]\n'.format(re.sub('^.*/', '', fn_base), i) \ + for i in range(0, counter) + ]) + result.append('\n') + result.append(l) + in_copy_paste_friendly_examples = False + elif '[section Copy-paste friendly code examples]' in l: + in_copy_paste_friendly_examples = True + result.append(l) + elif 'copy-paste friendly version' in l: + skip_empty_lines = True + else: + result.append(l) + + if in_cpp_code: + if not l.startswith(code_prefix): + in_cpp_code = False + if len(code) > 1: + f = '{0}_{1}'.format(fn_base, counter) + basename_f = re.sub('^.*/', '', f) + files['{0}.qbk'.format(f)] = \ + '[#{0}]\n\n{1}\n'.format( + basename_f, + ''.join( + [code_prefix + s for s in make_copy_paste_friendly(code)] + ) + ) + result.append( + '[link {0} copy-paste friendly version]\n'.format(basename_f) + ) + result.append('\n') + counter = counter + 1 + elif \ + l.startswith(code_prefix + '> ') \ + or l.startswith(code_prefix + '...> '): + code.append(l[len(code_prefix):]) + elif l.startswith(code_prefix): + in_cpp_code = True + code = [l[len(code_prefix):]] + + return (files, result) + +def write_file(fn, content): + with open(fn, 'w') as f: + f.write(content) + +def write_files(files): + for fn in files: + write_file(fn, files[fn]) + +def main(): + desc = 'Generate headers with the definitions of a Getting Started guide' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument( + '--src', + dest='src', + default='doc/getting_started.qbk', + help='The .qbk source of the Getting Started guide' + ) + parser.add_argument( + '--dst', + dest='dst', + default='example/getting_started', + help='The target directory to generate into (all headers in that directory will be deleted!)' + ) + + args = parser.parse_args() + + qbk = open(args.src, 'r').readlines() + + delete_old_headers(args.dst) + doc_dir = os.path.dirname(args.src) + + (sections, defs) = parse_md(qbk) + files1 = gen_headers(sections, defs, args.dst) + (files2, qbk) = what_we_have_so_far_docs(doc_dir, qbk, defs, sections) + (files3, qbk) = \ + extract_code_snippets( + qbk, + args.src[:-4] if args.src.endswith('.qbk') else args.src + ) + + write_files(files1) + write_files(files2) + write_files(files3) + write_file(args.src, ''.join(qbk)) + +if __name__ == "__main__": + main() + diff --git a/src/boost/libs/metaparse/tools/string_headers.py b/src/boost/libs/metaparse/tools/string_headers.py new file mode 100755 index 000000000..43ef052f1 --- /dev/null +++ b/src/boost/libs/metaparse/tools/string_headers.py @@ -0,0 +1,347 @@ +#!/usr/bin/python +"""Utility to generate the header files for BOOST_METAPARSE_STRING""" + +# Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import argparse +import math +import os +import sys + + +VERSION = 1 + + +class Namespace(object): + """Generate namespace definition""" + + def __init__(self, out_f, names): + self.out_f = out_f + self.names = names + + def begin(self): + """Generate the beginning part""" + self.out_f.write('\n') + for depth, name in enumerate(self.names): + self.out_f.write( + '{0}namespace {1}\n{0}{{\n'.format(self.prefix(depth), name) + ) + + def end(self): + """Generate the closing part""" + for depth in xrange(len(self.names) - 1, -1, -1): + self.out_f.write('{0}}}\n'.format(self.prefix(depth))) + + def prefix(self, depth=None): + """Returns the prefix of a given depth. Returns the prefix code inside + the namespace should use when depth is None.""" + if depth is None: + depth = len(self.names) + return ' ' * depth + + def __enter__(self): + self.begin() + return self + + def __exit__(self, typ, value, traceback): + self.end() + + +def write_autogen_info(out_f): + """Write the comment about the file being autogenerated""" + out_f.write( + '\n' + '// This is an automatically generated header file.\n' + '// Generated with the tools/string_headers.py utility of\n' + '// Boost.Metaparse\n' + ) + + +class IncludeGuard(object): + """Generate include guards""" + + def __init__(self, out_f): + self.out_f = out_f + + def begin(self): + """Generate the beginning part""" + name = 'BOOST_METAPARSE_V1_CPP11_IMPL_STRING_HPP' + self.out_f.write('#ifndef {0}\n#define {0}\n'.format(name)) + write_autogen_info(self.out_f) + + def end(self): + """Generate the closing part""" + self.out_f.write('\n#endif\n') + + def __enter__(self): + self.begin() + return self + + def __exit__(self, typ, value, traceback): + self.end() + + +def macro_name(name): + """Generate the full macro name""" + return 'BOOST_METAPARSE_V{0}_{1}'.format(VERSION, name) + + +def define_macro(out_f, (name, args, body), undefine=False, check=True): + """Generate a macro definition or undefinition""" + if undefine: + out_f.write( + '#undef {0}\n' + .format(macro_name(name)) + ) + else: + if args: + arg_list = '({0})'.format(', '.join(args)) + else: + arg_list = '' + + if check: + out_f.write( + '#ifdef {0}\n' + '# error {0} already defined.\n' + '#endif\n' + .format(macro_name(name)) + ) + + out_f.write( + '#define {0}{1} {2}\n'.format(macro_name(name), arg_list, body) + ) + + +def filename(out_dir, name, undefine=False): + """Generate the filename""" + if undefine: + prefix = 'undef_' + else: + prefix = '' + return os.path.join(out_dir, '{0}{1}.hpp'.format(prefix, name.lower())) + + +def length_limits(max_length_limit, length_limit_step): + """Generates the length limits""" + string_len = len(str(max_length_limit)) + return [ + str(i).zfill(string_len) for i in + xrange( + length_limit_step, + max_length_limit + length_limit_step - 1, + length_limit_step + ) + ] + + +def unique_names(count): + """Generate count unique variable name""" + return ('C{0}'.format(i) for i in xrange(0, count)) + + +def generate_take(out_f, steps, line_prefix): + """Generate the take function""" + out_f.write( + '{0}constexpr inline int take(int n_)\n' + '{0}{{\n' + '{0} return {1} 0 {2};\n' + '{0}}}\n' + '\n'.format( + line_prefix, + ''.join('n_ >= {0} ? {0} : ('.format(s) for s in steps), + ')' * len(steps) + ) + ) + + +def generate_make_string(out_f, max_step): + """Generate the make_string template""" + steps = [2 ** n for n in xrange(int(math.log(max_step, 2)), -1, -1)] + + with Namespace( + out_f, + ['boost', 'metaparse', 'v{0}'.format(VERSION), 'impl'] + ) as nsp: + generate_take(out_f, steps, nsp.prefix()) + + out_f.write( + '{0}template <int LenNow, int LenRemaining, char... Cs>\n' + '{0}struct make_string;\n' + '\n' + '{0}template <char... Cs>' + ' struct make_string<0, 0, Cs...> : string<> {{}};\n' + .format(nsp.prefix()) + ) + + disable_sun = False + for i in reversed(steps): + if i > 64 and not disable_sun: + out_f.write('#ifndef __SUNPRO_CC\n') + disable_sun = True + out_f.write( + '{0}template <int LenRemaining,{1}char... Cs>' + ' struct make_string<{2},LenRemaining,{3}Cs...> :' + ' concat<string<{4}>,' + ' typename make_string<take(LenRemaining),' + 'LenRemaining-take(LenRemaining),Cs...>::type> {{}};\n' + .format( + nsp.prefix(), + ''.join('char {0},'.format(n) for n in unique_names(i)), + i, + ''.join('{0},'.format(n) for n in unique_names(i)), + ','.join(unique_names(i)) + ) + ) + if disable_sun: + out_f.write('#endif\n') + + +def generate_string(out_dir, limits): + """Generate string.hpp""" + max_limit = max((int(v) for v in limits)) + + with open(filename(out_dir, 'string'), 'wb') as out_f: + with IncludeGuard(out_f): + out_f.write( + '\n' + '#include <boost/metaparse/v{0}/cpp11/impl/concat.hpp>\n' + '#include <boost/preprocessor/cat.hpp>\n' + .format(VERSION) + ) + + generate_make_string(out_f, 512) + + out_f.write( + '\n' + '#ifndef BOOST_METAPARSE_LIMIT_STRING_SIZE\n' + '# error BOOST_METAPARSE_LIMIT_STRING_SIZE not defined\n' + '#endif\n' + '\n' + '#if BOOST_METAPARSE_LIMIT_STRING_SIZE > {0}\n' + '# error BOOST_METAPARSE_LIMIT_STRING_SIZE is greater than' + ' {0}. To increase the limit run tools/string_headers.py of' + ' Boost.Metaparse against your Boost headers.\n' + '#endif\n' + '\n' + .format(max_limit) + ) + + define_macro(out_f, ( + 'STRING', + ['s'], + '{0}::make_string< ' + '{0}::take(sizeof(s)-1), sizeof(s)-1-{0}::take(sizeof(s)-1),' + 'BOOST_PP_CAT({1}, BOOST_METAPARSE_LIMIT_STRING_SIZE)(s)' + '>::type' + .format( + '::boost::metaparse::v{0}::impl'.format(VERSION), + macro_name('I') + ) + )) + + out_f.write('\n') + for limit in xrange(0, max_limit + 1): + out_f.write( + '#define {0} {1}\n' + .format( + macro_name('I{0}'.format(limit)), + macro_name('INDEX_STR{0}'.format( + min(int(l) for l in limits if int(l) >= limit) + )) + ) + ) + out_f.write('\n') + + prev_macro = None + prev_limit = 0 + for length_limit in (int(l) for l in limits): + this_macro = macro_name('INDEX_STR{0}'.format(length_limit)) + out_f.write( + '#define {0}(s) {1}{2}\n' + .format( + this_macro, + '{0}(s),'.format(prev_macro) if prev_macro else '', + ','.join( + '{0}((s), {1})' + .format(macro_name('STRING_AT'), i) + for i in xrange(prev_limit, length_limit) + ) + ) + ) + prev_macro = this_macro + prev_limit = length_limit + + +def positive_integer(value): + """Throws when the argument is not a positive integer""" + val = int(value) + if val > 0: + return val + else: + raise argparse.ArgumentTypeError("A positive number is expected") + + +def existing_path(value): + """Throws when the path does not exist""" + if os.path.exists(value): + return value + else: + raise argparse.ArgumentTypeError("Path {0} not found".format(value)) + + +def main(): + """The main function of the script""" + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--boost_dir', + required=False, + type=existing_path, + help='The path to the include/boost directory of Metaparse' + ) + parser.add_argument( + '--max_length_limit', + required=False, + default=2048, + type=positive_integer, + help='The maximum supported length limit' + ) + parser.add_argument( + '--length_limit_step', + required=False, + default=128, + type=positive_integer, + help='The longest step at which headers are generated' + ) + args = parser.parse_args() + + if args.boost_dir is None: + tools_path = os.path.dirname(os.path.abspath(__file__)) + boost_dir = os.path.join( + os.path.dirname(tools_path), + 'include', + 'boost' + ) + else: + boost_dir = args.boost_dir + + if args.max_length_limit < 1: + sys.stderr.write('Invalid maximum length limit') + sys.exit(-1) + + generate_string( + os.path.join( + boost_dir, + 'metaparse', + 'v{0}'.format(VERSION), + 'cpp11', + 'impl' + ), + length_limits(args.max_length_limit, args.length_limit_step) + ) + + +if __name__ == '__main__': + main() |