You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/NNNN-escaped-identifiers.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -206,12 +206,17 @@ In [Zig](https://ziglang.org/documentation/master/#Identifiers), an identifier t
206
206
A raw identifier may contain any valid Unicode characters except for the following:
207
207
208
208
* The backtick (`` ` ``) itself, which termintes the identifier.
209
+
* The backslash (`\`), which is reserved for potential future escape sequences.
209
210
* Carriage return (`U+000D`) or newline (`U+000A`); identifiers must be written on a single line.
210
211
* The NUL character (`U+0000`), which already emits a warning if present in Swift source but would be disallowed completely in a raw identifier.
211
212
* All other non-printable ASCII code units that are also forbidden in single-line Swift string literals (`U+0001...U+001F`, `U+007F`).
212
213
213
214
In addition to these rules, some specific combinations that require special handling are discussed below.
214
215
216
+
#### Whitespace
217
+
218
+
A raw identifier may have leading, trailing, or internal whitespace; however, it may not consist of *only* whitespace. "Whitespace" is defined here to mean characters satisfying the Unicode `White_Space` property, exposed in Swift by `Unicode.Scalar.Properties.isWhitespace`.
219
+
215
220
#### Operator characters
216
221
217
222
A raw identifier may start with, contain, or end with operator characters, but it may not contain **only** operator characters. To avoid confusion, a raw identifier containing only operator characters is treated as a parsing error: it is neither a valid identifier nor an operator:
@@ -438,6 +443,10 @@ let fifteen = ```
438
443
439
444
At this time, however, we do not believe there are any compelling use cases for such identifiers.
440
445
446
+
### Escape sequences inside raw identifiers
447
+
448
+
Raw identifiers follow similar parsing rules as string literals with respect to unprintable characters, which raises the question of how to handle backslashes. The use cases served by many backslash escapes—such as writing unprintable characters—are not desirable for identifiers, so we could choose to treat backslashes as regular literal characters. For example, `` `hello\now` `` would mean the identifier `hello\now`. This could be confusing for users though, who might expect the `\n` to be interpreted the same way that it would be in a string literal. Treating backslashes as literal characters today would also close the door on a viable method of escaping characters inside raw identifiers if we decide that it is needed later. For these reasons, we currently forbid backslashes and leave their purpose to be defined in the future.
449
+
441
450
## Source compatibility
442
451
443
452
This proposal is purely additive; it does not affect compatibility with existing source code.
0 commit comments