Skip to content

Commit f9e8afa

Browse files
1 parent 5fc17e0 commit f9e8afa

File tree

2 files changed

+342
-24
lines changed

2 files changed

+342
-24
lines changed

Diff for: stl/inc/regex

+16-24
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,6 @@ public:
15111511
using _Difft = typename iterator_traits<_FwdIt>::difference_type;
15121512

15131513
_Builder(const _RxTraits& _Tr, regex_constants::syntax_option_type);
1514-
bool _Beg_expr() const;
15151514
void _Setlong();
15161515
// _Discard_pattern is an ABI zombie name
15171516
void _Tidy() noexcept;
@@ -1547,7 +1546,6 @@ private:
15471546
static void _Insert_node(_Node_base*, _Node_base*);
15481547
_Node_base* _New_node(_Node_type _Kind);
15491548
void _Add_str_node();
1550-
bool _Beg_expr(_Node_base*) const;
15511549
void _Add_char_to_bitmap(_Elem _Ch);
15521550
void _Add_char_to_array(_Elem _Ch);
15531551
void _Add_elts(_Node_class<_Elem, _RxTraits>*, typename _RxTraits::char_class_type, bool);
@@ -2784,17 +2782,6 @@ _Node_base* _Builder<_FwdIt, _Elem, _RxTraits>::_Getmark() const {
27842782
return _Current;
27852783
}
27862784

2787-
template <class _FwdIt, class _Elem, class _RxTraits>
2788-
bool _Builder<_FwdIt, _Elem, _RxTraits>::_Beg_expr(_Node_base* _Nx) const {
2789-
// test for beginning of expression or subexpression
2790-
return _Nx->_Kind == _N_begin || _Nx->_Kind == _N_group || _Nx->_Kind == _N_capture;
2791-
}
2792-
2793-
template <class _FwdIt, class _Elem, class _RxTraits>
2794-
bool _Builder<_FwdIt, _Elem, _RxTraits>::_Beg_expr() const { // test for beginning of expression or subexpression
2795-
return _Beg_expr(_Current) || (_Current->_Kind == _N_bol && _Beg_expr(_Current->_Prev));
2796-
}
2797-
27982785
template <class _FwdIt, class _Elem, class _RxTraits>
27992786
_Node_base* _Builder<_FwdIt, _Elem, _RxTraits>::_Link_node(_Node_base* _Nx) { // insert _Nx at current location
28002787
_Nx->_Prev = _Current;
@@ -3905,17 +3892,16 @@ void _Parser<_FwdIt, _Elem, _RxTraits>::_Trans() { // map character to meta-char
39053892
break;
39063893

39073894
case _Meta_star:
3908-
if ((_L_flags & _L_star_beg) && _Nfa._Beg_expr()) {
3909-
_Mchar = _Meta_chr;
3910-
}
3911-
3895+
// A star can always act as a quantifier outside bracket expressions,
3896+
// but _L_star_beg (used by basic/grep) allows its use as an ordinary character
3897+
// at the beginning of a (sub-)expression (potentially after an optional caret anchor).
3898+
// We'll handle that when we are parsing alternatives in disjunctions.
39123899
break;
39133900

39143901
case _Meta_caret:
3915-
if ((_L_flags & _L_anch_rstr) && !_Nfa._Beg_expr()) {
3916-
_Mchar = _Meta_chr;
3917-
}
3918-
3902+
// A caret can always negate a bracket expression,
3903+
// but _L_anch_rstr (used by basic/grep) restricts caret anchors to the beginning.
3904+
// We'll handle that restriction when we're about to add a bol node.
39193905
break;
39203906

39213907
case _Meta_dlr:
@@ -4481,15 +4467,21 @@ bool _Parser<_FwdIt, _Elem, _RxTraits>::_Alternative() { // check for valid alte
44814467
_Next();
44824468
_Quant = _Wrapped_disjunction();
44834469
_Expect(_Meta_rpar, regex_constants::error_paren);
4484-
} else if (_Mchar == _Meta_caret) { // add bol node
4470+
} else if (_Mchar == _Meta_caret && (!(_L_flags & _L_anch_rstr) || !_Found)) { // add bol node
44854471
_Nfa._Add_bol();
44864472
_Next();
4487-
_Quant = false;
4473+
if ((_L_flags & _L_star_beg) && _Mchar == _Meta_star && !_Found) {
4474+
_Nfa._Add_char(_Char);
4475+
_Next();
4476+
} else {
4477+
_Quant = false;
4478+
}
44884479
} else if (_Mchar == _Meta_dlr) { // add eol node
44894480
_Nfa._Add_eol();
44904481
_Next();
44914482
_Quant = false;
4492-
} else if (_Mchar == _Meta_star || _Mchar == _Meta_plus || _Mchar == _Meta_query || _Mchar == _Meta_lbr) {
4483+
} else if ((_Mchar == _Meta_star && (!(_L_flags & _L_star_beg) || _Found)) || _Mchar == _Meta_plus
4484+
|| _Mchar == _Meta_query || _Mchar == _Meta_lbr) {
44934485
_Error(regex_constants::error_badrepeat);
44944486
} else if (_Mchar == _Meta_rbr && !(_L_flags & _L_paren_bal)) {
44954487
_Error(regex_constants::error_brace);

0 commit comments

Comments
 (0)