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_INDEPENDENT_HPP_EAN_04_05_2007
9 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INDEPENDENT_HPP_EAN_04_05_2007
11 // MS compatible compilers support #pragma once
16 #include <boost/mpl/sizeof.hpp>
17 #include <boost/xpressive/detail/detail_fwd.hpp>
18 #include <boost/xpressive/detail/static/static.hpp>
19 #include <boost/proto/core.hpp>
20 #include <boost/proto/transform/arg.hpp>
21 #include <boost/proto/transform/when.hpp>
22 #include <boost/proto/transform/fold.hpp>
23 #include <boost/proto/transform/fold_tree.hpp>
25 namespace boost { namespace xpressive { namespace detail
37 namespace boost { namespace xpressive { namespace grammar_detail
39 // A grammar that only accepts static regexes that
40 // don't have semantic actions.
42 : proto::switch_<struct NotHasActionCases>
45 struct NotHasActionCases
47 template<typename Tag, int Dummy = 0>
49 : proto::nary_expr<Tag, proto::vararg<NotHasAction> >
53 struct case_<proto::tag::terminal, Dummy>
55 proto::terminal<detail::tracking_ptr<detail::regex_impl<_> > >,
56 proto::terminal<reference_wrapper<_> >
61 struct case_<proto::tag::comma, Dummy>
62 : proto::_ // because (set='a','b') can't contain an action
66 struct case_<proto::tag::complement, Dummy>
67 : proto::_ // because in ~X, X can't contain an unscoped action
71 struct case_<detail::lookahead_tag, Dummy>
72 : proto::_ // because actions in lookaheads are scoped
76 struct case_<detail::lookbehind_tag, Dummy>
77 : proto::_ // because actions in lookbehinds are scoped
81 struct case_<detail::keeper_tag, Dummy>
82 : proto::_ // because actions in keepers are scoped
86 struct case_<proto::tag::subscript, Dummy>
87 : proto::subscript<detail::set_initializer_type, _>
88 {}; // only accept set[...], not actions!
91 struct IndependentEndXpression
93 when<NotHasAction, detail::true_xpression()>
94 , otherwise<detail::independent_end_xpression()>
98 template<typename Grammar, typename Callable = proto::callable>
99 struct as_lookahead : proto::transform<as_lookahead<Grammar, Callable> >
101 template<typename Expr, typename State, typename Data>
102 struct impl : proto::transform_impl<Expr, State, Data>
104 typedef typename proto::result_of::child<Expr>::type arg_type;
107 typename IndependentEndXpression::impl<arg_type, int, int>::result_type
111 typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
115 detail::lookahead_matcher<xpr_type>
118 result_type operator ()(
119 typename impl::expr_param expr
120 , typename impl::state_param
121 , typename impl::data_param data
126 typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
128 , IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
137 template<typename Grammar, typename Callable = proto::callable>
138 struct as_lookbehind : proto::transform<as_lookbehind<Grammar, Callable> >
140 template<typename Expr, typename State, typename Data>
141 struct impl : proto::transform_impl<Expr, State, Data>
143 typedef typename proto::result_of::child<Expr>::type arg_type;
146 typename IndependentEndXpression::impl<arg_type, int, int>::result_type
150 typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
154 detail::lookbehind_matcher<xpr_type>
157 result_type operator ()(
158 typename impl::expr_param expr
159 , typename impl::state_param
160 , typename impl::data_param data
164 xpr_type expr2 = typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
166 , IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
169 std::size_t width = expr2.get_width().value();
170 return result_type(expr2, width, false);
175 template<typename Grammar, typename Callable = proto::callable>
176 struct as_keeper : proto::transform<as_keeper<Grammar, Callable> >
178 template<typename Expr, typename State, typename Data>
179 struct impl : proto::transform_impl<Expr, State, Data>
181 typedef typename proto::result_of::child<Expr>::type arg_type;
184 typename IndependentEndXpression::impl<arg_type, int, int>::result_type
188 typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
192 detail::keeper_matcher<xpr_type>
195 result_type operator ()(
196 typename impl::expr_param expr
197 , typename impl::state_param
198 , typename impl::data_param data
203 typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
205 , IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)