| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 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 | #ifndef BOOST_SPIRIT_QI_OPERATOR_AND_PREDICATE_HPP |
| 8 | #define BOOST_SPIRIT_QI_OPERATOR_AND_PREDICATE_HPP |
| 9 | |
| 10 | #if defined(_MSC_VER) |
| 11 | #pragma once |
| 12 | #endif |
| 13 | |
| 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/info.hpp> |
| 19 | #include <boost/spirit/home/support/has_semantic_action.hpp> |
| 20 | #include <boost/spirit/home/support/handles_container.hpp> |
| 21 | #include <boost/fusion/include/at.hpp> |
| 22 | #include <boost/proto/operators.hpp> |
| 23 | #include <boost/proto/tags.hpp> |
| 24 | |
| 25 | namespace boost { namespace spirit |
| 26 | { |
| 27 | /////////////////////////////////////////////////////////////////////////// |
| 28 | // Enablers |
| 29 | /////////////////////////////////////////////////////////////////////////// |
| 30 | template <> |
| 31 | struct use_operator<qi::domain, proto::tag::address_of> // enables &p |
| 32 | : mpl::true_ {}; |
| 33 | }} |
| 34 | |
| 35 | namespace boost { namespace spirit { namespace qi |
| 36 | { |
| 37 | template <typename Subject> |
| 38 | struct and_predicate : unary_parser<and_predicate<Subject> > |
| 39 | { |
| 40 | typedef Subject subject_type; |
| 41 | |
| 42 | template <typename Context, typename Iterator> |
| 43 | struct attribute |
| 44 | { |
| 45 | typedef unused_type type; |
| 46 | }; |
| 47 | |
| 48 | and_predicate(Subject const& subject_) |
| 49 | : subject(subject_) {} |
| 50 | |
| 51 | template <typename Iterator, typename Context |
| 52 | , typename Skipper, typename Attribute> |
| 53 | bool parse(Iterator& first, Iterator const& last |
| 54 | , Context& context, Skipper const& skipper |
| 55 | , Attribute& /*attr*/) const |
| 56 | { |
| 57 | Iterator i = first; |
| 58 | return subject.parse(i, last, context, skipper, unused); |
| 59 | } |
| 60 | |
| 61 | template <typename Context> |
| 62 | info what(Context& context) const |
| 63 | { |
| 64 | return info("and-predicate" , subject.what(context)); |
| 65 | } |
| 66 | |
| 67 | Subject subject; |
| 68 | }; |
| 69 | |
| 70 | /////////////////////////////////////////////////////////////////////////// |
| 71 | // Parser generators: make_xxx function (objects) |
| 72 | /////////////////////////////////////////////////////////////////////////// |
| 73 | template <typename Elements, typename Modifiers> |
| 74 | struct make_composite<proto::tag::address_of, Elements, Modifiers> |
| 75 | : make_unary_composite<Elements, and_predicate> |
| 76 | {}; |
| 77 | }}} |
| 78 | |
| 79 | namespace boost { namespace spirit { namespace traits |
| 80 | { |
| 81 | /////////////////////////////////////////////////////////////////////////// |
| 82 | template <typename Subject> |
| 83 | struct has_semantic_action<qi::and_predicate<Subject> > |
| 84 | : unary_has_semantic_action<Subject> {}; |
| 85 | |
| 86 | /////////////////////////////////////////////////////////////////////////// |
| 87 | template <typename Subject, typename Attribute, typename Context |
| 88 | , typename Iterator> |
| 89 | struct handles_container<qi::and_predicate<Subject>, Attribute, Context |
| 90 | , Iterator> |
| 91 | : unary_handles_container<Subject, Attribute, Context, Iterator> {}; |
| 92 | }}} |
| 93 | |
| 94 | #endif |
| 95 | |