Skip to content

Allow setting any of the three quant behaviors #311

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 6 commits into from
Apr 21, 2022

Conversation

natecook1000
Copy link
Member

This also moves QuantificationBehavior from the RegexBuilder module down to _StringProcessing, and renames it RegexQuantificationBehavior.

This also moves QuantificationBehavior from the RegexBuilder module
down to _StringProcessing, and renames it RegexQuantificationBehavior.
@natecook1000 natecook1000 requested a review from milseman April 21, 2022 15:08
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@@ -41,7 +41,11 @@ extension AST {
case graphemeClusterSemantics // X
case unicodeScalarSemantics // u
case byteSemantics // b

// Swift-only default possessive quantifier
case possessiveByDefault // t.b.d.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, it's fine to model swift extensions (even ones that we haven't assigned letters to) in the options here. But, I'm curious if or why it's necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just more of our existing AST leakage. I think it's okay since we'll want it in the AST eventually, but we still do need to audit and remove AST values from non-AST types.

@@ -150,6 +160,9 @@ extension MatchingOptions {
case unicodeScalarSemantics
case byteSemantics

// Swift-only default possessive quantifier
case possessiveByDefault
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be modeled in this way? It seems like options would just have a quantification kind in it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bitset internally, so it's modeling the tripartite state with two Booleans and an invariant check.

@@ -183,6 +189,46 @@ public struct RegexWordBoundaryKind: Hashable {
}
}

/// Specifies how much to attempt to match when using a quantifier.
@available(SwiftStdlib 5.7, *)
public struct RegexQuantificationBehavior: Hashable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex.QuantificationBehavior?

Do we want an unspecified case or do we want to model as optional behaviors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no unspecified case — eager is the default, and then you can switch to another. DSL types like OneOf take an optional behavior, with nil falling back to the behavior set via quantificationBehavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the choice of default is contextual. I think we'd want to resolve an unspecified quantification at compilation time by checking our options context. If someone had a context that explicitly overrided unspecified with .reluctant, then wanted to go back to .unspecified, how would that happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default isn't contextual, it's .eager — if someone wants to override that default for a chunk of their declaration they can, but there isn't an "unspecified" value for any of the options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how would they have a non-overridable .eager subexpression within there?

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit 4857bc7 into swiftlang:main Apr 21, 2022
natecook1000 added a commit to natecook1000/swift-experimental-string-processing that referenced this pull request Apr 21, 2022
This also moves QuantificationBehavior from the RegexBuilder module
down to _StringProcessing, and renames it to RegexRepetitionBehavior.
@natecook1000 natecook1000 deleted the quantifier_default branch April 21, 2022 20:20
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