Skip to content

Commit a76d73d

Browse files
committed
Forbid backslashes and identifiers consisting only of whitespace.
1 parent 4cafc93 commit a76d73d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

proposals/NNNN-escaped-identifiers.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,17 @@ In [Zig](https://ziglang.org/documentation/master/#Identifiers), an identifier t
206206
A raw identifier may contain any valid Unicode characters except for the following:
207207

208208
* The backtick (`` ` ``) itself, which termintes the identifier.
209+
* The backslash (`\`), which is reserved for potential future escape sequences.
209210
* Carriage return (`U+000D`) or newline (`U+000A`); identifiers must be written on a single line.
210211
* The NUL character (`U+0000`), which already emits a warning if present in Swift source but would be disallowed completely in a raw identifier.
211212
* All other non-printable ASCII code units that are also forbidden in single-line Swift string literals (`U+0001...U+001F`, `U+007F`).
212213

213214
In addition to these rules, some specific combinations that require special handling are discussed below.
214215

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+
215220
#### Operator characters
216221

217222
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 = ```
438443

439444
At this time, however, we do not believe there are any compelling use cases for such identifiers.
440445

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+
441450
## Source compatibility
442451

443452
This proposal is purely additive; it does not affect compatibility with existing source code.

0 commit comments

Comments
 (0)