]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2014 Joel de Guzman | |
3 | ||
4 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | =============================================================================*/ | |
7 | #if !defined(SPIRIT_X3_RAW_APRIL_9_2007_0912AM) | |
8 | #define SPIRIT_X3_RAW_APRIL_9_2007_0912AM | |
9 | ||
10 | #include <boost/spirit/home/x3/core/skip_over.hpp> | |
11 | #include <boost/spirit/home/x3/core/parser.hpp> | |
12 | #include <boost/spirit/home/x3/support/traits/move_to.hpp> | |
13 | #include <boost/range/iterator_range.hpp> | |
14 | ||
15 | namespace boost { namespace spirit { namespace x3 | |
16 | { | |
17 | // this is a pseudo attribute type indicating that the parser wants the | |
18 | // iterator range pointing to the [first, last) matching characters from | |
19 | // the input iterators. | |
20 | struct raw_attribute_type {}; | |
21 | ||
22 | template <typename Subject> | |
23 | struct raw_directive : unary_parser<Subject, raw_directive<Subject>> | |
24 | { | |
25 | typedef unary_parser<Subject, raw_directive<Subject> > base_type; | |
26 | typedef raw_attribute_type attribute_type; | |
27 | static bool const handles_container = Subject::handles_container; | |
28 | typedef Subject subject_type; | |
29 | ||
30 | raw_directive(Subject const& subject) | |
31 | : base_type(subject) {} | |
32 | ||
33 | template <typename Iterator, typename Context | |
34 | , typename RContext, typename Attribute> | |
35 | bool parse(Iterator& first, Iterator const& last | |
36 | , Context const& context, RContext& rcontext, Attribute& attr) const | |
37 | { | |
38 | x3::skip_over(first, last, context); | |
39 | Iterator i = first; | |
40 | if (this->subject.parse(i, last, context, rcontext, unused)) | |
41 | { | |
42 | traits::move_to(first, i, attr); | |
43 | first = i; | |
44 | return true; | |
45 | } | |
46 | return false; | |
47 | } | |
48 | ||
49 | template <typename Iterator, typename Context, typename RContext> | |
50 | bool parse(Iterator& first, Iterator const& last | |
51 | , Context const& context, RContext& rcontext, unused_type) const | |
52 | { | |
53 | return this->subject.parse(first, last, context, rcontext, unused); | |
54 | } | |
55 | }; | |
56 | ||
57 | struct raw_gen | |
58 | { | |
59 | template <typename Subject> | |
60 | raw_directive<typename extension::as_parser<Subject>::value_type> | |
61 | operator[](Subject const& subject) const | |
62 | { | |
63 | return { as_parser(subject) }; | |
64 | } | |
65 | }; | |
66 | ||
67 | auto const raw = raw_gen{}; | |
68 | }}} | |
69 | ||
70 | #endif |