1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/spirit/dynamic/select.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,237 @@
1.4 +/*=============================================================================
1.5 + Copyright (c) 2003 Hartmut Kaiser
1.6 + http://spirit.sourceforge.net/
1.7 +
1.8 + Use, modification and distribution is subject to the Boost Software
1.9 + License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.10 + http://www.boost.org/LICENSE_1_0.txt)
1.11 +=============================================================================*/
1.12 +#ifndef BOOST_SPIRIT_SELECT_HPP
1.13 +#define BOOST_SPIRIT_SELECT_HPP
1.14 +
1.15 +#include <boost/preprocessor/repeat.hpp>
1.16 +#include <boost/preprocessor/enum.hpp>
1.17 +#include <boost/preprocessor/enum_params.hpp>
1.18 +#include <boost/preprocessor/enum_params_with_defaults.hpp>
1.19 +#include <boost/preprocessor/inc.hpp>
1.20 +#include <boost/preprocessor/cat.hpp>
1.21 +#include <boost/preprocessor/facilities/intercept.hpp>
1.22 +
1.23 +#include <boost/spirit/core/parser.hpp>
1.24 +
1.25 +#include <boost/spirit/phoenix/tuples.hpp>
1.26 +
1.27 +///////////////////////////////////////////////////////////////////////////////
1.28 +//
1.29 +// Spirit predefined maximum number of possible embedded select_p parsers.
1.30 +// It should NOT be greater than PHOENIX_LIMIT!
1.31 +//
1.32 +///////////////////////////////////////////////////////////////////////////////
1.33 +#if !defined(BOOST_SPIRIT_SELECT_LIMIT)
1.34 +#define BOOST_SPIRIT_SELECT_LIMIT PHOENIX_LIMIT
1.35 +#endif // !defined(BOOST_SPIRIT_SELECT_LIMIT)
1.36 +
1.37 +///////////////////////////////////////////////////////////////////////////////
1.38 +//
1.39 +// ensure BOOST_SPIRIT_SELECT_LIMIT <= PHOENIX_LIMIT and
1.40 +// BOOST_SPIRIT_SELECT_LIMIT > 0
1.41 +// BOOST_SPIRIT_SELECT_LIMIT <= 15
1.42 +//
1.43 +// [Pushed this down a little to make CW happy with BOOST_STATIC_ASSERT]
1.44 +// [Otherwise, it complains: 'boost_static_assert_test_42' redefined]
1.45 +//
1.46 +///////////////////////////////////////////////////////////////////////////////
1.47 +BOOST_STATIC_ASSERT(BOOST_SPIRIT_SELECT_LIMIT <= PHOENIX_LIMIT);
1.48 +BOOST_STATIC_ASSERT(BOOST_SPIRIT_SELECT_LIMIT > 0);
1.49 +BOOST_STATIC_ASSERT(BOOST_SPIRIT_SELECT_LIMIT <= 15);
1.50 +
1.51 +///////////////////////////////////////////////////////////////////////////////
1.52 +//
1.53 +// Calculate the required amount of tuple members rounded up to the nearest
1.54 +// integer dividable by 3
1.55 +//
1.56 +///////////////////////////////////////////////////////////////////////////////
1.57 +#if BOOST_SPIRIT_SELECT_LIMIT > 12
1.58 +#define BOOST_SPIRIT_SELECT_LIMIT_A 15
1.59 +#elif BOOST_SPIRIT_SELECT_LIMIT > 9
1.60 +#define BOOST_SPIRIT_SELECT_LIMIT_A 12
1.61 +#elif BOOST_SPIRIT_SELECT_LIMIT > 6
1.62 +#define BOOST_SPIRIT_SELECT_LIMIT_A 9
1.63 +#elif BOOST_SPIRIT_SELECT_LIMIT > 3
1.64 +#define BOOST_SPIRIT_SELECT_LIMIT_A 6
1.65 +#else
1.66 +#define BOOST_SPIRIT_SELECT_LIMIT_A 3
1.67 +#endif
1.68 +
1.69 +///////////////////////////////////////////////////////////////////////////////
1.70 +namespace boost { namespace spirit {
1.71 +
1.72 +///////////////////////////////////////////////////////////////////////////////
1.73 +//
1.74 +// The select_default_no_fail and select_default_fail structs are used to
1.75 +// distinguish two different behaviours for the select_parser in case that not
1.76 +// any of the given sub-parsers match.
1.77 +//
1.78 +// If the select_parser is used with the select_default_no_fail behaviour,
1.79 +// then in case of no matching sub-parser the whole select_parser returns an
1.80 +// empty match and the value -1.
1.81 +//
1.82 +// If the select_parser is used with the select_default_fail behaviour, then
1.83 +// in case of no matching sub-parser the whole select_parser fails to match at
1.84 +// all.
1.85 +//
1.86 +///////////////////////////////////////////////////////////////////////////////
1.87 +struct select_default_no_fail {};
1.88 +struct select_default_fail {};
1.89 +
1.90 +}} // namespace boost::spirit
1.91 +
1.92 +///////////////////////////////////////////////////////////////////////////////
1.93 +#include <boost/spirit/dynamic/impl/select.ipp>
1.94 +
1.95 +///////////////////////////////////////////////////////////////////////////////
1.96 +namespace boost { namespace spirit {
1.97 +
1.98 +///////////////////////////////////////////////////////////////////////////////
1.99 +template <typename TupleT, typename BehaviourT, typename T>
1.100 +struct select_parser
1.101 +: public parser<select_parser<TupleT, BehaviourT, T> >
1.102 +{
1.103 + typedef select_parser<TupleT, BehaviourT, T> self_t;
1.104 +
1.105 + select_parser(TupleT const &t_)
1.106 + : t(t_)
1.107 + {}
1.108 +
1.109 + template <typename ScannerT>
1.110 + struct result
1.111 + {
1.112 + typedef typename match_result<ScannerT, T>::type type;
1.113 + };
1.114 +
1.115 + template <typename ScannerT>
1.116 + typename parser_result<self_t, ScannerT>::type
1.117 + parse(ScannerT const& scan) const
1.118 + {
1.119 + typedef typename parser_result<self_t, ScannerT>::type result_t;
1.120 +
1.121 + if (!scan.at_end()) {
1.122 + return impl::parse_tuple_element<
1.123 + TupleT::length, result_t, TupleT, BehaviourT>::do_(t, scan);
1.124 + }
1.125 + return impl::select_match_gen<result_t, BehaviourT>::do_(scan);
1.126 + }
1.127 +
1.128 + TupleT const t;
1.129 +};
1.130 +
1.131 +///////////////////////////////////////////////////////////////////////////////
1.132 +template <typename BehaviourT, typename T = int>
1.133 +struct select_parser_gen {
1.134 +
1.135 + ///////////////////////////////////////////////////////////////////////////
1.136 + //
1.137 + // This generates different select_parser_gen::operator()() functions with
1.138 + // an increasing number of parser parameters:
1.139 + //
1.140 + // template <typename ParserT0, ...>
1.141 + // select_parser<
1.142 + // phoenix::tuple<
1.143 + // typename impl::as_embedded_parser<ParserT0>::type,
1.144 + // ...
1.145 + // >,
1.146 + // BehaviourT,
1.147 + // T
1.148 + // >
1.149 + // operator()(ParserT0 const &p0, ...) const
1.150 + // {
1.151 + // typedef impl::as_embedded_parser<ParserT0> parser_t0;
1.152 + // ...
1.153 + //
1.154 + // typedef phoenix::tuple<
1.155 + // parser_t0::type,
1.156 + // ...
1.157 + // > tuple_t;
1.158 + // typedef select_parser<tuple_t, BehaviourT, T> result_t;
1.159 + //
1.160 + // return result_t(tuple_t(
1.161 + // parser_t0::convert(p0),
1.162 + // ...
1.163 + // ));
1.164 + // }
1.165 + //
1.166 + // The number of generated functions depends on the maximum tuple member
1.167 + // limit defined by the PHOENIX_LIMIT pp constant.
1.168 + //
1.169 + ///////////////////////////////////////////////////////////////////////////
1.170 + #define BOOST_SPIRIT_SELECT_EMBEDDED(z, N, _) \
1.171 + typename impl::as_embedded_parser<BOOST_PP_CAT(ParserT, N)>::type \
1.172 + /**/
1.173 + #define BOOST_SPIRIT_SELECT_EMBEDDED_TYPEDEF(z, N, _) \
1.174 + typedef impl::as_embedded_parser<BOOST_PP_CAT(ParserT, N)> \
1.175 + BOOST_PP_CAT(parser_t, N); \
1.176 + /**/
1.177 + #define BOOST_SPIRIT_SELECT_CONVERT(z, N, _) \
1.178 + BOOST_PP_CAT(parser_t, N)::convert(BOOST_PP_CAT(p, N)) \
1.179 + /**/
1.180 +
1.181 + #define BOOST_SPIRIT_SELECT_PARSER(z, N, _) \
1.182 + template < \
1.183 + BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_INC(N), typename ParserT) \
1.184 + > \
1.185 + select_parser< \
1.186 + phoenix::tuple< \
1.187 + BOOST_PP_ENUM_ ## z(BOOST_PP_INC(N), \
1.188 + BOOST_SPIRIT_SELECT_EMBEDDED, _) \
1.189 + >, \
1.190 + BehaviourT, \
1.191 + T \
1.192 + > \
1.193 + operator()( \
1.194 + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_INC(N), \
1.195 + ParserT, const &p) \
1.196 + ) const \
1.197 + { \
1.198 + BOOST_PP_REPEAT_ ## z(BOOST_PP_INC(N), \
1.199 + BOOST_SPIRIT_SELECT_EMBEDDED_TYPEDEF, _) \
1.200 + \
1.201 + typedef phoenix::tuple< \
1.202 + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_INC(N), \
1.203 + typename parser_t, ::type BOOST_PP_INTERCEPT) \
1.204 + > tuple_t; \
1.205 + typedef select_parser<tuple_t, BehaviourT, T> result_t; \
1.206 + \
1.207 + return result_t(tuple_t( \
1.208 + BOOST_PP_ENUM_ ## z(BOOST_PP_INC(N), \
1.209 + BOOST_SPIRIT_SELECT_CONVERT, _) \
1.210 + )); \
1.211 + } \
1.212 + /**/
1.213 +
1.214 + BOOST_PP_REPEAT(BOOST_SPIRIT_SELECT_LIMIT_A,
1.215 + BOOST_SPIRIT_SELECT_PARSER, _)
1.216 +
1.217 + #undef BOOST_SPIRIT_SELECT_PARSER
1.218 + #undef BOOST_SPIRIT_SELECT_CONVERT
1.219 + #undef BOOST_SPIRIT_SELECT_EMBEDDED_TYPEDEF
1.220 + #undef BOOST_SPIRIT_SELECT_EMBEDDED
1.221 + ///////////////////////////////////////////////////////////////////////////
1.222 +};
1.223 +
1.224 +///////////////////////////////////////////////////////////////////////////////
1.225 +//
1.226 +// Predefined parser generator helper objects
1.227 +//
1.228 +///////////////////////////////////////////////////////////////////////////////
1.229 +select_parser_gen<select_default_no_fail> const select_p =
1.230 + select_parser_gen<select_default_no_fail>();
1.231 +
1.232 +select_parser_gen<select_default_fail> const select_fail_p =
1.233 + select_parser_gen<select_default_fail>();
1.234 +
1.235 +#undef BOOST_SPIRIT_SELECT_LIMIT_A
1.236 +
1.237 +///////////////////////////////////////////////////////////////////////////////
1.238 +}} // namespace boost::spirit
1.239 +
1.240 +#endif // BOOST_SPIRIT_SELECT_HPP