]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2009 Chris Hoeppler | |
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 | ||
9 | #if !defined(BOOST_SPIRIT_X3_CONFIX_MAY_30_2014_1819PM) | |
10 | #define BOOST_SPIRIT_X3_CONFIX_MAY_30_2014_1819PM | |
11 | ||
12 | #include <boost/spirit/home/x3/core/parser.hpp> | |
13 | ||
14 | namespace boost { namespace spirit { namespace x3 | |
15 | { | |
16 | template<typename Prefix, typename Subject, typename Postfix> | |
17 | struct confix_directive : | |
18 | unary_parser<Subject, confix_directive<Prefix, Subject, Postfix>> | |
19 | { | |
20 | typedef unary_parser< | |
21 | Subject, confix_directive<Prefix, Subject, Postfix>> base_type; | |
22 | static bool const is_pass_through_unary = true; | |
23 | static bool const handles_container = Subject::handles_container; | |
24 | ||
25 | confix_directive(Prefix const& prefix | |
26 | , Subject const& subject | |
27 | , Postfix const& postfix) : | |
28 | base_type(subject), | |
29 | prefix(prefix), | |
30 | postfix(postfix) | |
31 | { | |
32 | } | |
33 | ||
34 | template<typename Iterator, typename Context | |
35 | , typename RContext, typename Attribute> | |
36 | bool parse( | |
37 | Iterator& first, Iterator const& last | |
38 | , Context& context, RContext& rcontext, Attribute& attr) const | |
39 | { | |
40 | Iterator save = first; | |
41 | ||
42 | if (!(prefix.parse(first, last, context, rcontext, unused) && | |
43 | this->subject.parse(first, last, context, rcontext, attr) && | |
44 | postfix.parse(first, last, context, rcontext, unused))) | |
45 | { | |
46 | first = save; | |
47 | return false; | |
48 | } | |
49 | ||
50 | return true; | |
51 | } | |
52 | ||
53 | Prefix prefix; | |
54 | Postfix postfix; | |
55 | }; | |
56 | ||
57 | template<typename Prefix, typename Postfix> | |
58 | struct confix_gen | |
59 | { | |
60 | template<typename Subject> | |
61 | confix_directive< | |
62 | Prefix, typename extension::as_parser<Subject>::value_type, Postfix> | |
63 | operator[](Subject const& subject) const | |
64 | { | |
65 | return { prefix, as_parser(subject), postfix }; | |
66 | } | |
67 | ||
68 | Prefix prefix; | |
69 | Postfix postfix; | |
70 | }; | |
71 | ||
72 | ||
73 | template<typename Prefix, typename Postfix> | |
74 | confix_gen<typename extension::as_parser<Prefix>::value_type, | |
75 | typename extension::as_parser<Postfix>::value_type> | |
76 | confix(Prefix const& prefix, Postfix const& postfix) | |
77 | { | |
78 | return { as_parser(prefix), as_parser(postfix) }; | |
79 | } | |
80 | ||
81 | }}} | |
82 | ||
83 | #endif |