Skip to content

Introduce One #403

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

Introduce One #403

merged 1 commit into from
May 12, 2022

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented May 12, 2022

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
Copy link
Contributor Author

rxwei commented May 12, 2022

@swift-ci please test

@rxwei rxwei merged commit b8178c2 into swiftlang:main May 12, 2022
@rxwei rxwei deleted the 1 branch May 12, 2022 17:19
This was referenced 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