]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-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 | =============================================================================*/ | |
11fdf7f2 TL |
7 | #if !defined(BOOST_SPIRIT_X3_DIFFERENCE_FEBRUARY_11_2007_1250PM) |
8 | #define BOOST_SPIRIT_X3_DIFFERENCE_FEBRUARY_11_2007_1250PM | |
7c673cae FG |
9 | |
10 | #include <boost/spirit/home/x3/support/traits/attribute_of.hpp> | |
11 | #include <boost/spirit/home/x3/support/traits/has_attribute.hpp> | |
12 | #include <boost/spirit/home/x3/core/parser.hpp> | |
13 | ||
14 | namespace boost { namespace spirit { namespace x3 | |
15 | { | |
16 | template <typename Left, typename Right> | |
17 | struct difference : binary_parser<Left, Right, difference<Left, Right>> | |
18 | { | |
19 | typedef binary_parser<Left, Right, difference<Left, Right>> base_type; | |
20 | static bool const handles_container = Left::handles_container; | |
21 | ||
22 | difference(Left const& left, Right const& right) | |
23 | : base_type(left, right) {} | |
24 | ||
25 | template <typename Iterator, typename Context | |
26 | , typename RContext, typename Attribute> | |
27 | bool parse(Iterator& first, Iterator const& last | |
28 | , Context const& context, RContext& rcontext, Attribute& attr) const | |
29 | { | |
30 | // Try Right first | |
31 | Iterator start = first; | |
32 | if (this->right.parse(first, last, context, rcontext, unused)) | |
33 | { | |
34 | // Right succeeds, we fail. | |
35 | first = start; | |
36 | return false; | |
37 | } | |
38 | // Right fails, now try Left | |
39 | return this->left.parse(first, last, context, rcontext, attr); | |
40 | } | |
41 | ||
42 | template <typename Left_, typename Right_> | |
43 | difference<Left_, Right_> | |
44 | make(Left_ const& left, Right_ const& right) const | |
45 | { | |
46 | return { left, right }; | |
47 | } | |
48 | }; | |
49 | ||
50 | template <typename Left, typename Right> | |
51 | inline difference< | |
52 | typename extension::as_parser<Left>::value_type | |
53 | , typename extension::as_parser<Right>::value_type> | |
54 | operator-(Left const& left, Right const& right) | |
55 | { | |
56 | return { as_parser(left), as_parser(right) }; | |
57 | } | |
58 | }}} | |
59 | ||
60 | namespace boost { namespace spirit { namespace x3 { namespace traits | |
61 | { | |
62 | template <typename Left, typename Right, typename Context> | |
63 | struct attribute_of<x3::difference<Left, Right>, Context> | |
64 | : attribute_of<Left, Context> {}; | |
65 | ||
66 | template <typename Left, typename Right, typename Context> | |
67 | struct has_attribute<x3::difference<Left, Right>, Context> | |
68 | : has_attribute<Left, Context> {}; | |
69 | }}}} | |
70 | ||
71 | #endif |