Skip to content

[5.7] Introduce One #406

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 1 commit into from
May 12, 2022
Merged

[5.7] Introduce One #406

merged 1 commit into from
May 12, 2022

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented May 12, 2022

Cherry-pick of #403


One is a lightweight component that allows the use of the leading dot syntax to reference RegexComponent static members such as character classes as a non-first expression in a regex builder block.


Before:

Regex {
    .digit // works today but brittle; inserting anything above this line will break this

    OneOrMore(.whitespace)

    .word // ❌ error: 'OneOrMore' has no member named 'word' (because this is parsed as a member reference on the preceeding expression)
}

After:

Regex {
    One(.digit)              // recommended even though `.digit` works today
    OneOrMore(.whitespace)
    One(.word)
} // ✅

In a follow-up patch, we will propose adding an additional protocol inheriting from RegexComponent that will ban the use of the leading dot syntax even on the first line of Regex { ... }, as this will enforce the recommended style (use of One), and prevent surprises when the user inserts a pattern above the leading dot line.

One is a lightweight component that allows the use of the leading dot syntax to reference `RegexComponent` static members such as character classes as a non-first expression in a regex builder block.

---

Before:

```swift
Regex {
    .digit // works today but brittle; inserting anything above this line will break this

    OneOrMore(.whitespace)

    .word // ❌ error: 'OneOrMore' has no member named 'word' (because this is parsed as a member reference on the preceeding expression)
}
```

After:

```swift
Regex {
    One(.digit)              // recommended even though `.digit` works today
    OneOrMore(.whitespace)
    One(.word)
} // ✅
```

In a follow-up patch, we will propose adding an additional protocol inheriting from `RegexComponent` that will ban the use of the leading dot syntax even on the first line of `Regex { ... }`, as this will enforce the recommended style (use of `One`), and prevent surprises when the user inserts a pattern above the leading dot line.
@rxwei rxwei changed the title Introduce One [5.7-04182022] Introduce One May 12, 2022
@rxwei rxwei changed the title [5.7-04182022] Introduce One [5.7] Introduce One May 12, 2022
@rxwei rxwei merged commit 5e34b84 into swiftlang:swift/release/5.7 May 12, 2022
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