Skip to content

Allow CustomConsuming types to match w/ zero width #479

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 3 commits into from
Jun 17, 2022

Conversation

natecook1000
Copy link
Member

We previously asserted if a custom consuming type matches with zero width, but that isn't necessary or good. A custom type can implement a lookaround assertion or act as a tracer.

We previously asserted if a custom consuming type matches with zero
width, but that isn't necessary or good. A custom type can implement
a lookaround assertion or act as a tracer.
@natecook1000
Copy link
Member Author

@swift-ci Please test

@@ -120,7 +120,7 @@ extension Processor {
mutating func advance(to nextIndex: Input.Index) {
assert(nextIndex >= bounds.lowerBound)
assert(nextIndex <= bounds.upperBound)
assert(nextIndex > currentPosition)
assert(nextIndex >= currentPosition)
Copy link
Member

Choose a reason for hiding this comment

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

Is this the better change, or is it better to not call advance(to:) if there's nowhere to advance to?

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 doesn't seem necessary to require the precondition for this method, given that a zero-width "advance" is a reasonable output for a consumer/other regex component. Would it sound better to you to rename this to continue(at:)?

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer changing the name if we're changing the meaning here. That way the call sites are clearer that we're not guaranteeing forward progress (e.g. empty matches)

Since the given index doesn’t need to advance, this name is less
misleading.
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit f395a85 into swiftlang:main Jun 17, 2022
@natecook1000 natecook1000 deleted the zero-width-custom-consumer branch June 17, 2022 13:19
mutating func resume(at index: Input.Index) {
assert(index >= bounds.lowerBound)
assert(index <= bounds.upperBound)
assert(index >= currentPosition)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this assertion here?

milseman pushed a commit to milseman/swift-experimental-string-processing that referenced this pull request Jun 30, 2022
* Allow CustomConsuming types to match w/ zero width

We previously asserted if a custom consuming type matches with zero
width, but that isn't necessary or good. A custom type can implement
a lookaround assertion or act as a tracer.

* Rename Processor.advance(to:) to resume(at:)

Since the given index doesn’t need to advance, this name is less
misleading.
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