]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
8 | #ifndef BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_END_MATCHER_HPP_EAN_10_04_2005 | |
9 | #define BOOST_XPRESSIVE_DETAIL_CORE_MATCHER_END_MATCHER_HPP_EAN_10_04_2005 | |
10 | ||
11 | // MS compatible compilers support #pragma once | |
12 | #if defined(_MSC_VER) | |
13 | # pragma once | |
14 | #endif | |
15 | ||
16 | #include <boost/assert.hpp> | |
17 | #include <boost/xpressive/detail/detail_fwd.hpp> | |
18 | #include <boost/xpressive/detail/core/quant_style.hpp> | |
19 | #include <boost/xpressive/detail/core/state.hpp> | |
20 | #include <boost/xpressive/detail/core/sub_match_impl.hpp> | |
21 | #include <boost/xpressive/detail/core/flow_control.hpp> | |
22 | ||
23 | namespace boost { namespace xpressive { namespace detail | |
24 | { | |
25 | ||
26 | /////////////////////////////////////////////////////////////////////////////// | |
27 | // end_matcher | |
28 | // | |
29 | struct end_matcher | |
30 | : quant_style_assertion | |
31 | { | |
32 | template<typename BidiIter, typename Next> | |
33 | static bool match(match_state<BidiIter> &state, Next const &) | |
34 | { | |
35 | BidiIter const tmp = state.cur_; | |
36 | sub_match_impl<BidiIter> &s0 = state.sub_match(0); | |
37 | BOOST_ASSERT(!s0.matched); | |
38 | ||
39 | // SPECIAL: if there is a match context on the context stack, then | |
40 | // this pattern has been nested within another. pop that context and | |
41 | // continue executing. | |
42 | if(0 != state.context_.prev_context_) | |
43 | { | |
44 | if(!pop_context_match(state)) | |
45 | { | |
46 | return false; | |
47 | } | |
48 | ||
49 | // record the end of sub-match zero | |
50 | s0.first = s0.begin_; | |
51 | s0.second = tmp; | |
52 | s0.matched = true; | |
53 | ||
54 | return true; | |
55 | } | |
56 | else if((state.flags_.match_all_ && !state.eos()) || | |
57 | (state.flags_.match_not_null_ && state.cur_ == s0.begin_)) | |
58 | { | |
59 | return false; | |
60 | } | |
61 | ||
62 | // record the end of sub-match zero | |
63 | s0.first = s0.begin_; | |
64 | s0.second = tmp; | |
65 | s0.matched = true; | |
66 | ||
67 | // Now execute any actions that have been queued | |
68 | for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next) | |
69 | { | |
70 | actor->execute(state.action_args_); | |
71 | } | |
72 | ||
73 | return true; | |
74 | } | |
75 | }; | |
76 | ||
77 | /////////////////////////////////////////////////////////////////////////////// | |
78 | // independent_end_matcher | |
79 | // | |
80 | struct independent_end_matcher | |
81 | : quant_style_assertion | |
82 | { | |
83 | template<typename BidiIter, typename Next> | |
84 | bool match(match_state<BidiIter> &state, Next const &) const | |
85 | { | |
86 | // Now execute any actions that have been queued | |
87 | for(actionable const *actor = state.action_list_.next; 0 != actor; actor = actor->next) | |
88 | { | |
89 | actor->execute(state.action_args_); | |
90 | } | |
91 | ||
92 | return true; | |
93 | } | |
94 | }; | |
95 | ||
96 | }}} | |
97 | ||
98 | #endif |