Skip to content

Commit 06c2b28

Browse files
committed
Tweak phrasing
1 parent be7a802 commit 06c2b28

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Documentation/Evolution/DelimiterSyntax.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ We could help distinguish it from a string literal by requiring e.g `'/.../'`, t
223223

224224
### Magic literal `#regex(...)`
225225

226-
We could opt for for a more explicitly spelled out literal syntax such as `#regex(...)`. This is an even more heavyweight option, similar to `#selector(...)`. As such, it may be considered syntactically noisy as e.g a function argument `str.match(#regex([abc]+))` vs `str.match(/[abc]+/)`.
226+
We could opt for for a more explicitly spelled out literal syntax such as `#regex(...)`. This is a more heavyweight option, similar to `#selector(...)`. As such, it may be considered syntactically noisy as e.g a function argument `str.match(#regex([abc]+))` vs `str.match(/[abc]+/)`.
227227

228228
Such a syntax would require the containing regex to correctly balance capture group parentheses, otherwise the rest of the line might be incorrectly considered a regex. This could place additional cognitive burden on the user, and may lead to an awkward typing experience. For example, if the user is editing a previously written regex, the syntax highlighting for the rest of the line may change, and unhelpful spurious errors may be reported. With a different delimiter, the compiler would be able to detect and better diagnose unbalanced parentheses in the regex.
229229

@@ -233,22 +233,22 @@ It should also be noted that `#regex(...)` would introduce a syntactic inconsist
233233

234234
### Shortened magic literal `#(...)`
235235

236-
We could reduce the visual weight of `#regex(...)` by only requiring `#(...)`. This would retain the same advantages e.g not requiring to escape `/`. However it would also still retain the same issues, such as still looking potentially visually noisy as an argument, and having suboptimal behavior for parenthesis balancing. It is also not clear why regex literals would deserve such privileged syntax.
236+
We could reduce the visual weight of `#regex(...)` by only requiring `#(...)`. However it would still retain the same issues, such as still looking potentially visually noisy as an argument, and having suboptimal behavior for parenthesis balancing. It is also not clear why regex literals would deserve such privileged syntax.
237237

238238
### Reusing string literal syntax
239239

240240
Instead of supporting a first-class literal kind for regular expressions, we could instead allow users to write a regular expression in a string literal, and parse, diagnose, and generate the appropriate code when it's coerced to an `ExpressibleByRegexLiteral` conforming type.
241241

242242
```swift
243-
let regex: Regex = "([[:alpha:]]\w*) = ([0-9A-F]+)"
243+
let regex: Regex = #"([[:alpha:]]\w*) = ([0-9A-F]+)"#
244244
```
245245

246246
However we decided against this because:
247247

248248
- We would not be able to easily apply custom syntax highlighting for the regex syntax.
249249
- It would require an `ExpressibleByRegexLiteral` contextual type to be treated as a regex, otherwise it would be defaulted to `String`, which may be undesired.
250250
- In an overloaded context it may be ambiguous or unclear whether a string literal is meant to be interpreted as a literal string or regex.
251-
- Regex escape sequences aren't currently compatible with string literal escape sequence rules, e.g `\w` is currently illegal in a string literal.
251+
- Regex-specific escape sequences such as `\w` would likely require the use of raw string syntax `#"..."#`, as they are otherwise invalid in a string literal.
252252
- It wouldn't be compatible with other string literal features such as interpolations.
253253

254254
### No custom literal

0 commit comments

Comments
 (0)