1 #ifndef BOOST_METAPARSE_V1_FOLDR_START_WITH_PARSER_HPP 2 #define BOOST_METAPARSE_V1_FOLDR_START_WITH_PARSER_HPP 3 4 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. 5 // Distributed under the Boost Software License, Version 1.0. 6 // (See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt) 8 9 #include <boost/metaparse/v1/accept.hpp> 10 #include <boost/metaparse/v1/is_error.hpp> 11 #include <boost/metaparse/v1/get_position.hpp> 12 #include <boost/metaparse/v1/get_result.hpp> 13 #include <boost/metaparse/v1/get_remaining.hpp> 14 15 #include <boost/mpl/eval_if.hpp> 16 17 namespace boost 18 { 19 namespace metaparse 20 { 21 namespace v1 22 { 23 template <class P, class StateP, class BackwardOp> 24 struct foldr_start_with_parser 25 { 26 private: 27 template <class Res, class Rem> 28 struct apply_unchecked1 : 29 accept< 30 typename BackwardOp::template apply< 31 typename get_result<Rem>::type, 32 typename get_result<Res>::type 33 >::type, 34 typename get_remaining<Rem>::type, 35 typename get_position<Rem>::type 36 > 37 {}; 38 39 template <class Res> 40 struct apply_unchecked; 41 public: 42 typedef foldr_start_with_parser type; 43 44 template <class S, class Pos> 45 struct apply : 46 boost::mpl::eval_if< 47 typename is_error<typename P::template apply<S, Pos> >::type, 48 typename StateP::template apply<S, Pos>, 49 apply_unchecked<typename P::template apply<S, Pos> > 50 > 51 {}; 52 private: 53 template <class Res> 54 struct apply_unchecked 55 { 56 private: 57 typedef 58 typename foldr_start_with_parser::template apply< 59 typename get_remaining<Res>::type, 60 typename get_position<Res>::type 61 > 62 parsed_remaining; 63 public: 64 typedef 65 typename boost::mpl::eval_if< 66 typename is_error<parsed_remaining>::type, 67 parsed_remaining, 68 apply_unchecked1<Res, parsed_remaining> 69 >::type 70 type; 71 }; 72 }; 73 } 74 } 75 } 76 77 #endif 78 79