//////////////////////////////////////////////////////////////////////////// // set_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_SET_COMPILERS_HPP_EAN_10_04_2005 #define BOOST_XPRESSIVE_DETAIL_STATIC_PRODUCTIONS_SET_COMPILERS_HPP_EAN_10_04_2005 #include #include #include #include #include #include #include namespace boost { namespace xpressive { namespace detail { /////////////////////////////////////////////////////////////////////////////// // set_branch // struct set_branch { typedef no_next state_type; template struct apply { typedef State type; }; template static State const &call(Op const &op, State const &state, Visitor &) { return state.set(set_branch::get_matcher(op)), state; } private: template static Matcher const &get_matcher(static_xpression const &xpr) { return xpr; } }; /////////////////////////////////////////////////////////////////////////////// // list_branch struct list_branch { typedef int state_type; // not used template struct apply { typedef static_xpression type; }; template static static_xpression call(Op const &op, State const &state, dont_care) { return make_static_xpression(op, state); } }; /////////////////////////////////////////////////////////////////////////////// // list_noop_compiler struct list_noop_compiler { template struct apply { typedef typename State::next_type type; }; template static typename State::next_type call(Op const &op, State const &state, Visitor &visitor) { typedef typename Visitor::char_type char_type; char_type ch = char_cast(proto::arg(op), visitor.traits()); return state.push_back(ch, visitor.traits()); } }; /////////////////////////////////////////////////////////////////////////////// // list_assign_compiler struct list_assign_compiler { template struct apply { typedef typename Visitor::traits_type traits_type; typedef set_matcher type; }; template static typename apply::type call(Op const &op, State const &, Visitor &visitor) { typedef typename Visitor::char_type char_type; char_type ch = char_cast(proto::arg(proto::right(op)), visitor.traits()); return typename apply::type(ch, visitor.traits()); } }; }}} namespace boost { namespace proto { /////////////////////////////////////////////////////////////////////////////// // compilers for sets such as set['a' | range('a','z')] template<> struct compiler : fold_compiler { }; template<> struct compiler : branch_compiler { }; template<> struct compiler : branch_compiler { }; template<> struct compiler : branch_compiler { }; /////////////////////////////////////////////////////////////////////////////// // compilers for list-initialized sets such as (set='a','b','c') template<> struct compiler : branch_compiler { }; template<> struct compiler : fold_compiler { }; template<> struct compiler : xpressive::detail::list_noop_compiler { }; template<> struct compiler : xpressive::detail::list_assign_compiler { }; }} #endif