/////////////////////////////////////////////////////////////////////////////// // as_independent.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_INDEPENDENT_HPP_EAN_04_05_2007 #define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INDEPENDENT_HPP_EAN_04_05_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 { struct keeper_tag {}; struct lookahead_tag {}; struct lookbehind_tag {}; }}} namespace boost { namespace xpressive { namespace grammar_detail { // A grammar that only accepts static regexes that // don't have semantic actions. struct NotHasAction : proto::switch_ {}; struct NotHasActionCases { template struct case_ : proto::nary_expr > {}; template struct case_ : not_< or_< proto::terminal > >, proto::terminal > > > {}; template struct case_ : proto::_ // because (set='a','b') can't contain an action {}; template struct case_ : proto::_ // because in ~X, X can't contain an unscoped action {}; template struct case_ : proto::_ // because actions in lookaheads are scoped {}; template struct case_ : proto::_ // because actions in lookbehinds are scoped {}; template struct case_ : proto::_ // because actions in keepers are scoped {}; template struct case_ : proto::subscript {}; // only accept set[...], not actions! }; struct IndependentEndXpression : or_< when , otherwise > {}; template struct as_lookahead : proto::transform > { template struct impl : proto::transform_impl { typedef typename proto::result_of::child::type arg_type; typedef typename IndependentEndXpression::impl::result_type end_xpr_type; typedef typename Grammar::template impl::result_type xpr_type; typedef detail::lookahead_matcher result_type; result_type operator ()( typename impl::expr_param expr , typename impl::state_param , typename impl::data_param data ) const { int i = 0; return result_type( typename Grammar::template impl()( proto::child(expr) , IndependentEndXpression::impl()(proto::child(expr), i, i) , data ) , false ); } }; }; template struct as_lookbehind : proto::transform > { template struct impl : proto::transform_impl { typedef typename proto::result_of::child::type arg_type; typedef typename IndependentEndXpression::impl::result_type end_xpr_type; typedef typename Grammar::template impl::result_type xpr_type; typedef detail::lookbehind_matcher result_type; result_type operator ()( typename impl::expr_param expr , typename impl::state_param , typename impl::data_param data ) const { int i = 0; xpr_type expr2 = typename Grammar::template impl()( proto::child(expr) , IndependentEndXpression::impl()(proto::child(expr), i, i) , data ); std::size_t width = expr2.get_width().value(); return result_type(expr2, width, false); } }; }; template struct as_keeper : proto::transform > { template struct impl : proto::transform_impl { typedef typename proto::result_of::child::type arg_type; typedef typename IndependentEndXpression::impl::result_type end_xpr_type; typedef typename Grammar::template impl::result_type xpr_type; typedef detail::keeper_matcher result_type; result_type operator ()( typename impl::expr_param expr , typename impl::state_param , typename impl::data_param data ) const { int i = 0; return result_type( typename Grammar::template impl()( proto::child(expr) , IndependentEndXpression::impl()(proto::child(expr), i, i) , data ) ); } }; }; }}} #endif