Skip to content

Commit 811bfcb

Browse files
committed
Generalize discussion on language mode
1 parent 1ebefa1 commit 811bfcb

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Documentation/Evolution/DelimiterSyntax.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ This proposal helps complete the story told in [Regex Type and Overview][regex-t
1717

1818
## Proposed solution
1919

20-
**TODO: Say that this is Swift 6 syntax only, `#/.../#` would be 5.7 syntax**
21-
22-
**TODO: But is it?**
23-
2420
A regex literal will be introduced using `/.../` delimiters, within which the compiler will parse a regex (the details of which are outlined in [the Regex Syntax pitch][internal-syntax]):
2521

2622
```swift
@@ -32,6 +28,8 @@ Forward slashes are a regex term of art, and are used as the delimiters for rege
3228

3329
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.
3430

31+
Some of these ambiguities require a couple of source breaking language changes, and as such the `/.../` syntax will require upgrading to a new language mode in order to use.
32+
3533
## Detailed design
3634

3735
Choosing `/` as the regex literal delimiter requires a number of ambiguities to be resolved. It also requires a couple of source breaking language changes to be introduced in a new language mode.
@@ -186,13 +184,13 @@ Allowing non-semantic whitespace and other features of the extended syntax would
186184

187185
### Pound slash `#/.../#`
188186

189-
**TODO: This needs to be rewritten to say that it's a potential transition syntax**
187+
This is a less syntactically ambiguous version of `/.../` that retains some of the term-of-art familiarity. It could potentially provide a natural path through which to introduce `/.../` in a new language mode, as users could drop the `#` characters once they upgrade.
190188

191-
This would be less syntactically ambiguous than `/.../`, while retaining some of the term-of-art familiarity. It would also provide a natural path through which to introduce `/.../` in a new language mode, as users could drop the `#` characters once they upgrade.
189+
However, introducing this as non-raw regex literal syntax would introduce an inconsistency with raw string literal syntax, as `#/.../#` on its own would not treat backslashes as literal, unlike `#"..."#`. If raw regex syntax were added, they would likely start at `##/.../##`. With raw strings, escape sequences must use the same number of `#`s as the delimiter, e.g `#"\#n"#` for a newline. However for raw regex literals it would be one fewer `#` than the delimiter e.g `##/\#n/##`.
192190

193-
However this option would also have the same block comment issue as `/.../` where e.g `#/x*/#` nested inside a block comment would prematurely end. Similarly, it's not clear how a multi-line version of the literal would be spelled.
191+
**TODO: What backslash rules do we want?**
194192

195-
Additionally, introducing this syntax would introduce an inconsistency with raw string literal syntax, as `#/.../#` on its own would not treat backslashes as literal, unlike `#"..."#`. If raw regex syntax were implemented, it would start at `##/.../##`. With raw strings, escape sequences must use the same number of `#`s as the delimiter, e.g `#"\#n"#` for a newline. However for raw regex literals it would be one fewer `#` than the delimiter e.g `##/\#n/##`.
193+
It should also be noted that this option has the same block comment issue as `/.../` where e.g `#/[0-9]*/#` nested inside a block comment would prematurely end. Similarly, it's not clear how a multi-line version of the literal would be spelled.
196194

197195
### Prefixed quote `re'...'`
198196

0 commit comments

Comments
 (0)