foldr_start_with_parser.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef BOOST_METAPARSE_V1_FOLDR_START_WITH_PARSER_HPP
  2. #define BOOST_METAPARSE_V1_FOLDR_START_WITH_PARSER_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
  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/accept.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. namespace boost
  14. {
  15. namespace metaparse
  16. {
  17. namespace v1
  18. {
  19. template <class P, class StateP, class BackwardOp>
  20. struct foldr_start_with_parser
  21. {
  22. private:
  23. template <class Res, class Rem>
  24. struct apply_unchecked1 :
  25. accept<
  26. typename BackwardOp::template apply<
  27. typename get_result<Rem>::type,
  28. typename get_result<Res>::type
  29. >::type,
  30. typename get_remaining<Rem>::type,
  31. typename get_position<Rem>::type
  32. >
  33. {};
  34. template <class Res>
  35. struct apply_unchecked;
  36. public:
  37. typedef foldr_start_with_parser type;
  38. template <class S, class Pos>
  39. struct apply :
  40. boost::mpl::eval_if<
  41. typename is_error<typename P::template apply<S, Pos> >::type,
  42. typename StateP::template apply<S, Pos>,
  43. apply_unchecked<typename P::template apply<S, Pos> >
  44. >
  45. {};
  46. private:
  47. template <class Res>
  48. struct apply_unchecked
  49. {
  50. private:
  51. typedef
  52. typename foldr_start_with_parser::template apply<
  53. typename get_remaining<Res>::type,
  54. typename get_position<Res>::type
  55. >
  56. parsed_remaining;
  57. public:
  58. typedef
  59. typename boost::mpl::eval_if<
  60. typename is_error<parsed_remaining>::type,
  61. parsed_remaining,
  62. apply_unchecked1<Res, parsed_remaining>
  63. >::type
  64. type;
  65. };
  66. };
  67. }
  68. }
  69. }
  70. #endif