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

feat: implement capture #16

Closed
okwasniewski opened this issue Dec 6, 2023 · 2 comments
Closed

feat: implement capture #16

okwasniewski opened this issue Dec 6, 2023 · 2 comments

Comments

@okwasniewski
Copy link
Member

okwasniewski commented Dec 6, 2023

Describe the feature

Implement capture() component

let regex = buildRegex(
    "a", capture(one("c"), oneOrMore("ab")) // a(c(?:ab)+)
)

References

https://developer.apple.com/documentation/regexbuilder/capture

Related Issues

@mdjastrzebski
Copy link
Member

mdjastrzebski commented Dec 6, 2023

My suggestions:

Swift:

Regex {
    // Basic
    Capture {
      OneOrMore(.digit)
      "."
      Repeat(.digit, count: 2)
    }
   // With transform
    Capture {
      OneOrMore(.digit)
      "."
      Repeat(.digit, count: 2)
    } transform: { Double($0)! }
}

Proposed API:

buildRegex(
  // Basic
  capture(
     oneOrMore(digit),
     ".",
     repeat({ count: 2}, digit),
  )
  // With transform
  capture(
     { transform: (n) => parseFloat(n) },
     oneOrMore(digit),
     ".",
     repeat({ count: 2}, digit),
  )
}

Providing transform is optional.

I don't know if config (transform) should be the first or last parameter. JS conventions would suggest first due to the presence of vargargs.

Note that we probably should keep the transform key explicit, as the Swift API also has some as an argument, which we might want to implement)

@mdjastrzebski
Copy link
Member

Implemented in #24

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

2 participants