File indexing completed on 2025-01-31 10:02:16
0001
0002
0003
0004
0005
0006 #if !defined(BOOST_SPIRIT_LEX_LEXER_SEMANTIC_ACTION_DATA_JUN_10_2009_0417PM)
0007 #define BOOST_SPIRIT_LEX_LEXER_SEMANTIC_ACTION_DATA_JUN_10_2009_0417PM
0008
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012
0013 #include <boost/spirit/home/lex/lexer/pass_flags.hpp>
0014 #include <boost/mpl/bool.hpp>
0015 #include <boost/function.hpp>
0016 #include <vector>
0017
0018 namespace boost { namespace spirit { namespace lex { namespace lexertl
0019 {
0020 namespace detail
0021 {
0022
0023 template <typename Iterator, typename SupportsState, typename Data>
0024 struct semantic_actions;
0025
0026
0027
0028
0029
0030 template <typename Iterator, typename Data>
0031 struct semantic_actions<Iterator, mpl::false_, Data>
0032 {
0033 typedef void functor_type(Iterator&, Iterator&
0034 , BOOST_SCOPED_ENUM(pass_flags)&, std::size_t&, Data&);
0035 typedef boost::function<functor_type> functor_wrapper_type;
0036
0037
0038 template <typename F>
0039 void add_action(std::size_t unique_id, std::size_t, F act)
0040 {
0041 if (actions_.size() <= unique_id)
0042 actions_.resize(unique_id + 1);
0043
0044 actions_[unique_id] = act;
0045 }
0046
0047
0048 BOOST_SCOPED_ENUM(pass_flags) invoke_actions(std::size_t
0049 , std::size_t& id, std::size_t unique_id, Iterator& end
0050 , Data& data) const
0051 {
0052
0053 if (unique_id >= actions_.size() || !actions_[unique_id])
0054 return pass_flags::pass_normal;
0055
0056
0057
0058 BOOST_SCOPED_ENUM(pass_flags) match = pass_flags::pass_normal;
0059 actions_[unique_id](data.get_first(), end, match, id, data);
0060 return match;
0061 }
0062
0063 std::vector<functor_wrapper_type> actions_;
0064 };
0065
0066
0067
0068
0069
0070 template <typename Iterator, typename Data>
0071 struct semantic_actions<Iterator, mpl::true_, Data>
0072 {
0073 typedef void functor_type(Iterator&, Iterator&
0074 , BOOST_SCOPED_ENUM(pass_flags)&, std::size_t&, Data&);
0075 typedef boost::function<functor_type> functor_wrapper_type;
0076
0077
0078 template <typename F>
0079 void add_action(std::size_t unique_id, std::size_t state, F act)
0080 {
0081 if (actions_.size() <= state)
0082 actions_.resize(state + 1);
0083
0084 std::vector<functor_wrapper_type>& actions (actions_[state]);
0085 if (actions.size() <= unique_id)
0086 actions.resize(unique_id + 1);
0087
0088 actions[unique_id] = act;
0089 }
0090
0091
0092 BOOST_SCOPED_ENUM(pass_flags) invoke_actions(std::size_t state
0093 , std::size_t& id, std::size_t unique_id, Iterator& end
0094 , Data& data) const
0095 {
0096
0097 if (state >= actions_.size())
0098 return pass_flags::pass_normal;
0099
0100
0101 std::vector<functor_wrapper_type> const& actions = actions_[state];
0102 if (unique_id >= actions.size() || !actions[unique_id])
0103 return pass_flags::pass_normal;
0104
0105
0106 data.set_end(end);
0107
0108
0109
0110 BOOST_SCOPED_ENUM(pass_flags) match = pass_flags::pass_normal;
0111 actions[unique_id](data.get_first(), end, match, id, data);
0112 return match;
0113 }
0114
0115 std::vector<std::vector<functor_wrapper_type> > actions_;
0116 };
0117 }
0118
0119 }}}}
0120
0121 #endif