foldl_reject_incomplete.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef BOOST_METAPARSE_V1_FOLDL_REJECT_INCOMPLETE_HPP
  2. #define BOOST_METAPARSE_V1_FOLDL_REJECT_INCOMPLETE_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/metaparse/v1/fail_at_first_char_expected.hpp>
  8. #include <boost/metaparse/v1/is_error.hpp>
  9. #include <boost/metaparse/v1/get_position.hpp>
  10. #include <boost/metaparse/v1/get_result.hpp>
  11. #include <boost/metaparse/v1/get_remaining.hpp>
  12. #include <boost/mpl/eval_if.hpp>
  13. #include <boost/mpl/equal_to.hpp>
  14. namespace boost
  15. {
  16. namespace metaparse
  17. {
  18. namespace v1
  19. {
  20. template <class P, class State, class ForwardOp>
  21. struct foldl_reject_incomplete
  22. {
  23. private:
  24. template <class Res>
  25. struct apply_unchecked :
  26. // I need to use apply_wrap, and not apply, because apply would
  27. // build a metafunction class from foldl<P, State, ForwardOp>
  28. // when ForwardOp is a lambda expression.
  29. foldl_reject_incomplete<
  30. P,
  31. typename ForwardOp::template apply<
  32. typename State::type,
  33. typename get_result<Res>::type
  34. >,
  35. ForwardOp
  36. >::template apply<
  37. typename get_remaining<Res>::type,
  38. typename get_position<Res>::type
  39. >
  40. {};
  41. template <class S, class Pos>
  42. struct accept_state : accept<typename State::type, S, Pos> {};
  43. template <class S, class Pos>
  44. struct end_of_folding :
  45. boost::mpl::eval_if<
  46. typename boost::mpl::equal_to<
  47. typename Pos::type,
  48. typename get_position<typename P::template apply<S, Pos> >::type
  49. >::type,
  50. accept_state<S, Pos>,
  51. typename P::template apply<S, Pos>
  52. >
  53. {};
  54. public:
  55. typedef foldl_reject_incomplete type;
  56. template <class S, class Pos>
  57. struct apply :
  58. boost::mpl::eval_if<
  59. typename is_error<typename P::template apply<S, Pos> >::type,
  60. end_of_folding<S, Pos>,
  61. apply_unchecked<typename P::template apply<S, Pos> >
  62. >
  63. {};
  64. };
  65. }
  66. }
  67. }
  68. #endif