1 /*=============================================================================
2 Copyright (c) 2001-2011 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 #ifndef BOOST_SPIRIT_QI_OPERATOR_NOT_PREDICATE_HPP
8 #define BOOST_SPIRIT_QI_OPERATOR_NOT_PREDICATE_HPP
14 #include <boost/spirit/home/qi/domain.hpp>
15 #include <boost/spirit/home/qi/meta_compiler.hpp>
16 #include <boost/spirit/home/qi/parser.hpp>
17 #include <boost/spirit/home/qi/detail/attributes.hpp>
18 #include <boost/spirit/home/support/has_semantic_action.hpp>
19 #include <boost/spirit/home/support/handles_container.hpp>
20 #include <boost/spirit/home/support/info.hpp>
21 #include <boost/proto/operators.hpp>
22 #include <boost/proto/tags.hpp>
24 namespace boost { namespace spirit
26 ///////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////
30 struct use_operator<qi::domain, proto::tag::logical_not> // enables !p
34 namespace boost { namespace spirit { namespace qi
36 template <typename Subject>
37 struct not_predicate : unary_parser<not_predicate<Subject> >
39 typedef Subject subject_type;
41 template <typename Context, typename Iterator>
44 typedef unused_type type;
47 not_predicate(Subject const& subject_)
48 : subject(subject_) {}
50 template <typename Iterator, typename Context
51 , typename Skipper, typename Attribute>
52 bool parse(Iterator& first, Iterator const& last
53 , Context& context, Skipper const& skipper
54 , Attribute& /*attr*/) const
57 return !subject.parse(i, last, context, skipper, unused);
60 template <typename Context>
61 info what(Context& context) const
63 return info("not-predicate", subject.what(context));
69 ///////////////////////////////////////////////////////////////////////////
70 // Parser generators: make_xxx function (objects)
71 ///////////////////////////////////////////////////////////////////////////
72 template <typename Elements, typename Modifiers>
73 struct make_composite<proto::tag::logical_not, Elements, Modifiers>
74 : make_unary_composite<Elements, not_predicate>
78 namespace boost { namespace spirit { namespace traits
80 ///////////////////////////////////////////////////////////////////////////
81 template <typename Subject>
82 struct has_semantic_action<qi::not_predicate<Subject> >
83 : unary_has_semantic_action<Subject> {};
85 ///////////////////////////////////////////////////////////////////////////
86 template <typename Subject, typename Attribute, typename Context
88 struct handles_container<qi::not_predicate<Subject>, Attribute
90 : unary_handles_container<Subject, Attribute, Context, Iterator> {};