Skip to content
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

'behavior' Parameter Passed In The Wrong Order in Regex Builder Refactoring #608

Open
CodaFi opened this issue Oct 2, 2022 · 3 comments
Assignees

Comments

@CodaFi
Copy link
Member

CodaFi commented Oct 2, 2022

In Xcode 14.1 beta 3, this regex

#/(.*?)/#

Expands to this regex builder

Regex {
  Capture {
    ZeroOrMore(.reluctant, .any)
  }
}

Which fails to type check because ZeroOrMore takes the component first and the behavior second when not passed a trailing closure that produces a component.

@milseman
Copy link
Collaborator

milseman commented Oct 4, 2022

CC @DaveEwing

@Azoy
Copy link
Member

Azoy commented Oct 6, 2022

On main this get's printed as:

Regex {
  Capture {
    ZeroOrMore(.reluctant) {
      /./
    }
  }
}

with the comment that the DSL'S .any is not equivalent to /./. cc: @hamishknight

@hamishknight
Copy link
Contributor

Yeah the . of a regex literal has different newline matching behavior to .any. However looks like this is still an issue for other elements, e.g on main /\d*?/ gets refactored to:

Regex {
  ZeroOrMore(.reluctant, .digit)
}

@natecook1000 natecook1000 self-assigned this Dec 15, 2022
natecook1000 added a commit to natecook1000/swift-experimental-string-processing that referenced this issue Dec 15, 2022
When rendering a regex as DSL, the parameter order for atoms that
include a non-default repetition behavior is backwards -- the
pattern should come before the repetition behavior. With this
change, the correct RegexBuilder code is provided:

    let regex = /\d+?/
    // converted code:
    let regex = Regex {
        OneOrMore(.digit, .reluctant)
    }

Fixes apple#608.
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

No branches or pull requests

5 participants