end_matcher.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // end_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_END_MATCHER_HPP_EAN_10_04_2005
  8. #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_END_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/core/sub_match_impl.hpp>
  18. #include <boost/xpressive/detail/core/flow_control.hpp>
  19. namespace boost { namespace xpressive { namespace detail
  20. {
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // end_matcher
  23. //
  24. struct end_matcher
  25. : quant_style_assertion
  26. {
  27. template<typename BidiIter, typename Next>
  28. static bool match(match_state<BidiIter> &state, Next const &)
  29. {
  30. BidiIter const tmp = state.cur_;
  31. sub_match_impl<BidiIter> &s0 = state.sub_match(0);
  32. BOOST_ASSERT(!s0.matched);
  33. // SPECIAL: if there is a match context on the context stack, then
  34. // this pattern has been nested within another. pop that context and
  35. // continue executing.
  36. if(0 != state.context_.prev_context_)
  37. {
  38. if(!pop_context_match(state))
  39. {
  40. return false;
  41. }
  42. // record the end of sub-match zero
  43. s0.first = s0.begin_;
  44. s0.second = tmp;
  45. s0.matched = true;
  46. return true;
  47. }
  48. else if((state.flags_.match_all_ && !state.eos()) ||
  49. (state.flags_.match_not_null_ && state.cur_ == s0.begin_))
  50. {
  51. return false;
  52. }
  53. // record the end of sub-match zero
  54. s0.first = s0.begin_;
  55. s0.second = tmp;
  56. s0.matched = true;
  57. // Now execute any actions that have been queued
  58. for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next)
  59. {
  60. actor->execute(state.action_args_);
  61. }
  62. return true;
  63. }
  64. };
  65. ///////////////////////////////////////////////////////////////////////////////
  66. // independent_end_matcher
  67. //
  68. struct independent_end_matcher
  69. : quant_style_assertion
  70. {
  71. template<typename BidiIter, typename Next>
  72. bool match(match_state<BidiIter> &state, Next const &) const
  73. {
  74. // Now execute any actions that have been queued
  75. for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next)
  76. {
  77. actor->execute(state.action_args_);
  78. }
  79. return true;
  80. }
  81. };
  82. }}}
  83. #endif