/Src/Dependencies/Boost/boost/spirit/home/lex/lexer/lexertl/iterator.hpp

http://hadesmem.googlecode.com/ · C++ Header · 121 lines · 77 code · 19 blank · 25 comment · 1 complexity · 9a314a1caf1cce96af8a17108f89678c MD5 · raw file

  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_SPIRIT_LEX_LEXER_ITERATOR_MAR_16_2007_0353PM)
  6. #define BOOST_SPIRIT_LEX_LEXER_ITERATOR_MAR_16_2007_0353PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #if defined(BOOST_SPIRIT_DEBUG)
  11. #include <boost/spirit/home/support/iterators/detail/buf_id_check_policy.hpp>
  12. #else
  13. #include <boost/spirit/home/support/iterators/detail/no_check_policy.hpp>
  14. #endif
  15. #include <boost/spirit/home/support/iterators/detail/split_functor_input_policy.hpp>
  16. #include <boost/spirit/home/support/iterators/detail/ref_counted_policy.hpp>
  17. #include <boost/spirit/home/support/iterators/detail/split_std_deque_policy.hpp>
  18. #include <boost/spirit/home/support/iterators/multi_pass.hpp>
  19. namespace boost { namespace spirit { namespace lex { namespace lexertl
  20. {
  21. ///////////////////////////////////////////////////////////////////////////
  22. template <typename FunctorData>
  23. struct make_multi_pass
  24. {
  25. // Divide the given functor type into its components (unique and
  26. // shared) and build a std::pair from these parts
  27. typedef std::pair<typename FunctorData::unique
  28. , typename FunctorData::shared> functor_data_type;
  29. // This is the result type returned from the iterator
  30. typedef typename FunctorData::result_type result_type;
  31. // Compose the multi_pass iterator policy type from the appropriate
  32. // policies
  33. typedef iterator_policies::split_functor_input input_policy;
  34. typedef iterator_policies::ref_counted ownership_policy;
  35. #if defined(BOOST_SPIRIT_DEBUG)
  36. typedef iterator_policies::buf_id_check check_policy;
  37. #else
  38. typedef iterator_policies::no_check check_policy;
  39. #endif
  40. typedef iterator_policies::split_std_deque storage_policy;
  41. typedef iterator_policies::default_policy<
  42. ownership_policy, check_policy, input_policy, storage_policy>
  43. policy_type;
  44. // Compose the multi_pass iterator from the policy
  45. typedef spirit::multi_pass<functor_data_type, policy_type> type;
  46. };
  47. ///////////////////////////////////////////////////////////////////////////
  48. // lexer_iterator exposes an iterator for a lexertl based dfa (lexer)
  49. // The template parameters have the same semantics as described for the
  50. // functor above.
  51. ///////////////////////////////////////////////////////////////////////////
  52. template <typename Functor>
  53. class iterator : public make_multi_pass<Functor>::type
  54. {
  55. public:
  56. typedef typename Functor::unique unique_functor_type;
  57. typedef typename Functor::shared shared_functor_type;
  58. typedef typename Functor::iterator_type base_iterator_type;
  59. typedef typename Functor::result_type token_type;
  60. private:
  61. typedef typename make_multi_pass<Functor>::functor_data_type
  62. functor_type;
  63. typedef typename make_multi_pass<Functor>::type base_type;
  64. typedef typename Functor::char_type char_type;
  65. public:
  66. // create a new iterator encapsulating the lexer object to be used
  67. // for tokenization
  68. template <typename IteratorData>
  69. iterator(IteratorData const& iterdata_, base_iterator_type& first
  70. , base_iterator_type const& last, char_type const* state = 0)
  71. : base_type(functor_type(unique_functor_type()
  72. , shared_functor_type(iterdata_, first, last)))
  73. {
  74. set_state(map_state(state));
  75. }
  76. // create an end iterator usable for end of range checking
  77. iterator() {}
  78. // (wash): < mgaunard> T it; T it2 = ++it; doesn't ocmpile
  79. // < mgaunard> this gets fixed by adding
  80. iterator(const base_type& base)
  81. : base_type(base) { }
  82. // set the new required state for the underlying lexer object
  83. std::size_t set_state(std::size_t state)
  84. {
  85. return unique_functor_type::set_state(*this, state);
  86. }
  87. // get the curent state for the underlying lexer object
  88. std::size_t get_state()
  89. {
  90. return unique_functor_type::get_state(*this);
  91. }
  92. // map the given state name to a corresponding state id as understood
  93. // by the underlying lexer object
  94. std::size_t map_state(char_type const* statename)
  95. {
  96. return (0 != statename)
  97. ? unique_functor_type::map_state(*this, statename)
  98. : 0;
  99. }
  100. };
  101. }}}}
  102. #endif