/////////////////////////////////////////////////////////////////////////////// // as_alternate.hpp // // Copyright 2008 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007 // MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif #include #include #include #include #include #include #include #include namespace boost { namespace xpressive { namespace detail { /////////////////////////////////////////////////////////////////////////////// // alternates_list // a fusion-compatible sequence of alternate expressions, that also keeps // track of the list's width and purity. template struct alternates_list : fusion::cons { BOOST_STATIC_CONSTANT(std::size_t, width = Head::width == Tail::width ? Head::width : detail::unknown_width::value); BOOST_STATIC_CONSTANT(bool, pure = Head::pure && Tail::pure); alternates_list(Head const &head, Tail const &tail) : fusion::cons(head, tail) { } }; template struct alternates_list : fusion::cons { BOOST_STATIC_CONSTANT(std::size_t, width = Head::width); BOOST_STATIC_CONSTANT(bool, pure = Head::pure); alternates_list(Head const &head, fusion::nil const &tail) : fusion::cons(head, tail) { } }; } namespace grammar_detail { /////////////////////////////////////////////////////////////////////////////// // in_alternate_list template struct in_alternate_list : proto::transform > { template struct impl : proto::transform_impl { typedef detail::alternates_list< typename Grammar::template impl< Expr , detail::alternate_end_xpression , Data >::result_type , State > result_type; result_type operator ()( typename impl::expr_param expr , typename impl::state_param state , typename impl::data_param data ) const { return result_type( typename Grammar::template impl()( expr , detail::alternate_end_xpression() , data ) , state ); } }; }; /////////////////////////////////////////////////////////////////////////////// // as_alternate_matcher template struct as_alternate_matcher : proto::transform > { template struct impl : proto::transform_impl { typedef typename impl::data data_type; typedef detail::alternate_matcher< typename Grammar::template impl::result_type , typename data_type::traits_type > result_type; result_type operator ()( typename impl::expr_param expr , typename impl::state_param state , typename impl::data_param data ) const { return result_type( typename Grammar::template impl()(expr, state, data) ); } }; }; } }} #endif