1 /*=============================================================================
2 Copyright (c) 2001-2007 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_FEB_11_2007_1250PM)
8 #define SPIRIT_DIFFERENCE_FEB_11_2007_1250PM
10 #include <boost/spirit/home/qi/domain.hpp>
11 #include <boost/spirit/home/support/component.hpp>
12 #include <boost/spirit/home/support/attribute_of.hpp>
15 namespace boost
{ namespace spirit
{ namespace qi
19 template <typename Component
, typename Context
, typename Iterator
>
23 result_of::left
<Component
>::type
28 qi::domain
, left_type
, Context
, Iterator
>::type
34 , typename Iterator
, typename Context
35 , typename Skipper
, typename Attribute
>
37 Component
const& component
38 , Iterator
& first
, Iterator
const& last
39 , Context
& context
, Skipper
const& skipper
43 result_of::left
<Component
>::type::director
47 result_of::right
<Component
>::type::director
50 // Unlike classic Spirit, with this version of difference, the rule
51 // lit("policeman") - "police" will always fail to match.
53 // Spirit2 does not count the matching chars while parsing and
54 // there is no reliable and fast way to check if the LHS matches
58 Iterator start
= first
;
59 if (rdirector::parse(spirit::right(component
), first
, last
, context
,
62 // RHS succeeds, we fail.
66 // RHS fails, now try LHS
67 return ldirector::parse(spirit::left(component
), first
, last
,
68 context
, skipper
, attr
);
71 template <typename Component
, typename Context
>
72 static std::string
what(Component
const& component
, Context
const& ctx
)
74 std::string result
= "difference[";
77 result_of::left
<Component
>::type::director
81 result_of::right
<Component
>::type::director
84 result
+= ldirector::what(spirit::left(component
), ctx
);
86 result
+= rdirector::what(spirit::right(component
), ctx
);