1 /*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
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_DIFFERENCE_FEBRUARY_11_2007_1250PM)
8 #define SPIRIT_DIFFERENCE_FEBRUARY_11_2007_1250PM
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>
14 namespace boost { namespace spirit { namespace x3
16 template <typename Left, typename Right>
17 struct difference : binary_parser<Left, Right, difference<Left, Right>>
19 typedef binary_parser<Left, Right, difference<Left, Right>> base_type;
20 static bool const handles_container = Left::handles_container;
22 difference(Left const& left, Right const& right)
23 : base_type(left, right) {}
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
31 Iterator start = first;
32 if (this->right.parse(first, last, context, rcontext, unused))
34 // Right succeeds, we fail.
38 // Right fails, now try Left
39 return this->left.parse(first, last, context, rcontext, attr);
42 template <typename Left_, typename Right_>
43 difference<Left_, Right_>
44 make(Left_ const& left, Right_ const& right) const
46 return { left, right };
50 template <typename Left, typename Right>
52 typename extension::as_parser<Left>::value_type
53 , typename extension::as_parser<Right>::value_type>
54 operator-(Left const& left, Right const& right)
56 return { as_parser(left), as_parser(right) };
60 namespace boost { namespace spirit { namespace x3 { namespace traits
62 template <typename Left, typename Right, typename Context>
63 struct attribute_of<x3::difference<Left, Right>, Context>
64 : attribute_of<Left, Context> {};
66 template <typename Left, typename Right, typename Context>
67 struct has_attribute<x3::difference<Left, Right>, Context>
68 : has_attribute<Left, Context> {};