os/ossrv/ossrv_pub/boost_apis/boost/spirit/meta/traverse.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/spirit/meta/traverse.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,218 @@
     1.4 +/*=============================================================================
     1.5 +    Copyright (c) 2002-2003 Joel de Guzman
     1.6 +    Copyright (c) 2002-2003 Hartmut Kaiser
     1.7 +    http://spirit.sourceforge.net/
     1.8 +
     1.9 +    Use, modification and distribution is subject to the Boost Software
    1.10 +    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.11 +    http://www.boost.org/LICENSE_1_0.txt)
    1.12 +=============================================================================*/
    1.13 +#if !defined(BOOST_SPIRIT_TRAVERSE_HPP)
    1.14 +#define BOOST_SPIRIT_TRAVERSE_HPP
    1.15 +
    1.16 +#include <boost/spirit/meta/impl/traverse.ipp>
    1.17 +
    1.18 +namespace boost { namespace spirit
    1.19 +{
    1.20 +    ///////////////////////////////////////////////////////////////////////////
    1.21 +    //
    1.22 +    //  Post-order traversal of auxilliary parsers.
    1.23 +    //
    1.24 +    ///////////////////////////////////////////////////////////////////////////
    1.25 +    struct post_order
    1.26 +    {
    1.27 +        //  Return the parser type, which is generated as the result of the
    1.28 +        //  traverse function below.
    1.29 +
    1.30 +        template <typename MetaT, typename ParserT>
    1.31 +        struct result
    1.32 +        {
    1.33 +            typedef typename
    1.34 +                traverse_post_order_return<
    1.35 +                    MetaT
    1.36 +                  , ParserT
    1.37 +                  , traverse_post_order_env<0, 0, 0, 0>
    1.38 +                >::type
    1.39 +            type;
    1.40 +        };
    1.41 +
    1.42 +        //  Traverse a given parser and refactor it with the help of the given
    1.43 +        //  MetaT metafunction template.
    1.44 +
    1.45 +        template <typename MetaT, typename ParserT>
    1.46 +        static typename result<MetaT, ParserT>::type
    1.47 +        traverse(MetaT const &meta_, ParserT const &parser_)
    1.48 +        {
    1.49 +            typedef typename ParserT::parser_category_t parser_category_t;
    1.50 +            return impl::traverse_post_order<parser_category_t>::generate(
    1.51 +                meta_, parser_, traverse_post_order_env<0, 0, 0, 0>());
    1.52 +        }
    1.53 +    };
    1.54 +
    1.55 +    ///////////////////////////////////////////////////////////////////////////
    1.56 +    //
    1.57 +    //  Transform policies
    1.58 +    //
    1.59 +    //      The following policy classes could be used to assemble some new
    1.60 +    //      transformation metafunction which uses identity transformations
    1.61 +    //      for some parser_category type parsers.
    1.62 +    //
    1.63 +    ///////////////////////////////////////////////////////////////////////////
    1.64 +
    1.65 +    ///////////////////////////////////////////////////////////////////////////
    1.66 +    //  transform plain parsers
    1.67 +    template <typename TransformT>
    1.68 +    struct plain_identity_policy
    1.69 +    {
    1.70 +        template <typename ParserT, typename EnvT>
    1.71 +        struct plain_result
    1.72 +        {
    1.73 +            // plain parsers should be embedded and returned correctly
    1.74 +            typedef typename ParserT::embed_t type;
    1.75 +        };
    1.76 +
    1.77 +        template <typename ParserT, typename EnvT>
    1.78 +        typename parser_traversal_plain_result<TransformT, ParserT, EnvT>::type
    1.79 +        generate_plain(ParserT const &parser_, EnvT const& /*env*/) const
    1.80 +        {
    1.81 +            return parser_;
    1.82 +        }
    1.83 +    };
    1.84 +
    1.85 +    //////////////////////////////////
    1.86 +    //  transform unary parsers
    1.87 +    template <typename UnaryT, typename SubjectT>
    1.88 +    struct unary_identity_policy_return
    1.89 +    {
    1.90 +        typedef typename UnaryT::parser_generator_t parser_generator_t;
    1.91 +        typedef typename parser_generator_t
    1.92 +            ::template result<SubjectT>::type type;
    1.93 +    };
    1.94 +
    1.95 +    template <typename TransformT>
    1.96 +    struct unary_identity_policy
    1.97 +    {
    1.98 +        template <typename UnaryT, typename SubjectT, typename EnvT>
    1.99 +        struct unary_result
   1.100 +        {
   1.101 +            typedef
   1.102 +                typename unary_identity_policy_return<UnaryT, SubjectT>::type
   1.103 +            type;
   1.104 +        };
   1.105 +
   1.106 +        template <typename UnaryT, typename SubjectT, typename EnvT>
   1.107 +        typename parser_traversal_unary_result<
   1.108 +            TransformT, UnaryT, SubjectT, EnvT>::type
   1.109 +        generate_unary(
   1.110 +            UnaryT const &, SubjectT const &subject_, EnvT const& /*env*/) const
   1.111 +        {
   1.112 +            typedef typename UnaryT::parser_generator_t parser_generator_t;
   1.113 +            return parser_generator_t::template generate<SubjectT>(subject_);
   1.114 +        }
   1.115 +    };
   1.116 +
   1.117 +    //////////////////////////////////
   1.118 +    //  transform action parsers
   1.119 +    template <typename TransformT>
   1.120 +    struct action_identity_policy
   1.121 +    {
   1.122 +        template <typename ActionT, typename SubjectT, typename EnvT>
   1.123 +        struct action_result
   1.124 +        {
   1.125 +            typedef action<SubjectT, typename ActionT::predicate_t> type;
   1.126 +        };
   1.127 +
   1.128 +        template <typename ActionT, typename SubjectT, typename EnvT>
   1.129 +        typename parser_traversal_action_result<
   1.130 +            TransformT, ActionT, SubjectT, EnvT
   1.131 +        >::type
   1.132 +        generate_action(ActionT const &action_, SubjectT const &subject_,
   1.133 +            EnvT const& /*env*/) const
   1.134 +        {
   1.135 +            return subject_[action_.predicate()];
   1.136 +        }
   1.137 +    };
   1.138 +
   1.139 +    //////////////////////////////////
   1.140 +    //  transform binary parsers
   1.141 +    template <typename BinaryT, typename LeftT, typename RightT>
   1.142 +    struct binary_identity_policy_return
   1.143 +    {
   1.144 +        typedef typename BinaryT::parser_generator_t parser_generator_t;
   1.145 +        typedef typename parser_generator_t
   1.146 +            ::template result<LeftT, RightT>::type type;
   1.147 +    };
   1.148 +
   1.149 +    template <typename TransformT>
   1.150 +    struct binary_identity_policy
   1.151 +    {
   1.152 +        template <typename BinaryT, typename LeftT
   1.153 +            , typename RightT, typename EnvT>
   1.154 +        struct binary_result {
   1.155 +
   1.156 +            typedef typename
   1.157 +                binary_identity_policy_return<BinaryT, LeftT, RightT>::type
   1.158 +            type;
   1.159 +        };
   1.160 +
   1.161 +        template <typename BinaryT, typename LeftT
   1.162 +            , typename RightT, typename EnvT>
   1.163 +        typename parser_traversal_binary_result<
   1.164 +            TransformT, BinaryT, LeftT, RightT, EnvT
   1.165 +        >::type
   1.166 +        generate_binary(
   1.167 +            BinaryT const &, LeftT const& left_
   1.168 +          , RightT const& right_, EnvT const& /*env*/) const
   1.169 +        {
   1.170 +            typedef typename BinaryT::parser_generator_t parser_generator_t;
   1.171 +            return parser_generator_t::
   1.172 +                template generate<LeftT, RightT>(left_, right_);
   1.173 +        }
   1.174 +    };
   1.175 +
   1.176 +    ///////////////////////////////////////////////////////////////////////////
   1.177 +    //
   1.178 +    //  transform_policies template
   1.179 +    //
   1.180 +    //      The transform_policies template metafunction could serve as a
   1.181 +    //      base class for new metafunctions to be passed to the traverse meta
   1.182 +    //      template (see above), where only minimal parts have to be
   1.183 +    //      overwritten.
   1.184 +    //
   1.185 +    ///////////////////////////////////////////////////////////////////////////
   1.186 +
   1.187 +    template <
   1.188 +        typename TransformT,
   1.189 +        typename PlainPolicyT = plain_identity_policy<TransformT>,
   1.190 +        typename UnaryPolicyT = unary_identity_policy<TransformT>,
   1.191 +        typename ActionPolicyT = action_identity_policy<TransformT>,
   1.192 +        typename BinaryPolicyT = binary_identity_policy<TransformT>
   1.193 +    >
   1.194 +    struct transform_policies :
   1.195 +        public PlainPolicyT,
   1.196 +        public UnaryPolicyT,
   1.197 +        public ActionPolicyT,
   1.198 +        public BinaryPolicyT
   1.199 +    {
   1.200 +    };
   1.201 +
   1.202 +    ///////////////////////////////////////////////////////////////////////////
   1.203 +    //
   1.204 +    //  Identity transformation
   1.205 +    //
   1.206 +    //      The identity_transform metafunction supplied to the traverse
   1.207 +    //      template will generate a new parser, which will be exactly
   1.208 +    //      identical to the parser given as the parameter to the traverse
   1.209 +    //      metafunction. I.e. the following conceptual 'equation' will be
   1.210 +    //      always true:
   1.211 +    //
   1.212 +    //      some_parser ==
   1.213 +    //          post_order::traverse(identity_transform(), some_parser)
   1.214 +    //
   1.215 +    ///////////////////////////////////////////////////////////////////////////
   1.216 +
   1.217 +    struct identity_transform : transform_policies<identity_transform> {};
   1.218 +
   1.219 +}} // namespace boost::spirit
   1.220 +
   1.221 +#endif // !defined(BOOST_SPIRIT_TRAVERSE_HPP)