56 namespace std _GLIBCXX_VISIBILITY(default)
60 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 template<
typename _FwdIter,
typename _TraitsT>
63 _Compiler<_FwdIter, _TraitsT>::
64 _Compiler(_FwdIter __b, _FwdIter __e,
65 const _TraitsT& __traits, _FlagT __flags)
68 | regex_constants::
basic
70 | regex_constants::
grep
71 | regex_constants::
egrep
72 | regex_constants::
awk))
76 _M_ctype(std::
use_facet<_CtypeT>(_M_traits.getloc())),
77 _M_scanner(__b, __e, _M_flags, _M_traits.getloc()),
80 _StateSeqT __r(_M_nfa, _M_nfa._M_start());
81 __r._M_append(_M_nfa._M_insert_subexpr_begin());
82 this->_M_disjunction();
83 if (!_M_match_token(_ScannerT::_S_token_eof))
85 __r._M_append(_M_pop());
86 _GLIBCXX_DEBUG_ASSERT(_M_stack.empty());
87 __r._M_append(_M_nfa._M_insert_subexpr_end());
88 __r._M_append(_M_nfa._M_insert_accept());
89 _M_nfa._M_eliminate_dummy();
92 template<
typename _FwdIter,
typename _TraitsT>
94 _Compiler<_FwdIter, _TraitsT>::
97 this->_M_alternative();
98 while (_M_match_token(_ScannerT::_S_token_or))
100 _StateSeqT __alt1 = _M_pop();
101 this->_M_alternative();
102 _StateSeqT __alt2 = _M_pop();
103 auto __end = _M_nfa._M_insert_dummy();
104 __alt1._M_append(__end);
105 __alt2._M_append(__end);
106 _M_stack.push(_StateSeqT(_M_nfa,
107 _M_nfa._M_insert_alt(__alt1._M_start,
108 __alt2._M_start,
false),
113 template<
typename _FwdIter,
typename _TraitsT>
115 _Compiler<_FwdIter, _TraitsT>::
120 _StateSeqT __re = _M_pop();
121 this->_M_alternative();
122 __re._M_append(_M_pop());
126 _M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_dummy()));
129 template<
typename _FwdIter,
typename _TraitsT>
131 _Compiler<_FwdIter, _TraitsT>::
134 if (this->_M_assertion())
138 this->_M_quantifier();
144 template<
typename _FwdIter,
typename _TraitsT>
146 _Compiler<_FwdIter, _TraitsT>::
149 if (_M_match_token(_ScannerT::_S_token_line_begin))
150 _M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_line_begin()));
151 else if (_M_match_token(_ScannerT::_S_token_line_end))
152 _M_stack.push(_StateSeqT(_M_nfa, _M_nfa._M_insert_line_end()));
153 else if (_M_match_token(_ScannerT::_S_token_word_bound))
155 _M_stack.push(_StateSeqT(_M_nfa, _M_nfa.
156 _M_insert_word_bound(_M_value[0] ==
'n')));
157 else if (_M_match_token(_ScannerT::_S_token_subexpr_lookahead_begin))
159 auto __neg = _M_value[0] ==
'n';
160 this->_M_disjunction();
161 if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
163 auto __tmp = _M_pop();
164 __tmp._M_append(_M_nfa._M_insert_accept());
168 _M_nfa._M_insert_lookahead(__tmp._M_start, __neg)));
175 template<
typename _FwdIter,
typename _TraitsT>
177 _Compiler<_FwdIter, _TraitsT>::
181 auto __init = [
this, &__neg]()
183 if (_M_stack.empty())
185 __neg = __neg && _M_match_token(_ScannerT::_S_token_opt);
187 if (_M_match_token(_ScannerT::_S_token_closure0))
191 _StateSeqT __r(_M_nfa, _M_nfa._M_insert_alt(_S_invalid_state_id,
192 __e._M_start, __neg));
196 else if (_M_match_token(_ScannerT::_S_token_closure1))
200 __e._M_append(_M_nfa._M_insert_alt(_S_invalid_state_id, __e._M_start,
204 else if (_M_match_token(_ScannerT::_S_token_opt))
208 auto __end = _M_nfa._M_insert_dummy();
209 _StateSeqT __r(_M_nfa, _M_nfa._M_insert_alt(_S_invalid_state_id,
210 __e._M_start, __neg));
211 __e._M_append(__end);
212 __r._M_append(__end);
215 else if (_M_match_token(_ScannerT::_S_token_interval_begin))
217 if (_M_stack.empty())
219 if (!_M_match_token(_ScannerT::_S_token_dup_count))
221 _StateSeqT __r(_M_pop());
222 _StateSeqT __e(_M_nfa, _M_nfa._M_insert_dummy());
223 long __min_rep = _M_cur_int_value(10);
228 if (_M_match_token(_ScannerT::_S_token_comma))
229 if (_M_match_token(_ScannerT::_S_token_dup_count))
230 __n = _M_cur_int_value(10) - __min_rep;
235 if (!_M_match_token(_ScannerT::_S_token_interval_end))
238 __neg = __neg && _M_match_token(_ScannerT::_S_token_opt);
240 for (
long __i = 0; __i < __min_rep; ++__i)
241 __e._M_append(__r._M_clone());
245 auto __tmp = __r._M_clone();
246 _StateSeqT __s(_M_nfa,
247 _M_nfa._M_insert_alt(_S_invalid_state_id,
248 __tmp._M_start, __neg));
249 __tmp._M_append(__s);
256 auto __end = _M_nfa._M_insert_dummy();
261 for (
long __i = 0; __i < __n; ++__i)
263 auto __tmp = __r._M_clone();
264 auto __alt = _M_nfa._M_insert_alt(__tmp._M_start,
267 __e._M_append(_StateSeqT(_M_nfa, __alt, __tmp._M_end));
269 __e._M_append(__end);
270 while (!__stack.empty())
272 auto& __tmp = _M_nfa[__stack.
top()];
274 swap(__tmp._M_next, __tmp._M_alt);
281 template<
typename _FwdIter,
typename _TraitsT>
283 _Compiler<_FwdIter, _TraitsT>::
286 if (_M_match_token(_ScannerT::_S_token_anychar))
287 _M_stack.push(_StateSeqT(_M_nfa,
288 _M_nfa._M_insert_matcher
289 (_AnyMatcher<_TraitsT>(_M_traits))));
290 else if (_M_try_char())
291 _M_stack.push(_StateSeqT(_M_nfa,
292 _M_nfa._M_insert_matcher
293 (_CharMatcher<_TraitsT>(_M_value[0],
296 else if (_M_match_token(_ScannerT::_S_token_backref))
297 _M_stack.push(_StateSeqT(_M_nfa, _M_nfa.
298 _M_insert_backref(_M_cur_int_value(10))));
299 else if (_M_match_token(_ScannerT::_S_token_quoted_class))
301 _GLIBCXX_DEBUG_ASSERT(_M_value.size() == 1);
302 _BMatcherT __matcher(_M_ctype.is(_CtypeT::upper, _M_value[0]),
303 _M_traits, _M_flags);
304 __matcher._M_add_character_class(_M_value);
305 _M_stack.push(_StateSeqT(_M_nfa,
306 _M_nfa._M_insert_matcher(std::move(__matcher))));
308 else if (_M_match_token(_ScannerT::_S_token_subexpr_no_group_begin))
310 _StateSeqT __r(_M_nfa, _M_nfa._M_insert_dummy());
311 this->_M_disjunction();
312 if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
314 __r._M_append(_M_pop());
317 else if (_M_match_token(_ScannerT::_S_token_subexpr_begin))
319 _StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin());
320 this->_M_disjunction();
321 if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
323 __r._M_append(_M_pop());
324 __r._M_append(_M_nfa._M_insert_subexpr_end());
327 else if (!_M_bracket_expression())
332 template<
typename _FwdIter,
typename _TraitsT>
334 _Compiler<_FwdIter, _TraitsT>::
335 _M_bracket_expression()
338 _M_match_token(_ScannerT::_S_token_bracket_neg_begin);
339 if (!(__neg || _M_match_token(_ScannerT::_S_token_bracket_begin)))
341 _BMatcherT __matcher(__neg, _M_traits, _M_flags);
342 while (!_M_match_token(_ScannerT::_S_token_bracket_end))
343 _M_expression_term(__matcher);
344 _M_stack.push(_StateSeqT(_M_nfa,
345 _M_nfa._M_insert_matcher(std::move(__matcher))));
349 template<
typename _FwdIter,
typename _TraitsT>
351 _Compiler<_FwdIter, _TraitsT>::
352 _M_expression_term(_BMatcherT& __matcher)
354 if (_M_match_token(_ScannerT::_S_token_collsymbol))
355 __matcher._M_add_collating_element(_M_value);
356 else if (_M_match_token(_ScannerT::_S_token_equiv_class_name))
357 __matcher._M_add_equivalence_class(_M_value);
358 else if (_M_match_token(_ScannerT::_S_token_char_class_name))
359 __matcher._M_add_character_class(_M_value);
360 else if (_M_try_char())
362 auto __ch = _M_value[0];
365 if (_M_value[0] ==
'-')
369 __matcher._M_make_range(__ch, _M_value[0]);
374 if (_M_scanner._M_get_token()
375 != _ScannerT::_S_token_bracket_end)
378 __matcher._M_add_char(_M_value[0]);
380 __matcher._M_add_char(__ch);
386 template<
typename _FwdIter,
typename _TraitsT>
388 _Compiler<_FwdIter, _TraitsT>::
391 bool __is_char =
false;
392 if (_M_match_token(_ScannerT::_S_token_oct_num))
395 _M_value.assign(1, _M_cur_int_value(8));
397 else if (_M_match_token(_ScannerT::_S_token_hex_num))
400 _M_value.assign(1, _M_cur_int_value(16));
402 else if (_M_match_token(_ScannerT::_S_token_ord_char))
407 template<
typename _FwdIter,
typename _TraitsT>
409 _Compiler<_FwdIter, _TraitsT>::
410 _M_match_token(_TokenT token)
412 if (token == _M_scanner._M_get_token())
414 _M_value = _M_scanner._M_get_value();
415 _M_scanner._M_advance();
421 template<
typename _FwdIter,
typename _TraitsT>
423 _Compiler<_FwdIter, _TraitsT>::
424 _M_cur_int_value(
int __radix)
427 for (
typename _StringT::size_type __i = 0;
428 __i < _M_value.length(); ++__i)
429 __v =__v * __radix + _M_traits.value(_M_value[__i], __radix);
433 template<
typename _TraitsT>
435 _BracketMatcher<_TraitsT>::operator()(_CharT __ch)
const
438 if (_M_traits.isctype(__ch, _M_class_set)
439 || _M_char_set.count(_M_translate(__ch))
440 || _M_equiv_set.count(_M_traits.transform_primary(&__ch, &__ch+1)))
445 ? _M_translate(__ch) : __ch);
446 for (
auto& __it : _M_range_set)
447 if (__it.first <= __s && __s <= __it.second)
453 if (_M_is_non_matching)
459 _GLIBCXX_END_NAMESPACE_VERSION
const _Facet & use_facet(const locale &__loc)
Return a facet.use_facet looks for and returns a reference to a facet of type Facet where Facet is th...
void pop()
Removes first element.
constexpr error_type error_badrepeat(_S_error_badrepeat)
constexpr error_type error_range(_S_error_range)
constexpr error_type error_brack(_S_error_brack)
constexpr error_type error_badbrace(_S_error_badbrace)
void push(const value_type &__x)
Add data to the top of the stack.
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
constexpr error_type error_paren(_S_error_paren)
A standard container giving FILO behavior.
constexpr error_type error_brace(_S_error_brace)