/////////////////////////////////////////////////////////////////////////////// // quant_compilers.hpp // // Copyright 2004 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_PRODUCTIONS_QUANT_COMPILERS_HPP_EAN_10_04_2005 #define BOOST_XPRESSIVE_DETAIL_STATIC_PRODUCTIONS_QUANT_COMPILERS_HPP_EAN_10_04_2005 #include #include #include #include #include #include #include #include #include namespace boost { namespace xpressive { namespace detail { typedef proto::unary_op nil_op; /////////////////////////////////////////////////////////////////////////////// // generic_quant_compiler template struct generic_quant_compiler : proto::conditional_compiler < use_simple_repeat_predicate , proto::branch_compiler, ind_tag> , proto::transform_compiler < proto::compose_transforms < proto::arg_transform , repeater_if_transform > , seq_tag > > { }; // degenerate case, foo{0,0} becomes nil template struct generic_quant_compiler : proto::transform_compiler, seq_tag> { }; // degenerate case, foo{1,1} becomes foo template struct generic_quant_compiler : proto::transform_compiler { }; /////////////////////////////////////////////////////////////////////////////// // non_greedy_compiler struct non_greedy_compiler { template struct apply { typedef typename proto::arg_type::type arg_type; // Did you apply operator- to something that wasn't a quantifier? BOOST_MPL_ASSERT((is_greedy_quant)); typedef typename proto::tag_type::type tag_type; typedef generic_quant_compiler < false , min_type::type::value , max_type::type::value > compiler_type; typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply < arg_type , State , Visitor >::type type; }; template static typename apply::type call(Op const &op, State const &state, Visitor &visitor) { typedef typename apply::compiler_type compiler_type; return compiler_type::call(proto::arg(op), state, visitor); } }; }}} namespace boost { namespace proto { // production for one or more quant template<> struct compiler : xpressive::detail::generic_quant_compiler { }; // production for zero or more quant template<> struct compiler : xpressive::detail::generic_quant_compiler { }; // production for optional template<> struct compiler : xpressive::detail::generic_quant_compiler { }; // production for generic quantifiers template struct compiler, xpressive::detail::seq_tag, void> : xpressive::detail::generic_quant_compiler { }; // production for non-greedy quantifiers template<> struct compiler : xpressive::detail::non_greedy_compiler { }; }} #endif