File indexing completed on 2025-01-31 10:02:16
0001
0002
0003
0004
0005
0006 #if !defined(BOOST_SPIRIT_LEX_STATIC_LEXER_FEB_10_2008_0753PM)
0007 #define BOOST_SPIRIT_LEX_STATIC_LEXER_FEB_10_2008_0753PM
0008
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012
0013 #include <boost/spirit/home/lex/lexer/lexertl/token.hpp>
0014 #include <boost/spirit/home/lex/lexer/lexertl/functor.hpp>
0015 #include <boost/spirit/home/lex/lexer/lexertl/static_functor_data.hpp>
0016 #include <boost/spirit/home/lex/lexer/lexertl/iterator.hpp>
0017 #include <boost/spirit/home/lex/lexer/lexertl/static_version.hpp>
0018 #if defined(BOOST_SPIRIT_DEBUG)
0019 #include <boost/spirit/home/support/detail/lexer/debug.hpp>
0020 #endif
0021 #include <iterator> // for std::iterator_traits
0022
0023 namespace boost { namespace spirit { namespace lex { namespace lexertl
0024 {
0025
0026
0027
0028 namespace static_
0029 {
0030 struct lexer;
0031 }
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 template <typename Token = token<>
0110 , typename LexerTables = static_::lexer
0111 , typename Iterator = typename Token::iterator_type
0112 , typename Functor = functor<Token, detail::static_data, Iterator> >
0113 class static_lexer
0114 {
0115 private:
0116 struct dummy { void true_() {} };
0117 typedef void (dummy::*safe_bool)();
0118
0119 public:
0120
0121 operator safe_bool() const { return &dummy::true_; }
0122
0123 typedef typename std::iterator_traits<Iterator>::value_type char_type;
0124 typedef std::basic_string<char_type> string_type;
0125
0126
0127
0128 typedef Token token_type;
0129 typedef typename Token::id_type id_type;
0130 typedef iterator<Functor> iterator_type;
0131
0132 private:
0133 #ifdef _MSC_VER
0134 # pragma warning(push)
0135 # pragma warning(disable: 4512)
0136 #endif
0137
0138 struct iterator_data_type
0139 {
0140 typedef typename Functor::next_token_functor next_token_functor;
0141 typedef typename Functor::semantic_actions_type semantic_actions_type;
0142 typedef typename Functor::get_state_name_type get_state_name_type;
0143
0144 iterator_data_type(next_token_functor next
0145 , semantic_actions_type const& actions
0146 , get_state_name_type get_state_name, std::size_t num_states
0147 , bool bol)
0148 : next_(next), actions_(actions), get_state_name_(get_state_name)
0149 , num_states_(num_states), bol_(bol)
0150 {}
0151
0152 next_token_functor next_;
0153 semantic_actions_type const& actions_;
0154 get_state_name_type get_state_name_;
0155 std::size_t num_states_;
0156 bool bol_;
0157 };
0158 #ifdef _MSC_VER
0159 # pragma warning(pop)
0160 #endif
0161
0162 typedef LexerTables tables_type;
0163
0164
0165
0166
0167
0168 BOOST_SPIRIT_ASSERT_MSG(
0169 tables_type::static_version == SPIRIT_STATIC_LEXER_VERSION
0170 , incompatible_static_lexer_version, (LexerTables));
0171
0172 public:
0173
0174
0175
0176 template <typename Iterator_>
0177 iterator_type begin(Iterator_& first, Iterator_ const& last
0178 , char_type const* initial_state = 0) const
0179 {
0180 iterator_data_type iterator_data(
0181 &tables_type::template next<Iterator_>, actions_
0182 , &tables_type::state_name, tables_type::state_count()
0183 , tables_type::supports_bol
0184 );
0185 return iterator_type(iterator_data, first, last, initial_state);
0186 }
0187
0188
0189
0190 iterator_type end() const
0191 {
0192 return iterator_type();
0193 }
0194
0195 protected:
0196
0197 static_lexer(unsigned int) : unique_id_(0) {}
0198
0199 public:
0200
0201 std::size_t add_token (char_type const*, char_type, std::size_t
0202 , char_type const*)
0203 {
0204 return unique_id_++;
0205 }
0206 std::size_t add_token (char_type const*, string_type const&
0207 , std::size_t, char_type const*)
0208 {
0209 return unique_id_++;
0210 }
0211
0212
0213 void add_pattern (char_type const*, string_type const&
0214 , string_type const&) {}
0215
0216 void clear(char_type const*) {}
0217
0218 std::size_t add_state(char_type const* state)
0219 {
0220 return detail::get_state_id(state, &tables_type::state_name
0221 , tables_type::state_count());
0222 }
0223 string_type initial_state() const
0224 {
0225 return tables_type::state_name(0);
0226 }
0227
0228
0229 template <typename F>
0230 void add_action(id_type unique_id, std::size_t state, F act)
0231 {
0232 typedef typename Functor::wrap_action_type wrapper_type;
0233 actions_.add_action(unique_id, state, wrapper_type::call(act));
0234 }
0235
0236 bool init_dfa(bool = false) const { return true; }
0237
0238 private:
0239 typename Functor::semantic_actions_type actions_;
0240 std::size_t unique_id_;
0241 };
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 template <typename Token = token<>
0266 , typename LexerTables = static_::lexer
0267 , typename Iterator = typename Token::iterator_type
0268 , typename Functor
0269 = functor<Token, detail::static_data, Iterator, mpl::true_> >
0270 class static_actor_lexer
0271 : public static_lexer<Token, LexerTables, Iterator, Functor>
0272 {
0273 protected:
0274
0275 static_actor_lexer(unsigned int flags)
0276 : static_lexer<Token, LexerTables, Iterator, Functor>(flags)
0277 {}
0278 };
0279
0280 }}}}
0281
0282 #endif