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_OMIT_HPP 8 #define BOOST_SPIRIT_QI_DIRECTIVE_OMIT_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/unused.hpp> 18 #include <boost/spirit/home/support/info.hpp> 19 #include <boost/spirit/home/support/common_terminals.hpp> 20 #include <boost/spirit/home/support/has_semantic_action.hpp> 21 #include <boost/spirit/home/support/handles_container.hpp> 22 23 namespace boost { namespace spirit 24 { 25 /////////////////////////////////////////////////////////////////////////// 26 // Enablers 27 /////////////////////////////////////////////////////////////////////////// 28 template <> 29 struct use_directive<qi::domain, tag::omit> // enables omit 30 : mpl::true_ {}; 31 }} 32 33 namespace boost { namespace spirit { namespace qi 34 { 35 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS 36 using spirit::omit; 37 #endif 38 using spirit::omit_type; 39 40 /////////////////////////////////////////////////////////////////////////// 41 // omit_directive forces the attribute of subject parser 42 // to be unused_type 43 /////////////////////////////////////////////////////////////////////////// 44 template <typename Subject> 45 struct omit_directive : unary_parser<omit_directive<Subject> > 46 { 47 typedef Subject subject_type; omit_directiveboost::spirit::qi::omit_directive48 omit_directive(Subject const& subject_) 49 : subject(subject_) {} 50 51 template <typename Context, typename Iterator> 52 struct attribute 53 { 54 typedef unused_type type; 55 }; 56 57 template <typename Iterator, typename Context 58 , typename Skipper, typename Attribute> parseboost::spirit::qi::omit_directive59 bool parse(Iterator& first, Iterator const& last 60 , Context& context, Skipper const& skipper, Attribute& attr_) const 61 { 62 return subject.parse(first, last, context, skipper, attr_); 63 } 64 65 template <typename Context> whatboost::spirit::qi::omit_directive66 info what(Context& context) const 67 { 68 return info("omit", subject.what(context)); 69 } 70 71 Subject subject; 72 73 // silence MSVC warning C4512: assignment operator could not be generated 74 BOOST_DELETED_FUNCTION(omit_directive& operator= (omit_directive const&)) 75 }; 76 77 /////////////////////////////////////////////////////////////////////////// 78 // Parser generators: make_xxx function (objects) 79 /////////////////////////////////////////////////////////////////////////// 80 template <typename Subject, typename Modifiers> 81 struct make_directive<tag::omit, Subject, Modifiers> 82 { 83 typedef omit_directive<Subject> result_type; operator ()boost::spirit::qi::make_directive84 result_type operator()(unused_type, Subject const& subject, unused_type) const 85 { 86 return result_type(subject); 87 } 88 }; 89 }}} 90 91 namespace boost { namespace spirit { namespace traits 92 { 93 /////////////////////////////////////////////////////////////////////////// 94 template <typename Subject> 95 struct has_semantic_action<qi::omit_directive<Subject> > 96 : mpl::false_ {}; 97 98 /////////////////////////////////////////////////////////////////////////// 99 template <typename Subject, typename Attribute, typename Context 100 , typename Iterator> 101 struct handles_container<qi::omit_directive<Subject>, Attribute 102 , Context, Iterator> 103 : unary_handles_container<Subject, Attribute, Context, Iterator> {}; 104 }}} 105 106 #endif 107