Skip to content

Make RegexBuilder quantifiers follow option settings #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2022

Conversation

natecook1000
Copy link
Member

This changes the RegexBuilder quantifiers to take an optional behavior, so that by default they can follow the current options setting. An explicitly provided behavior is always used.

This is how the regex syntax operator works:

let _ = /\w+/           // eager one-or-more operator
let _ = /\w+?/          // reluctant one-or-more operator
// (?U) toggles eager/reluctance
let _ = /(?U)\w+/       // reluctant one-or-more operator
let _ = /(?U)\w+?/      // eager one-or-more operator

In RegexBuilder regexes, we get support for (?U) via the reluctantQuantifiers() modifier method:

let _ = Regex {
    OneOrMore(.word)             // reluctant due to option method below
    OneOrMore(.word, .eagerly)   // eager due to explicit behavior parameter
}.reluctantQuantifiers()

@natecook1000 natecook1000 requested a review from rxwei April 18, 2022 19:11
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit fea6fe2 into swiftlang:main Apr 18, 2022
@natecook1000 natecook1000 deleted the quanitfier_default_behavior branch April 18, 2022 19:47
Azoy pushed a commit to Azoy/swift-experimental-string-processing that referenced this pull request Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants