]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2014 Joel de Guzman | |
3 | ||
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 | |
9 | ||
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> | |
13 | ||
14 | namespace boost { namespace spirit { namespace x3 | |
15 | { | |
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>> | |
22 | { | |
23 | negated_char_parser(Positive const& positive) | |
24 | : positive(positive) {} | |
25 | ||
26 | template <typename CharParam, typename Context> | |
27 | bool test(CharParam ch, Context const& context) const | |
28 | { | |
29 | return !positive.test(ch, context); | |
30 | } | |
31 | ||
32 | Positive positive; | |
33 | }; | |
34 | ||
35 | template <typename Positive> | |
36 | inline negated_char_parser<Positive> | |
37 | operator~(char_parser<Positive> const& cp) | |
38 | { | |
39 | return { cp.derived() }; | |
40 | } | |
41 | ||
42 | template <typename Positive> | |
43 | inline Positive const& | |
44 | operator~(negated_char_parser<Positive> const& cp) | |
45 | { | |
46 | return cp.positive; | |
47 | } | |
48 | }}} | |
49 | ||
50 | namespace boost { namespace spirit { namespace x3 { namespace traits | |
51 | { | |
52 | template <typename Positive, typename Context> | |
53 | struct attribute_of<x3::negated_char_parser<Positive>, Context> | |
54 | : attribute_of<Positive, Context> {}; | |
55 | ||
56 | template <typename Positive, typename Context> | |
57 | struct has_attribute<x3::negated_char_parser<Positive>, Context> | |
58 | : has_attribute<Positive, Context> {}; | |
59 | }}}} | |
60 | ||
61 | #endif |