Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:01:58

0001 /*=============================================================================
0002     Copyright (c) 2002-2003 Joel de Guzman
0003     Copyright (c) 2002-2003 Hartmut Kaiser
0004     Copyright (c) 2003 Martin Wille
0005     http://spirit.sourceforge.net/
0006 
0007   Distributed under the Boost Software License, Version 1.0. (See accompanying
0008   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 =============================================================================*/
0010 #if !defined(BOOST_SPIRIT_PARSER_TRAITS_HPP)
0011 #define BOOST_SPIRIT_PARSER_TRAITS_HPP
0012 
0013 #include <boost/type_traits/is_base_and_derived.hpp>
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/spirit/home/classic/namespace.hpp>
0017 #include <boost/spirit/home/classic/core/parser.hpp>
0018 #include <boost/spirit/home/classic/meta/impl/parser_traits.ipp>
0019 
0020 ///////////////////////////////////////////////////////////////////////////////
0021 namespace boost { namespace spirit {
0022 
0023 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0024 
0025 ///////////////////////////////////////////////////////////////////////////////
0026 //
0027 //  Parser traits templates
0028 //
0029 //      Used to determine the type and several other characteristics of a given
0030 //      parser type.
0031 //
0032 ///////////////////////////////////////////////////////////////////////////////
0033 
0034 ///////////////////////////////////////////////////////////////////////////////
0035 //
0036 // The is_parser traits template can be used to tell wether a given
0037 // class is a parser.
0038 //
0039 ///////////////////////////////////////////////////////////////////////////////
0040 template <typename T>
0041 struct is_parser
0042 {
0043     BOOST_STATIC_CONSTANT(bool, value =
0044         (::boost::is_base_and_derived<parser<T>, T>::value));
0045 
0046 //  [JDG 2/3/03] simplified implementation by
0047 //  using boost::is_base_and_derived
0048 };
0049 
0050 ///////////////////////////////////////////////////////////////////////////////
0051 //
0052 //  The is_unary_composite traits template can be used to tell if a given
0053 //  parser is a unary parser as for instance kleene_star or optional.
0054 //
0055 ///////////////////////////////////////////////////////////////////////////////
0056 template <typename UnaryT>
0057 struct is_unary_composite {
0058 
0059     BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<
0060         typename UnaryT::parser_category_t, unary_parser_category>::value));
0061 };
0062 
0063 ///////////////////////////////////////////////////////////////////////////////
0064 //
0065 //  The is_acction_parser traits template can be used to tell if a given
0066 //  parser is a action parser, i.e. it is a composite consisting of a
0067 //  auxiliary parser and an attached semantic action.
0068 //
0069 ///////////////////////////////////////////////////////////////////////////////
0070 template <typename ActionT>
0071 struct is_action_parser {
0072 
0073     BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<
0074         typename ActionT::parser_category_t, action_parser_category>::value));
0075 };
0076 
0077 ///////////////////////////////////////////////////////////////////////////////
0078 //
0079 //  The is_binary_composite traits template can be used to tell if a given
0080 //  parser is a binary parser as for instance sequence or difference.
0081 //
0082 ///////////////////////////////////////////////////////////////////////////////
0083 template <typename BinaryT>
0084 struct is_binary_composite {
0085 
0086     BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<
0087         typename BinaryT::parser_category_t, binary_parser_category>::value));
0088 };
0089 
0090 ///////////////////////////////////////////////////////////////////////////////
0091 //
0092 //  The is_composite_parser traits template can be used to tell if a given
0093 //  parser is a unary or a binary parser composite type.
0094 //
0095 ///////////////////////////////////////////////////////////////////////////////
0096 template <typename CompositeT>
0097 struct is_composite_parser {
0098 
0099     BOOST_STATIC_CONSTANT(bool, value = (
0100         ::BOOST_SPIRIT_CLASSIC_NS::is_unary_composite<CompositeT>::value ||
0101         ::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<CompositeT>::value));
0102 };
0103 
0104 ///////////////////////////////////////////////////////////////////////////////
0105 template <typename ParserT>
0106 struct is_alternative {
0107 
0108     BOOST_STATIC_CONSTANT(bool, value = (
0109         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_alternative));
0110 };
0111 
0112 template <typename ParserT>
0113 struct is_sequence {
0114 
0115     BOOST_STATIC_CONSTANT(bool, value = (
0116         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_sequence));
0117 };
0118 
0119 template <typename ParserT>
0120 struct is_sequential_or {
0121 
0122     BOOST_STATIC_CONSTANT(bool, value = (
0123         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_sequential_or));
0124 };
0125 
0126 template <typename ParserT>
0127 struct is_intersection {
0128 
0129     BOOST_STATIC_CONSTANT(bool, value = (
0130         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_intersection));
0131 };
0132 
0133 template <typename ParserT>
0134 struct is_difference {
0135 
0136     BOOST_STATIC_CONSTANT(bool, value = (
0137         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_difference));
0138 };
0139 
0140 template <typename ParserT>
0141 struct is_exclusive_or {
0142 
0143     BOOST_STATIC_CONSTANT(bool, value = (
0144         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_exclusive_or));
0145 };
0146 
0147 template <typename ParserT>
0148 struct is_optional {
0149 
0150     BOOST_STATIC_CONSTANT(bool, value = (
0151         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_optional));
0152 };
0153 
0154 template <typename ParserT>
0155 struct is_kleene_star {
0156 
0157     BOOST_STATIC_CONSTANT(bool, value = (
0158         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_kleene_star));
0159 };
0160 
0161 template <typename ParserT>
0162 struct is_positive {
0163 
0164     BOOST_STATIC_CONSTANT(bool, value = (
0165         ::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_positive));
0166 };
0167 
0168 ///////////////////////////////////////////////////////////////////////////////
0169 //
0170 //  Parser extraction templates
0171 //
0172 ///////////////////////////////////////////////////////////////////////////////
0173 
0174 ///////////////////////////////////////////////////////////////////////////////
0175 //
0176 //  The unary_subject template can be used to return the type of the
0177 //  parser used as the subject of an unary parser.
0178 //  If the parser under inspection is not an unary type parser the compilation
0179 //  will fail.
0180 //
0181 ///////////////////////////////////////////////////////////////////////////////
0182 template <typename UnaryT>
0183 struct unary_subject {
0184 
0185     BOOST_STATIC_ASSERT(BOOST_SPIRIT_CLASSIC_NS::is_unary_composite<UnaryT>::value);
0186     typedef typename UnaryT::subject_t type;
0187 };
0188 
0189 ///////////////////////////////////////////////////////////////////////////////
0190 //
0191 //  The get_unary_subject template function returns the parser object, which
0192 //  is used as the subject of an unary parser.
0193 //  If the parser under inspection is not an unary type parser the compilation
0194 //  will fail.
0195 //
0196 ///////////////////////////////////////////////////////////////////////////////
0197 template <typename UnaryT>
0198 inline typename unary_subject<UnaryT>::type const &
0199 get_unary_subject(UnaryT const &unary_)
0200 {
0201     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_unary_composite<UnaryT>::value);
0202     return unary_.subject();
0203 }
0204 
0205 ///////////////////////////////////////////////////////////////////////////////
0206 //
0207 //  The binary_left_subject and binary_right_subject templates can be used to
0208 //  return the types of the parsers used as the left and right subject of an
0209 //  binary parser.
0210 //  If the parser under inspection is not a binary type parser the compilation
0211 //  will fail.
0212 //
0213 ///////////////////////////////////////////////////////////////////////////////
0214 template <typename BinaryT>
0215 struct binary_left_subject {
0216 
0217     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
0218     typedef typename BinaryT::left_t type;
0219 };
0220 
0221 template <typename BinaryT>
0222 struct binary_right_subject {
0223 
0224     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
0225     typedef typename BinaryT::right_t type;
0226 };
0227 
0228 ///////////////////////////////////////////////////////////////////////////////
0229 //
0230 //  The get_binary_left_subject and get_binary_right_subject template functions
0231 //  return the parser object, which is used as the left or right subject of a
0232 //  binary parser.
0233 //  If the parser under inspection is not a binary type parser the compilation
0234 //  will fail.
0235 //
0236 ///////////////////////////////////////////////////////////////////////////////
0237 template <typename BinaryT>
0238 inline typename binary_left_subject<BinaryT>::type const &
0239 get_binary_left_subject(BinaryT const &binary_)
0240 {
0241     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
0242     return binary_.left();
0243 }
0244 
0245 template <typename BinaryT>
0246 inline typename binary_right_subject<BinaryT>::type const &
0247 get_binary_right_subject(BinaryT const &binary_)
0248 {
0249     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
0250     return binary_.right();
0251 }
0252 
0253 ///////////////////////////////////////////////////////////////////////////////
0254 //
0255 //  The action_subject template can be used to return the type of the
0256 //  parser used as the subject of an action parser.
0257 //  If the parser under inspection is not an action type parser the compilation
0258 //  will fail.
0259 //
0260 ///////////////////////////////////////////////////////////////////////////////
0261 template <typename ActionT>
0262 struct action_subject {
0263 
0264     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
0265     typedef typename ActionT::subject_t type;
0266 };
0267 
0268 ///////////////////////////////////////////////////////////////////////////////
0269 //
0270 //  The get_action_subject template function returns the parser object, which
0271 //  is used as the subject of an action parser.
0272 //  If the parser under inspection is not an action type parser the compilation
0273 //  will fail.
0274 //
0275 ///////////////////////////////////////////////////////////////////////////////
0276 template <typename ActionT>
0277 inline typename action_subject<ActionT>::type const &
0278 get_action_subject(ActionT const &action_)
0279 {
0280     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
0281     return action_.subject();
0282 }
0283 
0284 ///////////////////////////////////////////////////////////////////////////////
0285 //
0286 //  The semantic_action template can be used to return the type of the
0287 //  attached semantic action of an action parser.
0288 //  If the parser under inspection is not an action type parser the compilation
0289 //  will fail.
0290 //
0291 ///////////////////////////////////////////////////////////////////////////////
0292 template <typename ActionT>
0293 struct semantic_action {
0294 
0295     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
0296     typedef typename ActionT::predicate_t type;
0297 };
0298 
0299 ///////////////////////////////////////////////////////////////////////////////
0300 //
0301 //  The get_semantic_action template function returns the attached semantic
0302 //  action of an action parser.
0303 //  If the parser under inspection is not an action type parser the compilation
0304 //  will fail.
0305 //
0306 ///////////////////////////////////////////////////////////////////////////////
0307 template <typename ActionT>
0308 inline typename semantic_action<ActionT>::type const &
0309 get_semantic_action(ActionT const &action_)
0310 {
0311     BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
0312     return action_.predicate();
0313 }
0314 
0315 ///////////////////////////////////////////////////////////////////////////////
0316 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0317 
0318 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0319 
0320 #endif // !defined(BOOST_SPIRIT_PARSER_TRAITS_HPP)