action_matcher.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 490 行 · 第 1/2 页
HPP
490 行
}; /////////////////////////////////////////////////////////////////////////////// // action // template<typename Actor> struct action : actionable { action(Actor const &actor) : actionable() , actor_(actor) { } virtual void execute(action_args_type *action_args) const { action_context const ctx(action_args); proto::eval(this->actor_, ctx); } private: Actor actor_; }; /////////////////////////////////////////////////////////////////////////////// // subreg_transform // struct subreg_transform : proto::callable { template<typename Sig> struct result {}; template<typename This, typename Expr, typename State, typename Visitor> struct result<This(Expr, State, Visitor)> { typedef State unref_state; typedef typename proto::terminal<sub_match<typename unref_state::iterator> >::type type; }; template<typename Expr, typename State, typename Visitor> typename result<void(Expr, State, Visitor)>::type operator ()(Expr const &, State const &state, Visitor &visitor) const { sub_match<typename State::iterator> const &sub = state.sub_matches_[ visitor ]; return proto::as_expr(sub); } }; /////////////////////////////////////////////////////////////////////////////// // mark_transform // struct mark_transform : proto::callable { template<typename Sig> struct result {}; template<typename This, typename Expr, typename State, typename Visitor> struct result<This(Expr, State, Visitor)> { typedef State unref_state; typedef typename proto::terminal<sub_match<typename unref_state::iterator> >::type type; }; template<typename Expr, typename State, typename Visitor> typename result<void(Expr, State, Visitor)>::type operator ()(Expr const &expr, State const &state, Visitor &) const { sub_match<typename State::iterator> const &sub = state.sub_matches_[ proto::arg(expr).mark_number_ ]; return proto::as_expr(sub); } }; /////////////////////////////////////////////////////////////////////////////// // opt // template<typename T> struct opt { typedef T type; typedef T const &reference; opt(T const *t) : t_(t) {} operator reference() const { detail::ensure(0 != this->t_, regex_constants::error_badattr, "Use of uninitialized regex attribute"); return *this->t_; } T const *t_; }; /////////////////////////////////////////////////////////////////////////////// // attr_transform // struct attr_transform : proto::callable { template<typename Sig> struct result {}; template<typename This, typename Expr, typename State, typename Visitor> struct result<This(Expr, State, Visitor)> { typedef typename proto::result_of::as_expr< opt<typename Expr::proto_arg0::matcher_type::value_type::second_type> >::type type; }; template<typename Expr, typename State, typename Visitor> typename result<void(Expr, State, Visitor)>::type operator ()(Expr const &, State const &state, Visitor &) const { typedef typename Expr::proto_arg0::matcher_type::value_type::second_type attr_type; int slot = typename Expr::proto_arg0::nbr_type(); attr_type const *attr = static_cast<attr_type const *>(state.attr_context_.attr_slots_[slot-1]); return proto::as_expr(opt<attr_type>(attr)); } }; /////////////////////////////////////////////////////////////////////////////// // attr_with_default_transform // template<typename Grammar, typename Callable = proto::callable> struct attr_with_default_transform : proto::callable { template<typename Sig> struct result {}; template<typename This, typename Expr, typename State, typename Visitor> struct result<This(Expr, State, Visitor)> { typedef typename proto::unary_expr< attr_with_default_tag , typename Grammar::template result<void(Expr, State, Visitor)>::type >::type type; }; template<typename Expr, typename State, typename Visitor> typename result<void(Expr, State, Visitor)>::type operator ()(Expr const &expr, State const &state, Visitor &visitor) const { typename result<void(Expr, State, Visitor)>::type that = { Grammar()(expr, state, visitor) }; return that; } }; /////////////////////////////////////////////////////////////////////////////// // by_ref_transform // struct by_ref_transform : proto::callable { template<typename Sig> struct result {}; template<typename This, typename Expr, typename State, typename Visitor> struct result<This(Expr, State, Visitor)> { typedef typename proto::terminal<typename proto::result_of::arg<Expr>::const_reference>::type type; }; template<typename Expr, typename State, typename Visitor> typename result<void(Expr, State, Visitor)>::type operator ()(Expr const &expr, State const &, Visitor &) const { typedef typename result<void(Expr, State, Visitor)>::type that_type; return that_type::make(proto::arg(expr)); } }; /////////////////////////////////////////////////////////////////////////////// // BindActionArgs // struct BindActionArgs : proto::or_< proto::when<proto::terminal<any_matcher>, subreg_transform> , proto::when<proto::terminal<mark_placeholder>, mark_transform> , proto::when<proto::terminal<read_attr<proto::_, proto::_> >, attr_transform> , proto::when<proto::terminal<proto::_>, by_ref_transform> , proto::when< proto::bitwise_or<proto::terminal<read_attr<proto::_, proto::_> >, BindActionArgs> , attr_with_default_transform<proto::bitwise_or<attr_transform, BindActionArgs> > > , proto::otherwise<proto::nary_expr<proto::_, proto::vararg<BindActionArgs> > > > {}; /////////////////////////////////////////////////////////////////////////////// // action_matcher // template<typename Actor> struct action_matcher : quant_style<quant_none, 0, false> { int sub_; Actor actor_; action_matcher(Actor const &actor, int sub) : sub_(sub) , actor_(actor) { } template<typename BidiIter, typename Next> bool match(match_state<BidiIter> &state, Next const &next) const { // Bind the arguments int sub = this->sub_; // BUGBUG this is a hack typedef typename BindActionArgs::template result<void(Actor, match_state<BidiIter>, int)>::type action_type; action<action_type> actor(BindActionArgs()(this->actor_, state, sub)); // Put the action in the action list actionable const **action_list_tail = state.action_list_tail_; *state.action_list_tail_ = &actor; state.action_list_tail_ = &actor.next; // Match the rest of the pattern if(next.match(state)) { return true; } BOOST_ASSERT(0 == actor.next); // remove action from list *action_list_tail = 0; state.action_list_tail_ = action_list_tail; return false; } };}}}#if BOOST_MSVC#pragma warning(pop)#endif#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?