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(BOOST_SPIRIT_X3_NEGATED_CHAR_PARSER_APR_16_2006_0906AM)
8 #define BOOST_SPIRIT_X3_NEGATED_CHAR_PARSER_APR_16_2006_0906AM
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/char/char_parser.hpp>
14 namespace boost { namespace spirit { namespace x3
16 ///////////////////////////////////////////////////////////////////////////
17 // negated_char_parser handles ~cp expressions (cp is a char_parser)
18 ///////////////////////////////////////////////////////////////////////////
19 template <typename Positive>
20 struct negated_char_parser :
21 char_parser<negated_char_parser<Positive>>
23 negated_char_parser(Positive const& positive)
24 : positive(positive) {}
26 template <typename CharParam, typename Context>
27 bool test(CharParam ch, Context const& context) const
29 return !positive.test(ch, context);
35 template <typename Positive>
36 inline negated_char_parser<Positive>
37 operator~(char_parser<Positive> const& cp)
39 return { cp.derived() };
42 template <typename Positive>
43 inline Positive const&
44 operator~(negated_char_parser<Positive> const& cp)
50 namespace boost { namespace spirit { namespace x3 { namespace traits
52 template <typename Positive, typename Context>
53 struct attribute_of<x3::negated_char_parser<Positive>, Context>
54 : attribute_of<Positive, Context> {};
56 template <typename Positive, typename Context>
57 struct has_attribute<x3::negated_char_parser<Positive>, Context>
58 : has_attribute<Positive, Context> {};