-
Notifications
You must be signed in to change notification settings - Fork 50
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
Allow CustomConsuming types to match w/ zero width #479
Conversation
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.
@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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:)
?
There was a problem hiding this comment.
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.
@swift-ci Please test |
mutating func resume(at index: Input.Index) { | ||
assert(index >= bounds.lowerBound) | ||
assert(index <= bounds.upperBound) | ||
assert(index >= currentPosition) |
There was a problem hiding this comment.
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?
* 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.
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.