33 namespace std _GLIBCXX_VISIBILITY(default)
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 template<
bool __match_mode>
47 const auto& __state = (*_M_nfa)[__i];
49 switch (__state._M_opcode)
51 case _S_opcode_alternative:
55 __ret = _M_dfs<__match_mode>(__state._M_alt)
56 || _M_dfs<__match_mode>(__state._M_next);
58 case _S_opcode_subexpr_begin:
59 __state._M_tagger(_M_str_cur, _M_results);
60 __ret = _M_dfs<__match_mode>(__state._M_next);
62 case _S_opcode_subexpr_end:
63 __state._M_tagger(_M_str_cur, _M_results);
64 __ret = _M_dfs<__match_mode>(__state._M_next);
65 _M_results._M_set_matched(__state._M_subexpr, __ret);
68 if (!_M_str_cur._M_at_end() && __state._M_matches(_M_str_cur))
71 __ret = _M_dfs<__match_mode>(__state._M_next);
75 case _S_opcode_accept:
77 __ret = _M_str_cur._M_at_end();
82 _GLIBCXX_DEBUG_ASSERT(
false);
87 template<
bool __match_mode>
91 while (!_M_str_cur._M_at_end())
94 if (_M_includes_some())
100 return _M_includes_some();
111 for (
auto& __it : _M_current)
113 __in_q[__it.first] =
true;
114 __q.
push(__it.first);
118 auto __u = __q.
front();
121 const auto& __state = (*_M_nfa)[__u];
124 auto __add_visited_state = [&](
_StateIdT __v)
128 if (_M_match_less_than(__u, __v))
130 _M_current[__v] = _M_current[__u]->_M_clone();
141 switch (__state._M_opcode)
143 case _S_opcode_alternative:
144 __add_visited_state(__state._M_next);
145 __add_visited_state(__state._M_alt);
147 case _S_opcode_subexpr_begin:
148 __state._M_tagger(_M_str_cur, *_M_current[__u]);
149 __add_visited_state(__state._M_next);
151 case _S_opcode_subexpr_end:
152 __state._M_tagger(_M_str_cur, *_M_current[__u]);
153 _M_current[__u]->_M_set_matched(__state._M_subexpr,
true);
154 __add_visited_state(__state._M_next);
156 case _S_opcode_match:
158 case _S_opcode_accept:
159 __add_visited_state(__state._M_next);
162 _GLIBCXX_DEBUG_ASSERT(
false);
172 decltype(_M_current) __next;
173 for (auto& __it : _M_current)
175 const auto& __state = (*_M_nfa)[__it.first];
176 if (__state._M_opcode == _S_opcode_match
177 && __state._M_matches(_M_str_cur))
178 if (_M_match_less_than(__it.first, __state._M_next)
180 __next[__state._M_next] = __it.second->_M_clone();
182 _M_current = move(__next);
190 if (_M_current.count(__u) == 0)
192 if (_M_current.count(__v) > 0)
201 _M_includes_some()
const
203 auto& __s = _M_nfa->_M_final_states();
204 auto& __t = _M_current;
205 if (__s.size() > 0 && __t.size() > 0)
207 auto __first = __s.begin();
208 auto __second = __t.begin();
209 while (__first != __s.end() && __second != __t.end())
211 if (*__first < __second->first)
213 else if (__second->first < *__first)
217 _M_results._M_assign(*__second->second);
228 _M_get_matcher(_PatternCursor& __p,
234 return unique_ptr<_Grep_matcher>(
235 new _DFSMatcher(__p, __r, __a, __flags));
237 return unique_ptr<_Grep_matcher>(
238 new _BFSMatcher(__p, __r, __a, __flags));
241 _GLIBCXX_END_NAMESPACE_VERSION