Back to home page

EIC code displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // as_independent.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_INDEPENDENT_HPP_EAN_04_05_2007
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INDEPENDENT_HPP_EAN_04_05_2007
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <boost/mpl/sizeof.hpp>
0017 #include <boost/xpressive/detail/detail_fwd.hpp>
0018 #include <boost/xpressive/detail/static/static.hpp>
0019 #include <boost/proto/core.hpp>
0020 #include <boost/proto/transform/arg.hpp>
0021 #include <boost/proto/transform/when.hpp>
0022 #include <boost/proto/transform/fold.hpp>
0023 #include <boost/proto/transform/fold_tree.hpp>
0024 
0025 namespace boost { namespace xpressive { namespace detail
0026 {
0027     struct keeper_tag
0028     {};
0029 
0030     struct lookahead_tag
0031     {};
0032 
0033     struct lookbehind_tag
0034     {};
0035 }}}
0036 
0037 namespace boost { namespace xpressive { namespace grammar_detail
0038 {
0039     // A grammar that only accepts static regexes that
0040     // don't have semantic actions.
0041     struct NotHasAction
0042       : proto::switch_<struct NotHasActionCases>
0043     {};
0044 
0045     struct NotHasActionCases
0046     {
0047         template<typename Tag, int Dummy = 0>
0048         struct case_
0049           : proto::nary_expr<Tag, proto::vararg<NotHasAction> >
0050         {};
0051 
0052         template<int Dummy>
0053         struct case_<proto::tag::terminal, Dummy>
0054           : not_< or_<
0055                 proto::terminal<detail::tracking_ptr<detail::regex_impl<_> > >,
0056                 proto::terminal<reference_wrapper<_> >
0057             > >
0058         {};
0059 
0060         template<int Dummy>
0061         struct case_<proto::tag::comma, Dummy>
0062           : proto::_    // because (set='a','b') can't contain an action
0063         {};
0064 
0065         template<int Dummy>
0066         struct case_<proto::tag::complement, Dummy>
0067           : proto::_    // because in ~X, X can't contain an unscoped action
0068         {};
0069 
0070         template<int Dummy>
0071         struct case_<detail::lookahead_tag, Dummy>
0072           : proto::_    // because actions in lookaheads are scoped
0073         {};
0074 
0075         template<int Dummy>
0076         struct case_<detail::lookbehind_tag, Dummy>
0077           : proto::_    // because actions in lookbehinds are scoped
0078         {};
0079 
0080         template<int Dummy>
0081         struct case_<detail::keeper_tag, Dummy>
0082           : proto::_    // because actions in keepers are scoped
0083         {};
0084 
0085         template<int Dummy>
0086         struct case_<proto::tag::subscript, Dummy>
0087           : proto::subscript<detail::set_initializer_type, _>
0088         {}; // only accept set[...], not actions!
0089     };
0090 
0091     struct IndependentEndXpression
0092       : or_<
0093             when<NotHasAction, detail::true_xpression()>
0094           , otherwise<detail::independent_end_xpression()>
0095         >
0096     {};
0097 
0098     template<typename Grammar, typename Callable = proto::callable>
0099     struct as_lookahead : proto::transform<as_lookahead<Grammar, Callable> >
0100     {
0101         template<typename Expr, typename State, typename Data>
0102         struct impl : proto::transform_impl<Expr, State, Data>
0103         {
0104             typedef typename proto::result_of::child<Expr>::type arg_type;
0105 
0106             typedef
0107                 typename IndependentEndXpression::impl<arg_type, int, int>::result_type
0108             end_xpr_type;
0109 
0110             typedef
0111                 typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
0112             xpr_type;
0113 
0114             typedef
0115                 detail::lookahead_matcher<xpr_type>
0116             result_type;
0117 
0118             result_type operator ()(
0119                 typename impl::expr_param expr
0120               , typename impl::state_param
0121               , typename impl::data_param data
0122             ) const
0123             {
0124                 int i = 0;
0125                 return result_type(
0126                     typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
0127                         proto::child(expr)
0128                       , IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
0129                       , data
0130                     )
0131                   , false
0132                 );
0133             }
0134         };
0135     };
0136 
0137     template<typename Grammar, typename Callable = proto::callable>
0138     struct as_lookbehind : proto::transform<as_lookbehind<Grammar, Callable> >
0139     {
0140         template<typename Expr, typename State, typename Data>
0141         struct impl : proto::transform_impl<Expr, State, Data>
0142         {
0143             typedef typename proto::result_of::child<Expr>::type arg_type;
0144 
0145             typedef
0146                 typename IndependentEndXpression::impl<arg_type, int, int>::result_type
0147             end_xpr_type;
0148 
0149             typedef
0150                 typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
0151             xpr_type;
0152 
0153             typedef
0154                 detail::lookbehind_matcher<xpr_type>
0155             result_type;
0156 
0157             result_type operator ()(
0158                 typename impl::expr_param expr
0159               , typename impl::state_param
0160               , typename impl::data_param data
0161             ) const
0162             {
0163                 int i = 0;
0164                 xpr_type expr2 = typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
0165                     proto::child(expr)
0166                   , IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
0167                   , data
0168                 );
0169                 std::size_t width = expr2.get_width().value();
0170                 return result_type(expr2, width, false);
0171             }
0172         };
0173     };
0174 
0175     template<typename Grammar, typename Callable = proto::callable>
0176     struct as_keeper : proto::transform<as_keeper<Grammar, Callable> >
0177     {
0178         template<typename Expr, typename State, typename Data>
0179         struct impl : proto::transform_impl<Expr, State, Data>
0180         {
0181             typedef typename proto::result_of::child<Expr>::type arg_type;
0182 
0183             typedef
0184                 typename IndependentEndXpression::impl<arg_type, int, int>::result_type
0185             end_xpr_type;
0186 
0187             typedef
0188                 typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
0189             xpr_type;
0190 
0191             typedef
0192                 detail::keeper_matcher<xpr_type>
0193             result_type;
0194 
0195             result_type operator ()(
0196                 typename impl::expr_param expr
0197               , typename impl::state_param
0198               , typename impl::data_param data
0199             ) const
0200             {
0201                 int i = 0;
0202                 return result_type(
0203                     typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
0204                         proto::child(expr)
0205                       , IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
0206                       , data
0207                     )
0208                 );
0209             }
0210         };
0211     };
0212 
0213 }}}
0214 
0215 #endif