| 1 | /*============================================================================= |
| 2 | Copyright (c) 2011 Jamboree |
| 3 | Copyright (c) 2014 Lee Clagett |
| 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_SEEK_APRIL_13_2014_1920PM) |
| 9 | #define BOOST_SPIRIT_X3_SEEK_APRIL_13_2014_1920PM |
| 10 | |
| 11 | #include <boost/spirit/home/x3/core/parser.hpp> |
| 12 | |
| 13 | namespace boost { namespace spirit { namespace x3 |
| 14 | { |
| 15 | template<typename Subject> |
| 16 | struct seek_directive : unary_parser<Subject, seek_directive<Subject>> |
| 17 | { |
| 18 | typedef unary_parser<Subject, seek_directive<Subject>> base_type; |
| 19 | static bool const is_pass_through_unary = true; |
| 20 | static bool const handles_container = Subject::handles_container; |
| 21 | |
| 22 | constexpr seek_directive(Subject const& subject) : |
| 23 | base_type(subject) {} |
| 24 | |
| 25 | template<typename Iterator, typename Context |
| 26 | , typename RContext, typename Attribute> |
| 27 | bool parse( |
| 28 | Iterator& first, Iterator const& last |
| 29 | , Context const& context, RContext& rcontext, Attribute& attr) const |
| 30 | { |
| 31 | for (Iterator current(first);; ++current) |
| 32 | { |
| 33 | if (this->subject.parse(current, last, context, rcontext, attr)) |
| 34 | { |
| 35 | first = current; |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | // fail only after subject fails & no input |
| 40 | if (current == last) |
| 41 | return false; |
| 42 | } |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | struct seek_gen |
| 47 | { |
| 48 | template<typename Subject> |
| 49 | constexpr seek_directive<typename extension::as_parser<Subject>::value_type> |
| 50 | operator[](Subject const& subject) const |
| 51 | { |
| 52 | return { as_parser(subject) }; |
| 53 | } |
| 54 | }; |
| 55 | |
| 56 | constexpr auto seek = seek_gen{}; |
| 57 | }}} |
| 58 | |
| 59 | #endif |
| 60 | |