Skip to content

Commit 91a93a8

Browse files
committed
Small tweaks
1 parent 06c2b28 commit 91a93a8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Documentation/Evolution/DelimiterSyntax.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
A regular expression literal will be introduced using `/.../` delimiters, within which the compiler will parse a regular expression (the details of which are outlined in [the Regex Syntax pitch][internal-syntax]):
1818

19-
```
19+
```swift
2020
// Matches "<identifier> = <hexadecimal value>", extracting the identifier and hex number
2121
let regex = /([[:alpha:]]\w*) = ([0-9A-F]+)/
2222
```
2323

24-
Forward slashes are a regex term of art, and are used as the delimiters for regex literals in Perl, JavaScript and Ruby (though Perl and Ruby also provide alternative choices). Due to its existing use in comment syntax and operators, there are some syntactic ambiguities to consider. While there are quite a few cases to consider, we do not feel that the impact of any individual case is particularly high.
24+
Forward slashes are a regex term of art, and are used as the delimiters for regex literals in Perl, JavaScript and Ruby (though Perl and Ruby also provide alternatives). Their ubiquity and familiarity makes them a compelling choice for Swift.
2525

26-
**TODO: Do we want to present a stronger argument for `/.../`?**
26+
Due to the existing use of `/` in comment syntax and operators, there are some syntactic ambiguities to consider. While there are quite a few cases to consider, we do not feel that the impact of any individual case is sufficient to disqualify the syntax.
2727

2828
**TODO: Anything else we want to say here before segueing into the massive list?**
2929

@@ -182,22 +182,22 @@ Additionally, introducing this syntax would introduce an inconsistency with raw
182182

183183
## Future Directions
184184

185-
**TODO: What do we want to say here?**
185+
**TODO: What do we want to say here? Talk about raw and multiline? Don't really have a good option for the latter tho**
186186

187187
## Alternatives Considered
188188

189189
### Prefixed quote `re'...'`
190190

191191
We could choose to use `re'...'` delimiters, for example:
192192

193-
```
193+
```swift
194194
// Matches "<identifier> = <hexadecimal value>", extracting the identifier and hex number
195195
let regex = re'([[:alpha:]]\w*) = ([0-9A-F]+)'
196196
```
197197

198198
The use of two letter prefix could potentially be used as a namespace for future literal types. However, it is unusual for a Swift literal to be prefixed in this way.
199199

200-
**TODO: Fill in reasons why not to pick this**
200+
**TODO: Any other reasons why not to pick this?**
201201

202202
**TODO: Mention that it nicely extends to raw and multiline?**
203203

@@ -225,7 +225,7 @@ We could help distinguish it from a string literal by requiring e.g `'/.../'`, t
225225

226226
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

228-
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.
228+
Such a syntax would require the containing regex to correctly balance parentheses for groups, 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

230230
We could avoid the parenthesis balancing issue by requiring an additional internal delimiter such as `#regex(/.../)`. However it is even more heavyweight, and it may be unclear that `/` is part of the delimiter rather than part of the literal. Alternatively, we could replace the internal delimiter with another character such as ```#regex`...` ```, `#regex{...}`, or `#regex/.../`. However those would be inconsistent with the existing `#literal(...)` syntax and the first two would overload the existing meanings for the ``` `` ``` and `{}` delimiters.
231231

0 commit comments

Comments
 (0)