Chris@102
|
1 /*=============================================================================
|
Chris@102
|
2 Copyright (c) 2001-2014 Joel de Guzman
|
Chris@102
|
3
|
Chris@102
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@102
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
6 =============================================================================*/
|
Chris@102
|
7 #if !defined(SPIRIT_DIFFERENCE_FEBRUARY_11_2007_1250PM)
|
Chris@102
|
8 #define SPIRIT_DIFFERENCE_FEBRUARY_11_2007_1250PM
|
Chris@102
|
9
|
Chris@102
|
10 #if defined(_MSC_VER)
|
Chris@102
|
11 #pragma once
|
Chris@102
|
12 #endif
|
Chris@102
|
13
|
Chris@102
|
14 #include <boost/spirit/home/x3/support/traits/attribute_of.hpp>
|
Chris@102
|
15 #include <boost/spirit/home/x3/support/traits/has_attribute.hpp>
|
Chris@102
|
16 #include <boost/spirit/home/x3/core/parser.hpp>
|
Chris@102
|
17
|
Chris@102
|
18 namespace boost { namespace spirit { namespace x3
|
Chris@102
|
19 {
|
Chris@102
|
20 template <typename Left, typename Right>
|
Chris@102
|
21 struct difference : binary_parser<Left, Right, difference<Left, Right>>
|
Chris@102
|
22 {
|
Chris@102
|
23 typedef binary_parser<Left, Right, difference<Left, Right>> base_type;
|
Chris@102
|
24 static bool const handles_container = Left::handles_container;
|
Chris@102
|
25
|
Chris@102
|
26 difference(Left const& left, Right const& right)
|
Chris@102
|
27 : base_type(left, right) {}
|
Chris@102
|
28
|
Chris@102
|
29 template <typename Iterator, typename Context
|
Chris@102
|
30 , typename RContext, typename Attribute>
|
Chris@102
|
31 bool parse(Iterator& first, Iterator const& last
|
Chris@102
|
32 , Context const& context, RContext& rcontext, Attribute& attr) const
|
Chris@102
|
33 {
|
Chris@102
|
34 // Try Right first
|
Chris@102
|
35 Iterator start = first;
|
Chris@102
|
36 if (this->right.parse(first, last, context, rcontext, unused))
|
Chris@102
|
37 {
|
Chris@102
|
38 // Right succeeds, we fail.
|
Chris@102
|
39 first = start;
|
Chris@102
|
40 return false;
|
Chris@102
|
41 }
|
Chris@102
|
42 // Right fails, now try Left
|
Chris@102
|
43 return this->left.parse(first, last, context, rcontext, attr);
|
Chris@102
|
44 }
|
Chris@102
|
45
|
Chris@102
|
46 template <typename Left_, typename Right_>
|
Chris@102
|
47 difference<Left_, Right_>
|
Chris@102
|
48 make(Left_ const& left, Right_ const& right) const
|
Chris@102
|
49 {
|
Chris@102
|
50 return difference<Left_, Right_>(left, right);
|
Chris@102
|
51 }
|
Chris@102
|
52 };
|
Chris@102
|
53
|
Chris@102
|
54 template <typename Left, typename Right>
|
Chris@102
|
55 inline difference<
|
Chris@102
|
56 typename extension::as_parser<Left>::value_type
|
Chris@102
|
57 , typename extension::as_parser<Right>::value_type>
|
Chris@102
|
58 operator-(Left const& left, Right const& right)
|
Chris@102
|
59 {
|
Chris@102
|
60 return {as_parser(left), as_parser(right)};
|
Chris@102
|
61 }
|
Chris@102
|
62 }}}
|
Chris@102
|
63
|
Chris@102
|
64 namespace boost { namespace spirit { namespace x3 { namespace traits
|
Chris@102
|
65 {
|
Chris@102
|
66 template <typename Left, typename Right, typename Context>
|
Chris@102
|
67 struct attribute_of<x3::difference<Left, Right>, Context>
|
Chris@102
|
68 : attribute_of<Left, Context> {};
|
Chris@102
|
69
|
Chris@102
|
70 template <typename Left, typename Right, typename Context>
|
Chris@102
|
71 struct has_attribute<x3::difference<Left, Right>, Context>
|
Chris@102
|
72 : has_attribute<Left, Context> {};
|
Chris@102
|
73 }}}}
|
Chris@102
|
74
|
Chris@102
|
75 #endif
|