<regex>: Avoid generating group nodes for non-capturing groups#6359
Open
muellerj3 wants to merge 2 commits into
Open
<regex>: Avoid generating group nodes for non-capturing groups#6359muellerj3 wants to merge 2 commits into
<regex>: Avoid generating group nodes for non-capturing groups#6359muellerj3 wants to merge 2 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Removes parser-generated no-op nodes for non-capturing regex groups while preserving ABI handling.
Changes:
- Tracks group boundaries to generate repetition nodes correctly.
- Splits grouped and non-grouped repetition handling.
- Adds regression coverage for grouped quantifiers and captures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
stl/inc/regex |
Removes non-capturing group nodes and revises repetition generation. |
tests/std/tests/VSO_0000000_regex_use/test.cpp |
Adds grouped-quantifier regression tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| template <class _FwdIt, class _Elem, class _RxTraits> | ||
| void _Builder3<_FwdIt, _Elem, _RxTraits>::_Generate_rep(_Node_base* _First_node, int _Min, int _Max, bool _Greedy) { | ||
| // generates a rep around the range from given start node to current node | ||
| if (_Min == 0 && _Max == 1 && _First_node == _Current) { |
Contributor
Author
There was a problem hiding this comment.
This is a good catch of a very subtle problem (even if the mishandled pattern seems very unlikely to appear in practice).
But I think this only affects positive assertions, because capture groups in negative assertions are never matched after the assertion has been processed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Towards #5962. Also helps a bit with #6347.
This completes the removal of
_N_groupand_N_end_groupnode generation from the parser (but have to continue handling such nodes in the matcher for ABI reasons). As a side effect, this also avoids generating any nodes for constructs like(?:)*.This is achieved by marking the position of a node just before a non-capturing or capturing group and using this mark to generate the repeat nodes around such a group if the group is followed by a quantifier. We store this mark in
_Group_start. If_Group_startis null, we know that the quantifier doesn't apply to a group, so the repeat nodes have to surround the node generated last only._Group_startis reset after handling the quantifier, so it can't accidentally affect the parsing of following alternatives. We also have to assign the mark to_Group_startafter the group has been fully parsed, otherwise the mark might be accidentally used in or reset by the recursive_Alternative()call.The code that handles a quantifier following a non-group already handles the generation of
_N_strnodes correctly. We have to handle this for a repeated group now as well:_Builder3::_Charsmight not be empty for a non-capturing group because we do not generate an_N_end_groupnode anymore that triggers the generation of the_N_strnode. This means that_Emit_str_node()must be called first in_Add_group_rep().