1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007
9 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007
11 // MS compatible compilers support #pragma once
16 #include <boost/config.hpp>
17 #include <boost/mpl/assert.hpp>
18 #include <boost/type_traits/is_same.hpp>
19 #include <boost/proto/core.hpp>
20 #include <boost/xpressive/detail/detail_fwd.hpp>
21 #include <boost/xpressive/detail/static/static.hpp>
22 #include <boost/xpressive/detail/core/matcher/alternate_matcher.hpp>
23 #include <boost/xpressive/detail/utility/cons.hpp>
25 namespace boost { namespace xpressive
29 ///////////////////////////////////////////////////////////////////////////////
31 // a fusion-compatible sequence of alternate expressions, that also keeps
32 // track of the list's width and purity.
33 template<typename Head, typename Tail>
34 struct alternates_list
35 : fusion::cons<Head, Tail>
37 BOOST_STATIC_CONSTANT(std::size_t, width = Head::width == Tail::width ? Head::width : detail::unknown_width::value);
38 BOOST_STATIC_CONSTANT(bool, pure = Head::pure && Tail::pure);
40 alternates_list(Head const &head, Tail const &tail)
41 : fusion::cons<Head, Tail>(head, tail)
46 template<typename Head>
47 struct alternates_list<Head, fusion::nil>
48 : fusion::cons<Head, fusion::nil>
50 BOOST_STATIC_CONSTANT(std::size_t, width = Head::width);
51 BOOST_STATIC_CONSTANT(bool, pure = Head::pure);
53 alternates_list(Head const &head, fusion::nil const &tail)
54 : fusion::cons<Head, fusion::nil>(head, tail)
60 namespace grammar_detail
62 ///////////////////////////////////////////////////////////////////////////////
64 template<typename Grammar, typename Callable = proto::callable>
65 struct in_alternate_list : proto::transform<in_alternate_list<Grammar, Callable> >
67 template<typename Expr, typename State, typename Data>
68 struct impl : proto::transform_impl<Expr, State, Data>
71 detail::alternates_list<
72 typename Grammar::template impl<
74 , detail::alternate_end_xpression
81 result_type operator ()(
82 typename impl::expr_param expr
83 , typename impl::state_param state
84 , typename impl::data_param data
88 typename Grammar::template impl<Expr, detail::alternate_end_xpression, Data>()(
90 , detail::alternate_end_xpression()
99 ///////////////////////////////////////////////////////////////////////////////
100 // as_alternate_matcher
101 template<typename Grammar, typename Callable = proto::callable>
102 struct as_alternate_matcher : proto::transform<as_alternate_matcher<Grammar, Callable> >
104 template<typename Expr, typename State, typename Data>
105 struct impl : proto::transform_impl<Expr, State, Data>
107 typedef typename impl::data data_type;
109 detail::alternate_matcher<
110 typename Grammar::template impl<Expr, State, Data>::result_type
111 , typename data_type::traits_type
115 result_type operator ()(
116 typename impl::expr_param expr
117 , typename impl::state_param state
118 , typename impl::data_param data
122 typename Grammar::template impl<Expr, State, Data>()(expr, state, data)