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_DIRECTIVE_HOLD_HPP 8 #define BOOST_SPIRIT_QI_DIRECTIVE_HOLD_HPP 9 10 #if defined(_MSC_VER) 11 #pragma once 12 #endif 13 14 #include <boost/spirit/home/qi/meta_compiler.hpp> 15 #include <boost/spirit/home/qi/skip_over.hpp> 16 #include <boost/spirit/home/qi/parser.hpp> 17 #include <boost/spirit/home/support/attributes.hpp> 18 #include <boost/spirit/home/support/info.hpp> 19 #include <boost/spirit/home/support/common_terminals.hpp> 20 #include <boost/spirit/home/support/unused.hpp> 21 #include <boost/spirit/home/support/has_semantic_action.hpp> 22 #include <boost/spirit/home/support/handles_container.hpp> 23 24 namespace boost { namespace spirit 25 { 26 /////////////////////////////////////////////////////////////////////////// 27 // Enablers 28 /////////////////////////////////////////////////////////////////////////// 29 template <> 30 struct use_directive<qi::domain, tag::hold> // enables hold 31 : mpl::true_ {}; 32 }} 33 34 namespace boost { namespace spirit { namespace qi 35 { 36 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS 37 using spirit::hold; 38 #endif 39 using spirit::hold_type; 40 41 template <typename Subject> 42 struct hold_directive : unary_parser<hold_directive<Subject> > 43 { 44 typedef Subject subject_type; hold_directiveboost::spirit::qi::hold_directive45 hold_directive(Subject const& subject_) 46 : subject(subject_) {} 47 48 template <typename Context, typename Iterator> 49 struct attribute 50 { 51 typedef typename 52 traits::attribute_of<subject_type, Context, Iterator>::type 53 type; 54 }; 55 56 template <typename Iterator, typename Context 57 , typename Skipper, typename Attribute> parseboost::spirit::qi::hold_directive58 bool parse(Iterator& first, Iterator const& last 59 , Context& context, Skipper const& skipper, Attribute& attr_) const 60 { 61 Attribute copy(attr_); 62 if (subject.parse(first, last, context, skipper, copy)) 63 { 64 traits::swap_impl(copy, attr_); 65 return true; 66 } 67 return false; 68 } 69 70 template <typename Context> whatboost::spirit::qi::hold_directive71 info what(Context& context) const 72 { 73 return info("hold", subject.what(context)); 74 75 } 76 77 Subject subject; 78 }; 79 80 /////////////////////////////////////////////////////////////////////////// 81 // Parser generators: make_xxx function (objects) 82 /////////////////////////////////////////////////////////////////////////// 83 template <typename Subject, typename Modifiers> 84 struct make_directive<tag::hold, Subject, Modifiers> 85 { 86 typedef hold_directive<Subject> result_type; operator ()boost::spirit::qi::make_directive87 result_type operator()(unused_type, Subject const& subject, unused_type) const 88 { 89 return result_type(subject); 90 } 91 }; 92 }}} 93 94 namespace boost { namespace spirit { namespace traits 95 { 96 /////////////////////////////////////////////////////////////////////////// 97 template <typename Subject> 98 struct has_semantic_action<qi::hold_directive<Subject> > 99 : unary_has_semantic_action<Subject> {}; 100 101 /////////////////////////////////////////////////////////////////////////// 102 template <typename Subject, typename Attribute, typename Context 103 , typename Iterator> 104 struct handles_container<qi::hold_directive<Subject>, Attribute 105 , Context, Iterator> 106 : unary_handles_container<Subject, Attribute, Context, Iterator> {}; 107 }}} 108 109 #endif 110