gh-152100: Support set operations in character classes#152153
Merged
Conversation
Implement set difference [A--B], intersection [A&&B] and union [A||B] in regular expression character classes (Unicode Technical Standard #18), including nested, complemented and compound set operands. Symmetric difference [A~~B] remains reserved. Also use the new syntax in the standard library (_strptime, textwrap, doctest, pkgutil). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documentation build overview
|
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.
Implement UTS #18 RL1.3 set operations in regular expression character classes: difference
[A--B], intersection[A&&B]and union[A||B], with nested, complemented and compound operands and arbitrary left-to-right chaining ([a-z--[aeiou]&&\w]). Symmetric difference[A~~B]remains reserved (still aFutureWarning).These tokens (
--,&&,||, and nested[) have been reserved since 3.7 viaFutureWarning, so this turns the warnings into real syntax.The feature is parser-only: each operation maps to an assertion on the matched character —
[A--B]→A(?<![B]),[A&&B]→A(?<=[B]),[A||B]→ a merged charset[AB]or an alternation — so no charset complement is ever formed and the result is correct underIGNORECASE. A leading^negates by De Morgan, pushing the negation into the operands. The engine andMAGICare untouched.A
[opens a nested set only immediately after a set operator; at the start of a class it stays an ordinary literal, so existing patterns such as[[:alpha:]]and glob's[*?[]keep their meaning.The new syntax is also used in the standard library (
_strptime,textwrap,doctest,pkgutil).🤖 Generated with Claude Code