]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | 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 | Iterator current(first); | |
32 | for (/**/; current != last; ++current) | |
33 | { | |
34 | if (this->subject.parse(current, last, context, rcontext, attr)) | |
35 | { | |
36 | first = current; | |
37 | return true; | |
38 | } | |
39 | } | |
40 | ||
41 | // Test for when subjects match on input empty. Example: | |
42 | // comment = "//" >> seek[eol | eoi] | |
43 | if (this->subject.parse(current, last, context, rcontext, attr)) | |
44 | { | |
45 | first = current; | |
46 | return true; | |
47 | } | |
48 | ||
49 | return false; | |
50 | } | |
51 | }; | |
52 | ||
53 | struct seek_gen | |
54 | { | |
55 | template<typename Subject> | |
56 | seek_directive<typename extension::as_parser<Subject>::value_type> | |
57 | operator[](Subject const& subject) const | |
58 | { | |
59 | return { as_parser(subject) }; | |
60 | } | |
61 | }; | |
62 | ||
63 | auto const seek = seek_gen{}; | |
64 | }}} | |
65 | ||
66 | #endif |