Skip to content

Flatten optional nesting for regex literal captures #545

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 5 commits into from
Jul 6, 2022

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Jul 5, 2022

When computing the CaptureList for AST nodes, including converted AST -> DSL nodes, only permit at most one level of optionality. This means that regex literal captures are now either Substring or Substring?.

Optional nesting is however still performed in the DSL (due to result builder limitations). If a regex literal is nested in the DSL, it may only add at most one extra level of optionality to the current nesting level.

Additionally, change the value of a failed nested optional capture from .some(nil) to nil.

Resolves #399
Resolves #543
rdar://96505893

@hamishknight hamishknight requested review from milseman, rxwei and Azoy July 5, 2022 21:18
Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

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

I haven't looked at the implementation very closely but the new behavior makes sense to me.

This doesn't appear to be used.
Previously we would wrap a `nil` in
`optionalCount - 1` outer layers of `.some(...)`.
Change this to return an `optionalCount` nested
optional with a top-level value of `nil`.
When computing the CaptureList for AST nodes,
including converted AST -> DSL nodes, only permit
at most one level of optionality. This means that
regex literal captures are now either `Substring`
or `Substring?`.

Optional nesting is however still performed in the
DSL (due to result builder limitations). If a
regex literal is nested in the DSL, it may only
add at most one extra level of optionality to the
current nesting level.
This is no longer needed as the capture list has
the right nesting information.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

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.

Failed captures produced .some(nil) Flatten optionality of regex captures
2 participants