Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:50

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // as_alternate.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <boost/config.hpp>
0017 #include <boost/mpl/assert.hpp>
0018 #include <boost/type_traits/is_same.hpp>
0019 #include <boost/proto/core.hpp>
0020 #include <boost/xpressive/detail/detail_fwd.hpp>
0021 #include <boost/xpressive/detail/static/static.hpp>
0022 #include <boost/xpressive/detail/core/matcher/alternate_matcher.hpp>
0023 #include <boost/xpressive/detail/utility/cons.hpp>
0024 
0025 namespace boost { namespace xpressive
0026 {
0027     namespace detail
0028     {
0029         ///////////////////////////////////////////////////////////////////////////////
0030         // alternates_list
0031         //   a fusion-compatible sequence of alternate expressions, that also keeps
0032         //   track of the list's width and purity.
0033         template<typename Head, typename Tail>
0034         struct alternates_list
0035           : fusion::cons<Head, Tail>
0036         {
0037             BOOST_STATIC_CONSTANT(std::size_t, width = Head::width == Tail::width ? Head::width : detail::unknown_width::value);
0038             BOOST_STATIC_CONSTANT(bool, pure = Head::pure && Tail::pure);
0039 
0040             alternates_list(Head const &head, Tail const &tail)
0041               : fusion::cons<Head, Tail>(head, tail)
0042             {
0043             }
0044         };
0045 
0046         template<typename Head>
0047         struct alternates_list<Head, fusion::nil>
0048           : fusion::cons<Head, fusion::nil>
0049         {
0050             BOOST_STATIC_CONSTANT(std::size_t, width = Head::width);
0051             BOOST_STATIC_CONSTANT(bool, pure = Head::pure);
0052 
0053             alternates_list(Head const &head, fusion::nil const &tail)
0054               : fusion::cons<Head, fusion::nil>(head, tail)
0055             {
0056             }
0057         };
0058     }
0059 
0060     namespace grammar_detail
0061     {
0062         ///////////////////////////////////////////////////////////////////////////////
0063         // in_alternate_list
0064         template<typename Grammar, typename Callable = proto::callable>
0065         struct in_alternate_list : proto::transform<in_alternate_list<Grammar, Callable> >
0066         {
0067             template<typename Expr, typename State, typename Data>
0068             struct impl : proto::transform_impl<Expr, State, Data>
0069             {
0070                 typedef
0071                     detail::alternates_list<
0072                         typename Grammar::template impl<
0073                             Expr
0074                           , detail::alternate_end_xpression
0075                           , Data
0076                         >::result_type
0077                       , State
0078                     >
0079                 result_type;
0080 
0081                 result_type operator ()(
0082                     typename impl::expr_param expr
0083                   , typename impl::state_param state
0084                   , typename impl::data_param data
0085                 ) const
0086                 {
0087                     return result_type(
0088                         typename Grammar::template impl<Expr, detail::alternate_end_xpression, Data>()(
0089                             expr
0090                           , detail::alternate_end_xpression()
0091                           , data
0092                         )
0093                       , state
0094                     );
0095                 }
0096             };
0097         };
0098 
0099         ///////////////////////////////////////////////////////////////////////////////
0100         // as_alternate_matcher
0101         template<typename Grammar, typename Callable = proto::callable>
0102         struct as_alternate_matcher : proto::transform<as_alternate_matcher<Grammar, Callable> >
0103         {
0104             template<typename Expr, typename State, typename Data>
0105             struct impl : proto::transform_impl<Expr, State, Data>
0106             {
0107                 typedef typename impl::data data_type;
0108                 typedef
0109                     detail::alternate_matcher<
0110                         typename Grammar::template impl<Expr, State, Data>::result_type
0111                       , typename data_type::traits_type
0112                     >
0113                 result_type;
0114 
0115                 result_type operator ()(
0116                     typename impl::expr_param expr
0117                   , typename impl::state_param state
0118                   , typename impl::data_param data
0119                 ) const
0120                 {
0121                     return result_type(
0122                         typename Grammar::template impl<Expr, State, Data>()(expr, state, data)
0123                     );
0124                 }
0125             };
0126         };
0127     }
0128 
0129 }}
0130 
0131 #endif