| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2014 Joel de Guzman |
| 3 | Copyright (c) 2013 Agustin Berge |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 7 | =============================================================================*/ |
| 8 | #if !defined(BOOST_SPIRIT_X3_SKIP_JANUARY_26_2008_0422PM) |
| 9 | #define BOOST_SPIRIT_X3_SKIP_JANUARY_26_2008_0422PM |
| 10 | |
| 11 | #include <boost/spirit/home/x3/support/context.hpp> |
| 12 | #include <boost/spirit/home/x3/support/unused.hpp> |
| 13 | #include <boost/spirit/home/x3/core/skip_over.hpp> |
| 14 | #include <boost/spirit/home/x3/core/parser.hpp> |
| 15 | #include <boost/utility/enable_if.hpp> |
| 16 | |
| 17 | namespace boost { namespace spirit { namespace x3 |
| 18 | { |
| 19 | template <typename Subject> |
| 20 | struct reskip_directive : unary_parser<Subject, reskip_directive<Subject>> |
| 21 | { |
| 22 | typedef unary_parser<Subject, reskip_directive<Subject>> base_type; |
| 23 | static bool const is_pass_through_unary = true; |
| 24 | static bool const handles_container = Subject::handles_container; |
| 25 | |
| 26 | constexpr reskip_directive(Subject const& subject) |
| 27 | : base_type(subject) {} |
| 28 | |
| 29 | template <typename Iterator, typename Context |
| 30 | , typename RContext, typename Attribute> |
| 31 | typename disable_if<has_skipper<Context>, bool>::type |
| 32 | parse(Iterator& first, Iterator const& last |
| 33 | , Context const& context, RContext& rcontext, Attribute& attr) const |
| 34 | { |
| 35 | auto const& skipper = |
| 36 | detail::get_unused_skipper(x3::get<skipper_tag>(context)); |
| 37 | |
| 38 | return this->subject.parse( |
| 39 | first, last |
| 40 | , make_context<skipper_tag>(skipper, context) |
| 41 | , rcontext |
| 42 | , attr); |
| 43 | } |
| 44 | template <typename Iterator, typename Context |
| 45 | , typename RContext, typename Attribute> |
| 46 | typename enable_if<has_skipper<Context>, bool>::type |
| 47 | parse(Iterator& first, Iterator const& last |
| 48 | , Context const& context, RContext& rcontext, Attribute& attr) const |
| 49 | { |
| 50 | return this->subject.parse( |
| 51 | first, last |
| 52 | , context |
| 53 | , rcontext |
| 54 | , attr); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | template <typename Subject, typename Skipper> |
| 59 | struct skip_directive : unary_parser<Subject, skip_directive<Subject, Skipper>> |
| 60 | { |
| 61 | typedef unary_parser<Subject, skip_directive<Subject, Skipper>> base_type; |
| 62 | static bool const is_pass_through_unary = true; |
| 63 | static bool const handles_container = Subject::handles_container; |
| 64 | |
| 65 | constexpr skip_directive(Subject const& subject, Skipper const& skipper) |
| 66 | : base_type(subject) |
| 67 | , skipper(skipper) |
| 68 | {} |
| 69 | |
| 70 | template <typename Iterator, typename Context |
| 71 | , typename RContext, typename Attribute> |
| 72 | bool parse(Iterator& first, Iterator const& last |
| 73 | , Context const& context, RContext& rcontext, Attribute& attr) const |
| 74 | { |
| 75 | return this->subject.parse( |
| 76 | first, last |
| 77 | , make_context<skipper_tag>(skipper, context) |
| 78 | , rcontext |
| 79 | , attr); |
| 80 | } |
| 81 | |
| 82 | Skipper const skipper; |
| 83 | }; |
| 84 | |
| 85 | struct reskip_gen |
| 86 | { |
| 87 | template <typename Skipper> |
| 88 | struct skip_gen |
| 89 | { |
| 90 | constexpr skip_gen(Skipper const& skipper) |
| 91 | : skipper_(skipper) {} |
| 92 | |
| 93 | template <typename Subject> |
| 94 | constexpr skip_directive<typename extension::as_parser<Subject>::value_type, Skipper> |
| 95 | operator[](Subject const& subject) const |
| 96 | { |
| 97 | return { as_parser(subject), skipper_ }; |
| 98 | } |
| 99 | |
| 100 | Skipper skipper_; |
| 101 | }; |
| 102 | |
| 103 | template <typename Skipper> |
| 104 | constexpr skip_gen<Skipper> const operator()(Skipper const& skipper) const |
| 105 | { |
| 106 | return { skipper }; |
| 107 | } |
| 108 | |
| 109 | template <typename Subject> |
| 110 | constexpr reskip_directive<typename extension::as_parser<Subject>::value_type> |
| 111 | operator[](Subject const& subject) const |
| 112 | { |
| 113 | return { as_parser(subject) }; |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | constexpr auto skip = reskip_gen{}; |
| 118 | }}} |
| 119 | |
| 120 | #endif |
| 121 | |