mark_matcher.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // mark_matcher.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_MARK_MATCHER_HPP_EAN_10_04_2005
  9. // MS compatible compilers support #pragma once
  10. #if defined(_MSC_VER)
  11. # pragma once
  12. #endif
  13. #include <boost/assert.hpp>
  14. #include <boost/xpressive/detail/detail_fwd.hpp>
  15. #include <boost/xpressive/detail/core/quant_style.hpp>
  16. #include <boost/xpressive/detail/core/state.hpp>
  17. #include <boost/xpressive/detail/utility/traits_utils.hpp>
  18. namespace boost { namespace xpressive { namespace detail
  19. {
  20. // TODO: the mark matcher is acually a fixed-width matcher, but the width is
  21. // not known until pattern match time.
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // mark_matcher
  24. //
  25. template<typename Traits, typename ICase>
  26. struct mark_matcher
  27. : quant_style_variable_width
  28. {
  29. typedef ICase icase_type;
  30. int mark_number_;
  31. mark_matcher(int mark_number, Traits const &)
  32. : mark_number_(mark_number)
  33. {
  34. }
  35. template<typename BidiIter, typename Next>
  36. bool match(match_state<BidiIter> &state, Next const &next) const
  37. {
  38. BOOST_ASSERT(this->mark_number_ < static_cast<int>(state.mark_count_));
  39. sub_match_impl<BidiIter> const &br = state.sub_match(this->mark_number_);
  40. if(!br.matched)
  41. {
  42. return false;
  43. }
  44. BidiIter const tmp = state.cur_;
  45. for(BidiIter begin = br.first, end = br.second; begin != end; ++begin, ++state.cur_)
  46. {
  47. if(state.eos()
  48. || detail::translate(*state.cur_, traits_cast<Traits>(state), icase_type())
  49. != detail::translate(*begin, traits_cast<Traits>(state), icase_type()))
  50. {
  51. state.cur_ = tmp;
  52. return false;
  53. }
  54. }
  55. if(next.match(state))
  56. {
  57. return true;
  58. }
  59. state.cur_ = tmp;
  60. return false;
  61. }
  62. };
  63. }}}
  64. #endif