char_state_machine.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // char_state_machine.hpp
  2. // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_LEXER_CHAR_STATE_MACHINE_HPP
  7. #define BOOST_LEXER_CHAR_STATE_MACHINE_HPP
  8. #include "../consts.hpp"
  9. #include <map>
  10. #include "../size_t.hpp"
  11. #include "../string_token.hpp"
  12. #include <vector>
  13. namespace boost
  14. {
  15. namespace lexer
  16. {
  17. namespace detail
  18. {
  19. template<typename CharT>
  20. struct basic_char_state_machine
  21. {
  22. struct state
  23. {
  24. typedef basic_string_token<CharT> string_token;
  25. typedef std::map<std::size_t, string_token> size_t_string_token_map;
  26. typedef std::pair<std::size_t, string_token> size_t_string_token_pair;
  27. bool _end_state;
  28. std::size_t _id;
  29. std::size_t _unique_id;
  30. std::size_t _state;
  31. std::size_t _bol_index;
  32. std::size_t _eol_index;
  33. size_t_string_token_map _transitions;
  34. state () :
  35. _end_state (false),
  36. _id (0),
  37. _unique_id (npos),
  38. _state (0),
  39. _bol_index (npos),
  40. _eol_index (npos)
  41. {
  42. }
  43. };
  44. typedef std::vector<state> state_vector;
  45. typedef std::vector<state_vector> state_vector_vector;
  46. state_vector_vector _sm_vector;
  47. bool empty () const
  48. {
  49. return _sm_vector.empty ();
  50. }
  51. void clear ()
  52. {
  53. _sm_vector.clear ();
  54. }
  55. void swap (basic_char_state_machine &csm_)
  56. {
  57. _sm_vector.swap (csm_._sm_vector);
  58. }
  59. };
  60. typedef basic_char_state_machine<char> char_state_machine;
  61. typedef basic_char_state_machine<wchar_t> wchar_state_machine;
  62. }
  63. }
  64. }
  65. #endif