File indexing completed on 2025-01-19 09:47:44
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_SPIRIT_QI_DIRECTIVE_SKIP_HPP
0008 #define BOOST_SPIRIT_QI_DIRECTIVE_SKIP_HPP
0009
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013
0014 #include <boost/spirit/home/qi/meta_compiler.hpp>
0015 #include <boost/spirit/home/qi/parser.hpp>
0016 #include <boost/spirit/home/qi/auxiliary/lazy.hpp>
0017 #include <boost/spirit/home/qi/operator/kleene.hpp>
0018 #include <boost/spirit/home/qi/directive/lexeme.hpp>
0019 #include <boost/spirit/home/qi/skip_over.hpp>
0020 #include <boost/spirit/home/qi/detail/unused_skipper.hpp>
0021 #include <boost/spirit/home/support/container.hpp>
0022 #include <boost/spirit/home/support/common_terminals.hpp>
0023 #include <boost/spirit/home/qi/detail/attributes.hpp>
0024 #include <boost/spirit/home/support/info.hpp>
0025 #include <boost/spirit/home/support/has_semantic_action.hpp>
0026 #include <boost/spirit/home/support/handles_container.hpp>
0027 #include <boost/fusion/include/at.hpp>
0028 #include <boost/fusion/include/vector.hpp>
0029 #include <boost/utility/enable_if.hpp>
0030
0031 namespace boost { namespace spirit
0032 {
0033
0034
0035
0036 template <>
0037 struct use_directive<qi::domain, tag::skip>
0038 : mpl::true_ {};
0039
0040 template <typename T>
0041 struct use_directive<qi::domain
0042 , terminal_ex<tag::skip
0043 , fusion::vector1<T> >
0044 > : boost::spirit::traits::matches<qi::domain, T> {};
0045
0046 template <>
0047 struct use_lazy_directive<
0048 qi::domain
0049 , tag::skip
0050 , 1
0051 > : mpl::true_ {};
0052 }}
0053
0054 namespace boost { namespace spirit { namespace qi
0055 {
0056 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
0057 using spirit::skip;
0058 #endif
0059 using spirit::skip_type;
0060
0061 template <typename Subject>
0062 struct reskip_parser : unary_parser<reskip_parser<Subject> >
0063 {
0064 typedef Subject subject_type;
0065
0066 template <typename Context, typename Iterator>
0067 struct attribute
0068 {
0069 typedef typename
0070 traits::attribute_of<Subject, Context, Iterator>::type
0071 type;
0072 };
0073
0074 reskip_parser(Subject const& subject_)
0075 : subject(subject_) {}
0076
0077 template <typename Iterator, typename Context
0078 , typename Skipper, typename Attribute>
0079 typename enable_if<detail::is_unused_skipper<Skipper>, bool>::type
0080 parse(Iterator& first, Iterator const& last
0081 , Context& context, Skipper const& u
0082 , Attribute& attr_) const
0083 {
0084 return subject.parse(first, last, context
0085 , detail::get_skipper(u), attr_);
0086 }
0087 template <typename Iterator, typename Context
0088 , typename Skipper, typename Attribute>
0089 typename disable_if<detail::is_unused_skipper<Skipper>, bool>::type
0090 parse(Iterator& first, Iterator const& last
0091 , Context& context, Skipper const& skipper
0092 , Attribute& attr_) const
0093 {
0094 return subject.parse(first, last, context
0095 , skipper, attr_);
0096 }
0097
0098 template <typename Context>
0099 info what(Context& context) const
0100 {
0101 return info("skip", subject.what(context));
0102 }
0103
0104 Subject subject;
0105 };
0106
0107 template <typename Subject, typename Skipper>
0108 struct skip_parser : unary_parser<skip_parser<Subject, Skipper> >
0109 {
0110 typedef Subject subject_type;
0111 typedef Skipper skipper_type;
0112
0113 template <typename Context, typename Iterator>
0114 struct attribute
0115 {
0116 typedef typename
0117 traits::attribute_of<Subject, Context, Iterator>::type
0118 type;
0119 };
0120
0121 skip_parser(Subject const& subject_, Skipper const& skipper_)
0122 : subject(subject_), skipper(skipper_) {}
0123
0124 template <typename Iterator, typename Context
0125 , typename Skipper_, typename Attribute>
0126 bool parse(Iterator& first, Iterator const& last
0127 , Context& context, Skipper_ const&
0128 , Attribute& attr_) const
0129 {
0130 return subject.parse(first, last, context, skipper, attr_);
0131 }
0132
0133 template <typename Context>
0134 info what(Context& context) const
0135 {
0136 return info("skip", subject.what(context));
0137 }
0138
0139 Subject subject;
0140 Skipper skipper;
0141 };
0142
0143
0144
0145
0146 template <typename Subject, typename Modifiers>
0147 struct make_directive<tag::skip, Subject, Modifiers>
0148 {
0149 typedef reskip_parser<Subject> result_type;
0150 result_type operator()(unused_type, Subject const& subject, unused_type) const
0151 {
0152 return result_type(subject);
0153 }
0154 };
0155
0156 template <typename Skipper, typename Subject, typename Modifiers>
0157 struct make_directive<
0158 terminal_ex<tag::skip, fusion::vector1<Skipper> >, Subject, Modifiers>
0159 {
0160 typedef typename
0161 result_of::compile<qi::domain, Skipper, Modifiers>::type
0162 skipper_type;
0163
0164 typedef skip_parser<Subject, skipper_type> result_type;
0165
0166 template <typename Terminal>
0167 result_type operator()(Terminal const& term, Subject const& subject
0168 , Modifiers const& modifiers) const
0169 {
0170 return result_type(subject
0171 , compile<qi::domain>(fusion::at_c<0>(term.args), modifiers));
0172 }
0173 };
0174
0175 }}}
0176
0177 namespace boost { namespace spirit { namespace traits
0178 {
0179
0180 template <typename Subject>
0181 struct has_semantic_action<qi::reskip_parser<Subject> >
0182 : unary_has_semantic_action<Subject> {};
0183
0184 template <typename Subject, typename Skipper>
0185 struct has_semantic_action<qi::skip_parser<Subject, Skipper> >
0186 : unary_has_semantic_action<Subject> {};
0187
0188
0189 template <typename Subject, typename Attribute, typename Context
0190 , typename Iterator>
0191 struct handles_container<qi::reskip_parser<Subject>, Attribute
0192 , Context, Iterator>
0193 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
0194
0195 template <typename Subject, typename Skipper, typename Attribute
0196 , typename Context, typename Iterator>
0197 struct handles_container<qi::skip_parser<Subject, Skipper>, Attribute
0198 , Context, Iterator>
0199 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
0200 }}}
0201
0202 #endif