diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:38:45 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:39:52 +0900 |
commit | 5cde13f21d36c7224b0e13d11c4b49379ae5210d (patch) | |
tree | e8269ac85a4b0f7d416e2565fa4f451b5cb41351 /boost/metaparse/v1/impl | |
parent | d9ec475d945d3035377a0d89ed42e382d8988891 (diff) | |
download | boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.gz boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.bz2 boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.zip |
Imported Upstream version 1.61.0
Change-Id: I96a1f878d1e6164f01e9aadd5147f38fca448d90
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/metaparse/v1/impl')
36 files changed, 1907 insertions, 0 deletions
diff --git a/boost/metaparse/v1/impl/apply_parser.hpp b/boost/metaparse/v1/impl/apply_parser.hpp new file mode 100644 index 0000000000..65d0f76107 --- /dev/null +++ b/boost/metaparse/v1/impl/apply_parser.hpp @@ -0,0 +1,63 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_APPLY_PARSER_HPP +#define BOOST_METAPARSE_V1_IMPL_APPLY_PARSER_HPP + +// 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/unless_error.hpp> +#include <boost/metaparse/v1/get_result.hpp> +#include <boost/metaparse/v1/get_remaining.hpp> +#include <boost/metaparse/v1/get_position.hpp> +#include <boost/metaparse/v1/transform.hpp> + +#include <boost/mpl/push_back.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct apply_parser + { + private: + template <class ListToAppend> + struct do_append + { + template <class Item> + struct apply : boost::mpl::push_back<ListToAppend, Item> {}; + }; + + template <class Accum, class S, class Pos, class Parser> + struct apply_unchecked : + transform<Parser,do_append<typename Accum::type> >::template apply< + typename S::type, + typename Pos::type + > + {}; + + public: + template <class State, class Parser> + struct apply : + unless_error< + State, + apply_unchecked< + get_result<State>, + get_remaining<State>, + get_position<State>, + Parser + > + > + {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/assert_string_length.hpp b/boost/metaparse/v1/impl/assert_string_length.hpp new file mode 100644 index 0000000000..5dad4d9f49 --- /dev/null +++ b/boost/metaparse/v1/impl/assert_string_length.hpp @@ -0,0 +1,31 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_ASSERT_STRING_LENGTH_HPP +#define BOOST_METAPARSE_V1_IMPL_ASSERT_STRING_LENGTH_HPP + +// 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/static_assert.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <int Len, class S> + struct assert_string_length : S + { + BOOST_STATIC_ASSERT((Len <= BOOST_METAPARSE_LIMIT_STRING_SIZE)); + }; + } + } + } +} + +#endif + + diff --git a/boost/metaparse/v1/impl/at_c.hpp b/boost/metaparse/v1/impl/at_c.hpp new file mode 100644 index 0000000000..af7177410e --- /dev/null +++ b/boost/metaparse/v1/impl/at_c.hpp @@ -0,0 +1,66 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_AT_C_HPP +#define BOOST_METAPARSE_V1_IMPL_AT_C_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> + +#include <boost/mpl/char.hpp> + +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/repeat.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S, int N> + struct at_c; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <char C, char... Cs, int N> + struct at_c<string<C, Cs...>, N> : at_c<string<Cs...>, N - 1> {}; + + template <char C, char... Cs> + struct at_c<string<C, Cs...>, 0> : boost::mpl::char_<C> {}; +#else + #ifdef BOOST_METAPARSE_STRING_CASE + # error BOOST_METAPARSE_STRING_CASE is already defined + #endif + #define BOOST_METAPARSE_STRING_CASE(z, n, unused) \ + template < \ + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C) \ + > \ + struct \ + at_c< \ + string< \ + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C) \ + >, \ + n \ + > : \ + boost::mpl::char_<BOOST_PP_CAT(C, n)> \ + {}; + + BOOST_PP_REPEAT( + BOOST_METAPARSE_LIMIT_STRING_SIZE, + BOOST_METAPARSE_STRING_CASE, + ~ + ) + + #undef BOOST_METAPARSE_STRING_CASE +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/back_inserter.hpp b/boost/metaparse/v1/impl/back_inserter.hpp new file mode 100644 index 0000000000..986b2d32da --- /dev/null +++ b/boost/metaparse/v1/impl/back_inserter.hpp @@ -0,0 +1,32 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_BACK_INSERTER_HPP +#define BOOST_METAPARSE_V1_IMPL_BACK_INSERTER_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/mpl/push_back.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct back_inserter + { + typedef back_inserter type; + + template <class T0, class T1> + struct apply : boost::mpl::push_back<T0, T1> {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/concat.hpp b/boost/metaparse/v1/impl/concat.hpp new file mode 100644 index 0000000000..d866ae42b1 --- /dev/null +++ b/boost/metaparse/v1/impl/concat.hpp @@ -0,0 +1,106 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_CONCAT_HPP +#define BOOST_METAPARSE_V1_IMPL_CONCAT_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> + +#include <boost/preprocessor/arithmetic/dec.hpp> +#include <boost/preprocessor/arithmetic/inc.hpp> +#include <boost/preprocessor/arithmetic/mul.hpp> +#include <boost/preprocessor/arithmetic/sub.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/punctuation/comma_if.hpp> +#include <boost/preprocessor/repetition/enum.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class A, class B> + struct concat; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <char... As, char... Bs> + struct concat<string<As...>, string<Bs...>> : string<As..., Bs...> {}; +#else + template <class A, class B> + struct concat_impl; + + #ifdef BOOST_METAPARSE_ARG + # error BOOST_METAPARSE_ARG already defined + #endif + #define BOOST_METAPARSE_ARG(z, n, unused) \ + BOOST_PP_CAT(B, BOOST_PP_INC(n)) + + #ifdef BOOST_METAPARSE_CONCAT + # error BOOST_METAPARSE_CONCAT already defined + #endif + #define BOOST_METAPARSE_CONCAT(z, n, unused) \ + template < \ + BOOST_PP_ENUM_PARAMS(n, int A) BOOST_PP_COMMA_IF(n) \ + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int B) \ + > \ + struct \ + concat_impl< \ + string< \ + BOOST_PP_ENUM_PARAMS(n, A) \ + BOOST_PP_COMMA_IF( \ + BOOST_PP_MUL( \ + BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \ + n \ + ) \ + ) \ + BOOST_PP_ENUM( \ + BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \ + BOOST_NO_CHAR BOOST_PP_TUPLE_EAT(3), \ + ~ \ + ) \ + >, \ + string< \ + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, B) \ + > \ + > : \ + concat< \ + string<BOOST_PP_ENUM_PARAMS(n, A) BOOST_PP_COMMA_IF(n) B0>, \ + string< \ + BOOST_PP_ENUM( \ + BOOST_PP_DEC(BOOST_METAPARSE_LIMIT_STRING_SIZE), \ + BOOST_METAPARSE_ARG, \ + ~ \ + ) \ + > \ + > \ + {}; + + BOOST_PP_REPEAT( + BOOST_METAPARSE_LIMIT_STRING_SIZE, + BOOST_METAPARSE_CONCAT, + ~ + ) + + #undef BOOST_METAPARSE_ARG + #undef BOOST_METAPARSE_CONCAT + + template <class S> + struct concat<S, string<> > : S {}; + + template <class A, class B> + struct concat : concat_impl<A, B> {}; +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/empty_string.hpp b/boost/metaparse/v1/impl/empty_string.hpp new file mode 100644 index 0000000000..7b62496450 --- /dev/null +++ b/boost/metaparse/v1/impl/empty_string.hpp @@ -0,0 +1,44 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_EMPTY_STRING_HPP +#define BOOST_METAPARSE_V1_IMPL_EMPTY_STRING_HPP + +// 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> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class Ignore = int> + struct empty_string + { + typedef empty_string type; + + #ifdef BOOST_NO_CONSTEXPR_C_STR + static const char value[1]; + #else + static constexpr char value[1] = {0}; + #endif + }; + + #ifdef BOOST_NO_CONSTEXPR_C_STR + template <class Ignore> + const char empty_string<Ignore>::value[1] = {0}; + #else + template <class Ignore> + constexpr char empty_string<Ignore>::value[1]; + #endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/front_inserter.hpp b/boost/metaparse/v1/impl/front_inserter.hpp new file mode 100644 index 0000000000..620533bfbd --- /dev/null +++ b/boost/metaparse/v1/impl/front_inserter.hpp @@ -0,0 +1,32 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_FRONT_INSERTER_HPP +#define BOOST_METAPARSE_V1_IMPL_FRONT_INSERTER_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/mpl/push_front.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct front_inserter + { + typedef front_inserter type; + + template <class T0, class T1> + struct apply : boost::mpl::push_front<T0, T1> {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/fwd/iterate_impl.hpp b/boost/metaparse/v1/impl/fwd/iterate_impl.hpp new file mode 100644 index 0000000000..7773bf4ca1 --- /dev/null +++ b/boost/metaparse/v1/impl/fwd/iterate_impl.hpp @@ -0,0 +1,34 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_FWD_ITERATE_IMPL_HPP +#define BOOST_METAPARSE_V1_IMPL_FWD_ITERATE_IMPL_HPP + +// 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/is_error.hpp> +#include <boost/metaparse/v1/get_result.hpp> +#include <boost/metaparse/v1/get_remaining.hpp> +#include <boost/metaparse/v1/get_position.hpp> + +#include <boost/mpl/deque.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/push_back.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <int N, class P, class Accum> + struct iterate_impl; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/has_type.hpp b/boost/metaparse/v1/impl/has_type.hpp new file mode 100644 index 0000000000..167ea600a3 --- /dev/null +++ b/boost/metaparse/v1/impl/has_type.hpp @@ -0,0 +1,26 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_HAS_TYPE_HPP +#define BOOST_METAPARSE_V1_IMPL_HAS_TYPE_HPP + +// 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/mpl/has_xxx.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + BOOST_MPL_HAS_XXX_TRAIT_DEF(type) + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/is_any.hpp b/boost/metaparse/v1/impl/is_any.hpp new file mode 100644 index 0000000000..23122b35ce --- /dev/null +++ b/boost/metaparse/v1/impl/is_any.hpp @@ -0,0 +1,70 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_IS_ANY_HPP +#define BOOST_METAPARSE_V1_IMPL_IS_ANY_HPP + +// 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/limit_one_char_except_size.hpp> + +#include <boost/mpl/eval_if.hpp> +#include <boost/mpl/bool.hpp> + +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/arithmetic/dec.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/repeat_from_to.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class Stub = int> + struct is_any0 + { + template <class C> + struct apply : boost::mpl::true_ {}; + }; + + #ifdef BOOST_METAPARSE_DEFINE_IS_ANY + # error BOOST_METAPARSE_DEFINE_IS_ANY already defined + #endif + #define BOOST_METAPARSE_DEFINE_IS_ANY(z, n, unused) \ + template <BOOST_PP_ENUM_PARAMS(n, class T)> \ + struct BOOST_PP_CAT(is_any, n) \ + { \ + template <class C> \ + struct apply : \ + boost::mpl::eval_if< \ + boost::mpl::bool_< \ + C::type::value \ + == BOOST_PP_CAT(T, BOOST_PP_DEC(n))::type::value \ + >, \ + boost::mpl::false_, \ + typename BOOST_PP_CAT(is_any, BOOST_PP_DEC(n))< \ + BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(n), T) \ + >::template apply<C> \ + > \ + {}; \ + }; + + BOOST_PP_REPEAT_FROM_TO( + 1, + BOOST_METAPARSE_LIMIT_ONE_CHAR_EXCEPT_SIZE, + BOOST_METAPARSE_DEFINE_IS_ANY, + ~ + ) + + #undef BOOST_METAPARSE_DEFINE_IS_ANY + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/is_char_c.hpp b/boost/metaparse/v1/impl/is_char_c.hpp new file mode 100644 index 0000000000..1ad298f848 --- /dev/null +++ b/boost/metaparse/v1/impl/is_char_c.hpp @@ -0,0 +1,33 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_IS_CHAR_C_HPP +#define BOOST_METAPARSE_V1_IMPL_IS_CHAR_C_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/mpl/bool.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <char C> + struct is_char_c + { + typedef is_char_c type; + + template <class Ch> + struct apply : boost::mpl::bool_<Ch::type::value == C> {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/iterate_impl.hpp b/boost/metaparse/v1/impl/iterate_impl.hpp new file mode 100644 index 0000000000..f12be9edf6 --- /dev/null +++ b/boost/metaparse/v1/impl/iterate_impl.hpp @@ -0,0 +1,46 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_ITERATE_IMPL_HPP +#define BOOST_METAPARSE_V1_IMPL_ITERATE_IMPL_HPP + +// 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/iterate_impl_unchecked.hpp> +#include <boost/metaparse/v1/return_.hpp> +#include <boost/metaparse/v1/is_error.hpp> + +#include <boost/mpl/eval_if.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <int N, class P, class Accum> + struct iterate_impl + { + typedef iterate_impl type; + + template <class S, class Pos> + struct apply : + boost::mpl::eval_if< + typename is_error<typename P::template apply<S, Pos> >::type, + typename P::template apply<S, Pos>, + iterate_impl_unchecked<N, P, Accum, S, Pos> + > + {}; + }; + + template <class P, class Accum> + struct iterate_impl<0, P, Accum> : return_<Accum> {}; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/iterate_impl_unchecked.hpp b/boost/metaparse/v1/impl/iterate_impl_unchecked.hpp new file mode 100644 index 0000000000..535cd379d9 --- /dev/null +++ b/boost/metaparse/v1/impl/iterate_impl_unchecked.hpp @@ -0,0 +1,44 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_ITERATE_IMPL_UNCHECKED_HPP +#define BOOST_METAPARSE_V1_IMPL_ITERATE_IMPL_UNCHECKED_HPP + +// 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/fwd/iterate_impl.hpp> +#include <boost/metaparse/v1/get_result.hpp> +#include <boost/metaparse/v1/get_remaining.hpp> +#include <boost/metaparse/v1/get_position.hpp> + +#include <boost/mpl/push_back.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <int N, class P, class Accum, class S, class Pos> + struct iterate_impl_unchecked : + iterate_impl< + N - 1, + P, + typename boost::mpl::push_back< + Accum, + typename get_result<typename P::template apply<S, Pos> >::type + >::type + >::template apply< + typename get_remaining<typename P::template apply<S, Pos> >::type, + typename get_position<typename P::template apply<S, Pos> >::type + > + {}; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/later_result.hpp b/boost/metaparse/v1/impl/later_result.hpp new file mode 100644 index 0000000000..69c2e5b89a --- /dev/null +++ b/boost/metaparse/v1/impl/later_result.hpp @@ -0,0 +1,39 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_LATER_RESULT_HPP +#define BOOST_METAPARSE_V1_IMPL_LATER_RESULT_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/metaparse/v1/get_position.hpp> + +#include <boost/mpl/if.hpp> +#include <boost/mpl/less.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class R1, class R2> + struct later_result : + boost::mpl::if_< + typename boost::mpl::less< + typename get_position<R2>::type, + typename get_position<R1>::type + >::type, + R1, + R2 + > + {}; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/next_digit.hpp b/boost/metaparse/v1/impl/next_digit.hpp new file mode 100644 index 0000000000..959ea114c6 --- /dev/null +++ b/boost/metaparse/v1/impl/next_digit.hpp @@ -0,0 +1,36 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_NEXT_DIGIT_HPP +#define BOOST_METAPARSE_V1_IMPL_NEXT_DIGIT_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/mpl/int.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct next_digit + { + typedef next_digit type; + + template <class PartialResult, class NextDigit> + struct apply : + boost::mpl::int_< + PartialResult::type::value * 10 + NextDigit::type::value + > + {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/no_char.hpp b/boost/metaparse/v1/impl/no_char.hpp new file mode 100644 index 0000000000..c6b91f07a6 --- /dev/null +++ b/boost/metaparse/v1/impl/no_char.hpp @@ -0,0 +1,17 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_NO_CHAR_HPP +#define BOOST_METAPARSE_V1_IMPL_NO_CHAR_HPP + +// 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 <cstdio> + +#ifdef BOOST_NO_CHAR +# error BOOST_NO_CHAR already defined +#endif +#define BOOST_NO_CHAR EOF + +#endif + diff --git a/boost/metaparse/v1/impl/nth_of_c.hpp b/boost/metaparse/v1/impl/nth_of_c.hpp new file mode 100644 index 0000000000..d12d164eaa --- /dev/null +++ b/boost/metaparse/v1/impl/nth_of_c.hpp @@ -0,0 +1,61 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_NTH_OF_C_HPP +#define BOOST_METAPARSE_V1_IMPL_NTH_OF_C_HPP + +// 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/nth_of_c_impl.hpp> +#include <boost/metaparse/v1/error/index_out_of_range.hpp> +#include <boost/metaparse/v1/fail.hpp> +#include <boost/metaparse/limit_sequence_size.hpp> + +#include <boost/mpl/list.hpp> + +#include <boost/preprocessor/repetition/repeat.hpp> +#include <boost/preprocessor/punctuation/comma_if.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/cat.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + #ifdef BOOST_METAPARSE_NTH_OF_CASE + # error BOOST_METAPARSE_NTH_OF_CASE already defined + #endif + #define BOOST_METAPARSE_NTH_OF_CASE(z, n, unused) \ + template < \ + int K BOOST_PP_COMMA_IF(n) \ + BOOST_PP_ENUM_PARAMS(n, class P) \ + > \ + struct BOOST_PP_CAT(nth_of_c, n) : \ + boost::mpl::if_< \ + boost::mpl::bool_<(0 <= K && K < n)>, \ + nth_of_c_impl< \ + K, \ + boost::mpl::list<BOOST_PP_ENUM_PARAMS(n, P)> \ + >, \ + fail<error::index_out_of_range<0, n - 1, K> > \ + >::type \ + {}; + + BOOST_PP_REPEAT( + BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE, + BOOST_METAPARSE_NTH_OF_CASE, + ~ + ) + + #undef BOOST_METAPARSE_NTH_OF_CASE + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/nth_of_c_impl.hpp b/boost/metaparse/v1/impl/nth_of_c_impl.hpp new file mode 100644 index 0000000000..c74dcc0dae --- /dev/null +++ b/boost/metaparse/v1/impl/nth_of_c_impl.hpp @@ -0,0 +1,77 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_NTH_OF_C_IMPL_HPP +#define BOOST_METAPARSE_V1_IMPL_NTH_OF_C_IMPL_HPP + +// 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/skip_seq.hpp> + +#include <boost/mpl/front.hpp> +#include <boost/mpl/pop_front.hpp> +#include <boost/mpl/fold.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <int N, class Seq> + struct nth_of_c_impl + { + private: + template <class NextResult> + struct apply_unchecked : + nth_of_c_impl< + N - 1, + typename boost::mpl::pop_front<Seq>::type + >::template apply< + typename get_remaining<NextResult>::type, + typename get_position<NextResult>::type + > + {}; + public: + typedef nth_of_c_impl type; + + template <class S, class Pos> + struct apply : + boost::mpl::eval_if< + typename is_error< + typename boost::mpl::front<Seq>::type::template apply<S, Pos> + >::type, + typename boost::mpl::front<Seq>::type::template apply<S, Pos>, + apply_unchecked< + typename boost::mpl::front<Seq>::type::template apply<S, Pos> + > + > + {}; + }; + + template <class Seq> + struct nth_of_c_impl<0, Seq> + { + typedef nth_of_c_impl type; + + template <class S, class Pos> + struct apply : + boost::mpl::fold< + typename boost::mpl::pop_front<Seq>::type, + typename boost::mpl::front<Seq>::type::template apply< + S, + Pos + >::type, + skip_seq + > + {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/one_char_except_not_used.hpp b/boost/metaparse/v1/impl/one_char_except_not_used.hpp new file mode 100644 index 0000000000..249fcdd725 --- /dev/null +++ b/boost/metaparse/v1/impl/one_char_except_not_used.hpp @@ -0,0 +1,24 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_ONE_CHAR_EXCEPT_NOT_USED_HPP +#define BOOST_METAPARSE_V1_IMPL_ONE_CHAR_EXCEPT_NOT_USED_HPP + +// 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) + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct one_char_except_not_used {}; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/one_of.hpp b/boost/metaparse/v1/impl/one_of.hpp new file mode 100644 index 0000000000..e5b53e2e5c --- /dev/null +++ b/boost/metaparse/v1/impl/one_of.hpp @@ -0,0 +1,44 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_ONE_OF_HPP +#define BOOST_METAPARSE_V1_IMPL_ONE_OF_HPP + +// 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/error/none_of_the_expected_cases_found.hpp> +#include <boost/metaparse/v1/fail.hpp> + +#include <boost/metaparse/v1/impl/one_of_fwd_op.hpp> + +#include <boost/mpl/fold.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class Parsers> + struct one_of + { + typedef one_of type; + + template <class S, class Pos> + struct apply : + boost::mpl::fold< + Parsers, + fail<error::none_of_the_expected_cases_found>::apply<S, Pos>, + one_of_fwd_op<S, Pos> + >::type + {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/one_of_fwd_op.hpp b/boost/metaparse/v1/impl/one_of_fwd_op.hpp new file mode 100644 index 0000000000..97d4658381 --- /dev/null +++ b/boost/metaparse/v1/impl/one_of_fwd_op.hpp @@ -0,0 +1,46 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_ONE_OF_FWD_OP_HPP +#define BOOST_METAPARSE_V1_IMPL_ONE_OF_FWD_OP_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/metaparse/v1/is_error.hpp> +#include <boost/metaparse/v1/impl/later_result.hpp> + +#include <boost/mpl/eval_if.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S, class Pos> + struct one_of_fwd_op + { + typedef one_of_fwd_op type; + + template <class State, class P> + struct apply : + boost::mpl::eval_if< + typename is_error<State>::type, + boost::mpl::eval_if< + typename is_error<typename P::template apply<S, Pos> >::type, + later_result<State, typename P::template apply<S, Pos> >, + typename P::template apply<S, Pos> + >, + State + > + {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/pop_back.hpp b/boost/metaparse/v1/impl/pop_back.hpp new file mode 100644 index 0000000000..7c3d9b30b2 --- /dev/null +++ b/boost/metaparse/v1/impl/pop_back.hpp @@ -0,0 +1,52 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_POP_BACK_HPP +#define BOOST_METAPARSE_V1_IMPL_POP_BACK_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> +#include <boost/metaparse/v1/impl/push_front_c.hpp> +#include <boost/metaparse/v1/impl/size.hpp> +#include <boost/metaparse/v1/impl/update_c.hpp> + +#include <boost/mpl/clear.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S> + struct pop_back; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <char C> + struct pop_back<string<C>> : boost::mpl::clear<string<C>> {}; + + template <char C, char... Cs> + struct pop_back<string<C, Cs...>> : + push_front_c<typename pop_back<string<Cs...>>::type, C> + {}; +#else + template <class S> + struct pop_back : + update_c< + typename S::type, + size<typename S::type>::type::value - 1, + BOOST_NO_CHAR + > + {}; +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/pop_front.hpp b/boost/metaparse/v1/impl/pop_front.hpp new file mode 100644 index 0000000000..ac02d35aa1 --- /dev/null +++ b/boost/metaparse/v1/impl/pop_front.hpp @@ -0,0 +1,62 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_POP_FRONT_HPP +#define BOOST_METAPARSE_V1_IMPL_POP_FRONT_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> + +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/repeat_from_to.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S> + struct pop_front; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <char C, char... Cs> + struct pop_front<string<C, Cs...>> : string<Cs...> {}; +#else + #ifdef BOOST_METAPARSE_POP_FRONT + # error BOOST_METAPARSE_POP_FRONT already defined + #endif + #define BOOST_METAPARSE_POP_FRONT(z, n, unused) \ + BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) BOOST_PP_CAT(C, n) + + template < \ + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C) \ + > + struct + pop_front< + string<BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C)> + > : + string< + BOOST_PP_REPEAT_FROM_TO( + 1, + BOOST_METAPARSE_LIMIT_STRING_SIZE, + BOOST_METAPARSE_POP_FRONT, + ~ + ), + BOOST_NO_CHAR + > + {}; + + #undef BOOST_METAPARSE_POP_FRONT +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/push_back_c.hpp b/boost/metaparse/v1/impl/push_back_c.hpp new file mode 100644 index 0000000000..453043d97c --- /dev/null +++ b/boost/metaparse/v1/impl/push_back_c.hpp @@ -0,0 +1,40 @@ +#ifndef BOOST_METAPARSE_V1_PUSH_BACK_C_HPP +#define BOOST_METAPARSE_V1_PUSH_BACK_C_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> +#include <boost/metaparse/v1/impl/update_c.hpp> +#include <boost/metaparse/v1/impl/size.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S, char C> + struct push_back_c; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <char... Cs, char C> + struct push_back_c<string<Cs...>, C> : string<Cs..., C> {}; +#else + template <class S, char C> + struct push_back_c : + update_c<typename S::type, size<typename S::type>::type::value, C> + {}; +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/push_front_c.hpp b/boost/metaparse/v1/impl/push_front_c.hpp new file mode 100644 index 0000000000..27d0d3c7c9 --- /dev/null +++ b/boost/metaparse/v1/impl/push_front_c.hpp @@ -0,0 +1,53 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_PUSH_FRONT_C_HPP +#define BOOST_METAPARSE_V1_IMPL_PUSH_FRONT_C_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> + +#include <boost/preprocessor/arithmetic/dec.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S, char C> + struct push_front_c; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <char... Cs, char C> + struct push_front_c<string<Cs...>, C> : string<C, Cs...> {}; +#else + template < + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C), + char Ch + > + struct push_front_c< + string<BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C)>, + Ch + > : + string< + Ch, + BOOST_PP_ENUM_PARAMS( + BOOST_PP_DEC(BOOST_METAPARSE_LIMIT_STRING_SIZE), + C + ) + > + {}; +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/remove_trailing_no_chars.hpp b/boost/metaparse/v1/impl/remove_trailing_no_chars.hpp new file mode 100644 index 0000000000..7d561d2709 --- /dev/null +++ b/boost/metaparse/v1/impl/remove_trailing_no_chars.hpp @@ -0,0 +1,57 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_REMOVE_TRAILING_NO_CHARS_HPP +#define BOOST_METAPARSE_V1_IMPL_REMOVE_TRAILING_NO_CHARS_HPP + +// 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> +#include <boost/metaparse/v1/string.hpp> +#include <boost/metaparse/v1/impl/push_front_c.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S> + struct remove_trailing_no_chars : S {}; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + // this code assumes that BOOST_NO_CHARs are at the end of the string + template <char... Cs> + struct remove_trailing_no_chars<string<BOOST_NO_CHAR, Cs...>> : + string<> + {}; + + template <char C, char... Cs> + struct remove_trailing_no_chars<string<C, Cs...>> : + push_front_c<typename remove_trailing_no_chars<string<Cs...>>::type,C> + {}; + +#ifdef _MSC_VER + /* + * These specialisations are needed to avoid an internal compiler error + * in Visual C++ 12 + */ + template <char C> + struct remove_trailing_no_chars<string<C>> : string<C> {}; + + template <> + struct remove_trailing_no_chars<string<BOOST_NO_CHAR>> : string<> {}; + + template <> + struct remove_trailing_no_chars<string<>> : string<> {}; +#endif +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/returns.hpp b/boost/metaparse/v1/impl/returns.hpp new file mode 100644 index 0000000000..ede50f6a8f --- /dev/null +++ b/boost/metaparse/v1/impl/returns.hpp @@ -0,0 +1,28 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_RETURNS_HPP +#define BOOST_METAPARSE_V1_IMPL_RETURNS_HPP + +// 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) + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class T> + struct returns + { + typedef T type; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/sequence.hpp b/boost/metaparse/v1/impl/sequence.hpp new file mode 100644 index 0000000000..c500cdf046 --- /dev/null +++ b/boost/metaparse/v1/impl/sequence.hpp @@ -0,0 +1,59 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_SEQUENCE_HPP +#define BOOST_METAPARSE_V1_IMPL_SEQUENCE_HPP + +// 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/sequence_impl.hpp> +#include <boost/metaparse/limit_sequence_size.hpp> + +#include <boost/mpl/vector.hpp> + +#include <boost/preprocessor/repetition/repeat_from_to.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/cat.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + #ifdef BOOST_METAPARSE_SEQUENCE_CASE + # error BOOST_METAPARSE_SEQUENCE_CASE already defined + #endif + #define BOOST_METAPARSE_SEQUENCE_CASE(z, n, unused) \ + template <BOOST_PP_ENUM_PARAMS(n, class P)> \ + struct BOOST_PP_CAT(sequence, n) \ + { \ + typedef BOOST_PP_CAT(sequence, n) type; \ + \ + template <class S, class Pos> \ + struct apply : \ + sequence_impl< \ + boost::mpl::vector<BOOST_PP_ENUM_PARAMS(n, P)>, \ + S, \ + Pos \ + > \ + {}; \ + }; + + BOOST_PP_REPEAT_FROM_TO( + 1, + BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE, + BOOST_METAPARSE_SEQUENCE_CASE, + ~ + ) + + #undef BOOST_METAPARSE_SEQUENCE_CASE + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/sequence_impl.hpp b/boost/metaparse/v1/impl/sequence_impl.hpp new file mode 100644 index 0000000000..d3310ed8af --- /dev/null +++ b/boost/metaparse/v1/impl/sequence_impl.hpp @@ -0,0 +1,37 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_SEQUENCE_IMPL_HPP +#define BOOST_METAPARSE_V1_IMPL_SEQUENCE_IMPL_HPP + +// 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/apply_parser.hpp> +#include <boost/metaparse/v1/accept.hpp> + +#include <boost/mpl/deque.hpp> +#include <boost/mpl/fold.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class Ps, class S, class Pos> + struct sequence_impl : + boost::mpl::fold< + Ps, + accept<boost::mpl::deque<>, S, Pos>, + apply_parser + > + {}; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/size.hpp b/boost/metaparse/v1/impl/size.hpp new file mode 100644 index 0000000000..c6e0ee7e27 --- /dev/null +++ b/boost/metaparse/v1/impl/size.hpp @@ -0,0 +1,69 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_SIZE_HPP +#define BOOST_METAPARSE_V1_IMPL_SIZE_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> + +#include <boost/mpl/int.hpp> + +#include <boost/preprocessor/arithmetic/sub.hpp> +#include <boost/preprocessor/punctuation/comma_if.hpp> +#include <boost/preprocessor/repetition/enum.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/repeat.hpp> +#include <boost/preprocessor/tuple/eat.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <class S> + struct size; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <char... Cs> + struct size<string<Cs...>> : boost::mpl::int_<sizeof...(Cs)> {}; +#else + #ifdef BOOST_METAPARSE_STRING_CASE + # error BOOST_METAPARSE_STRING_CASE + #endif + #define BOOST_METAPARSE_STRING_CASE(z, n, unused) \ + template <BOOST_PP_ENUM_PARAMS(n, int C)> \ + struct \ + size< \ + string< \ + BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) \ + BOOST_PP_ENUM( \ + BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \ + BOOST_NO_CHAR BOOST_PP_TUPLE_EAT(3), \ + ~ \ + ) \ + > \ + > : \ + boost::mpl::int_<n> \ + {}; + + BOOST_PP_REPEAT( + BOOST_METAPARSE_LIMIT_STRING_SIZE, + BOOST_METAPARSE_STRING_CASE, + ~ + ) + + #undef BOOST_METAPARSE_STRING_CASE +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/skip_seq.hpp b/boost/metaparse/v1/impl/skip_seq.hpp new file mode 100644 index 0000000000..4d7e5b138a --- /dev/null +++ b/boost/metaparse/v1/impl/skip_seq.hpp @@ -0,0 +1,74 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_SKIP_SEQ_HPP +#define BOOST_METAPARSE_V1_IMPL_SKIP_SEQ_HPP + +// 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/is_error.hpp> +#include <boost/metaparse/v1/accept.hpp> +#include <boost/metaparse/v1/get_remaining.hpp> +#include <boost/metaparse/v1/get_position.hpp> +#include <boost/metaparse/v1/get_result.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct skip_seq + { + private: + template <class ParsingResult, class NewResultValue> + struct change_result : + accept< + NewResultValue, + typename get_remaining<ParsingResult>::type, + typename get_position<ParsingResult>::type + > + {}; + + template <class Result, class P> + struct apply_unchecked : + boost::mpl::eval_if< + typename is_error< + typename P::template apply< + typename get_remaining<Result>::type, + typename get_position<Result>::type + > + >::type, + typename P::template apply< + typename get_remaining<Result>::type, + typename get_position<Result>::type + >, + change_result< + typename P::template apply< + typename get_remaining<Result>::type, + typename get_position<Result>::type + >, + typename get_result<Result>::type + > + > + {}; + + public: + template <class Result, class P> + struct apply : + boost::mpl::eval_if< + is_error<Result>, + Result, + apply_unchecked<Result, P> + > + {}; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/split_at_c.hpp b/boost/metaparse/v1/impl/split_at_c.hpp new file mode 100644 index 0000000000..44c2675905 --- /dev/null +++ b/boost/metaparse/v1/impl/split_at_c.hpp @@ -0,0 +1,101 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_SPLIT_AT_C_HPP +#define BOOST_METAPARSE_V1_IMPL_SPLIT_AT_C_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> +#include <boost/metaparse/v1/impl/push_front_c.hpp> + +#include <boost/preprocessor/arithmetic/add.hpp> +#include <boost/preprocessor/arithmetic/sub.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/repetition/enum.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/repeat.hpp> + +#include <boost/mpl/pair.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + template <int N, class S> + struct split_at_c; + +#ifdef BOOST_METAPARSE_VARIADIC_STRING + template <int N, char C, char... Cs> + struct split_at_c<N, string<C, Cs...>> : + boost::mpl::pair< + typename push_front_c< + typename split_at_c<N - 1, string<Cs...>>::type::first, + C + >::type, + typename split_at_c<N - 1, string<Cs...>>::type::second + > + {}; + + template <char C, char... Cs> + struct split_at_c<0, string<C, Cs...>> : + boost::mpl::pair<string<>, string<C, Cs...>> + {}; + + template <char... Cs> + struct split_at_c<0, string<Cs...>> : + boost::mpl::pair<string<>, string<Cs...>> + {}; +#else + #ifdef BOOST_METAPARSE_ARG + # error BOOST_METAPARSE_ARG already defined + #endif + #define BOOST_METAPARSE_ARG(z, n, d) BOOST_PP_CAT(C, BOOST_PP_ADD(n, d)) + + #ifdef BOOST_METAPARSE_SPLIT_AT + # error BOOST_METAPARSE_SPLIT_AT already defined + #endif + #define BOOST_METAPARSE_SPLIT_AT(z, n, unused) \ + template < \ + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C) \ + > \ + struct \ + split_at_c< \ + n, \ + string<BOOST_PP_ENUM_PARAMS( \ + BOOST_METAPARSE_LIMIT_STRING_SIZE, C) \ + > \ + > : \ + boost::mpl::pair< \ + string<BOOST_PP_ENUM_PARAMS(n, C)>, \ + string< \ + BOOST_PP_ENUM( \ + BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_STRING_SIZE, n), \ + BOOST_METAPARSE_ARG, \ + n \ + ) \ + > \ + > \ + {}; + + BOOST_PP_REPEAT( + BOOST_METAPARSE_LIMIT_STRING_SIZE, + BOOST_METAPARSE_SPLIT_AT, + ~ + ) + + #undef BOOST_METAPARSE_SPLIT_AT + #undef BOOST_METAPARSE_ARG +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/string_iterator.hpp b/boost/metaparse/v1/impl/string_iterator.hpp new file mode 100644 index 0000000000..3e37ff3b0d --- /dev/null +++ b/boost/metaparse/v1/impl/string_iterator.hpp @@ -0,0 +1,159 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_STRING_ITERATOR_HPP +#define BOOST_METAPARSE_V1_IMPL_STRING_ITERATOR_HPP + +// 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/metaparse/v1/impl/at_c.hpp> + + +#include <boost/mpl/iterator_tags.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/bool.hpp> + +#include <boost/type_traits/is_same.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + // string_iterator + template <class S, int N> + struct string_iterator + { + typedef string_iterator type; + typedef string_iterator_tag tag; + typedef boost::mpl::random_access_iterator_tag category; + }; + + // advance_c + + template <class S, int N> + struct advance_c; + + template <class S, int N, int P> + struct advance_c<string_iterator<S, N>, P> : + string_iterator<S, N + P> + {}; + + // distance + + template <class A, class B> + struct distance; + + template <class S, int A, int B> + struct distance<string_iterator<S, A>, string_iterator<S, B> > : + boost::mpl::int_<B - A> + {}; + } + } + } +} + +namespace boost +{ + namespace mpl + { + // advance + template <class S> + struct advance_impl; + + template <> + struct advance_impl<boost::metaparse::v1::impl::string_iterator_tag> + { + typedef advance_impl type; + + template <class S, class N> + struct apply : + boost::metaparse::v1::impl::advance_c< + typename S::type, N::type::value + > + {}; + }; + + // distance + template <class S> + struct distance_impl; + + template <> + struct distance_impl<boost::metaparse::v1::impl::string_iterator_tag> + { + typedef distance_impl type; + + template <class A, class B> + struct apply : + boost::metaparse::v1::impl::distance< + typename A::type, + typename B::type + > + {}; + }; + + // next + template <class S> + struct next; + + template <class S, int N> + struct next<boost::metaparse::v1::impl::string_iterator<S, N> > : + boost::metaparse::v1::impl::string_iterator<S, N + 1> + {}; + + // prior + template <class S> + struct prior; + + template <class S, int N> + struct prior<boost::metaparse::v1::impl::string_iterator<S, N> > : + boost::metaparse::v1::impl::string_iterator<S, N - 1> + {}; + + // deref + template <class S> + struct deref; + + template <class S, int N> + struct deref<boost::metaparse::v1::impl::string_iterator<S, N> > : + boost::metaparse::v1::impl::at_c<S, N> + {}; + + // equal_to + template <class A, class B> + struct equal_to_impl; + + template <> + struct equal_to_impl< + boost::metaparse::v1::impl::string_iterator_tag, + boost::metaparse::v1::impl::string_iterator_tag + > + { + typedef equal_to_impl type; + + template <class A, class B> + struct apply : is_same<typename A::type, typename B::type> {}; + }; + + template <class T> + struct equal_to_impl<boost::metaparse::v1::impl::string_iterator_tag, T> + { + typedef equal_to_impl type; + + template <class, class> + struct apply : false_ {}; + }; + + template <class T> + struct equal_to_impl<T, boost::metaparse::v1::impl::string_iterator_tag> : + equal_to_impl<boost::metaparse::v1::impl::string_iterator_tag, T> + {}; + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/string_iterator_tag.hpp b/boost/metaparse/v1/impl/string_iterator_tag.hpp new file mode 100644 index 0000000000..b7d9041006 --- /dev/null +++ b/boost/metaparse/v1/impl/string_iterator_tag.hpp @@ -0,0 +1,27 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_STRING_ITERATOR_TAG_HPP +#define BOOST_METAPARSE_V1_IMPL_STRING_ITERATOR_TAG_HPP + +// 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) + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct string_iterator_tag + { + typedef string_iterator_tag type; + }; + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/update_c.hpp b/boost/metaparse/v1/impl/update_c.hpp new file mode 100644 index 0000000000..5553933e95 --- /dev/null +++ b/boost/metaparse/v1/impl/update_c.hpp @@ -0,0 +1,93 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_UPDATE_C_HPP +#define BOOST_METAPARSE_V1_IMPL_UPDATE_C_HPP + +// 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> +#include <boost/metaparse/v1/fwd/string.hpp> +#include <boost/metaparse/v1/impl/split_at_c.hpp> +#include <boost/metaparse/v1/impl/concat.hpp> + +#include <boost/preprocessor/arithmetic/dec.hpp> +#include <boost/preprocessor/arithmetic/inc.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/punctuation/comma_if.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/repeat.hpp> +#include <boost/preprocessor/repetition/repeat_from_to.hpp> + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { +#ifndef BOOST_METAPARSE_VARIADIC_STRING + template <class S, int N, int C> + struct update_c; + + #ifdef BOOST_METAPARSE_ARGN + # error BOOST_METAPARSE_ARGN already defined + #endif + #define BOOST_METAPARSE_ARGN(z, n, unused) , BOOST_PP_CAT(C, n) + + #ifdef BOOST_METAPARSE_UPDATE + # error BOOST_METAPARSE_UPDATE already defined + #endif + #define BOOST_METAPARSE_UPDATE(z, n, unused) \ + template < \ + BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, int C), \ + int Ch \ + > \ + struct update_c< \ + string<BOOST_PP_ENUM_PARAMS(BOOST_METAPARSE_LIMIT_STRING_SIZE, C)>,\ + n, \ + Ch \ + > : \ + string< \ + BOOST_PP_ENUM_PARAMS(n, C) BOOST_PP_COMMA_IF(n) \ + Ch \ + BOOST_PP_REPEAT_FROM_TO( \ + BOOST_PP_INC(n), \ + BOOST_PP_DEC(BOOST_METAPARSE_LIMIT_STRING_SIZE), \ + BOOST_METAPARSE_ARGN, \ + ~ \ + ) \ + > \ + {}; + + BOOST_PP_REPEAT( + BOOST_METAPARSE_LIMIT_STRING_SIZE, + BOOST_METAPARSE_UPDATE, + ~ + ) + + #undef BOOST_METAPARSE_UPDATE + #undef BOOST_METAPARSE_ARGN +#else + template <class S, int N, char C> + struct update_c : + concat< + typename split_at_c<N, S>::type::first, + typename + update_c<typename split_at_c<N, S>::type::second, 0, C>::type + > + {}; + + template <char... Cs, char C, char NewChar> + struct update_c<string<C, Cs...>, 0, NewChar> : + string<NewChar, Cs...> + {}; +#endif + } + } + } +} + +#endif + diff --git a/boost/metaparse/v1/impl/void_.hpp b/boost/metaparse/v1/impl/void_.hpp new file mode 100644 index 0000000000..03c1d4598f --- /dev/null +++ b/boost/metaparse/v1/impl/void_.hpp @@ -0,0 +1,25 @@ +#ifndef BOOST_METAPARSE_V1_IMPL_VOID_HPP +#define BOOST_METAPARSE_V1_IMPL_VOID_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) + + +namespace boost +{ + namespace metaparse + { + namespace v1 + { + namespace impl + { + struct void_ { typedef void_ type; }; + } + } + } +} + +#endif + |