Skip to content

Commit a0b1195

Browse files
authored
Merge pull request #1450 from nnethercote/nul-in-c-str-literal
Update C-String literals to reject NUL
2 parents e848fbc + a393aaf commit a0b1195

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/tokens.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ b"\\x52"; br"\x52"; // \x52
320320
> **<sup>Lexer</sup>**\
321321
> C_STRING_LITERAL :\
322322
> &nbsp;&nbsp; `c"` (\
323-
> &nbsp;&nbsp; &nbsp;&nbsp; ~\[`"` `\` _IsolatedCR_]\
324-
> &nbsp;&nbsp; &nbsp;&nbsp; | BYTE_ESCAPE\
325-
> &nbsp;&nbsp; &nbsp;&nbsp; | UNICODE_ESCAPE\
323+
> &nbsp;&nbsp; &nbsp;&nbsp; ~\[`"` `\` _IsolatedCR_ _NUL_]\
324+
> &nbsp;&nbsp; &nbsp;&nbsp; | BYTE_ESCAPE _except `\0` or `\x00`_\
325+
> &nbsp;&nbsp; &nbsp;&nbsp; | UNICODE_ESCAPE _except `\u{0}`, `\u{00}`, …, `\u{000000}`_\
326326
> &nbsp;&nbsp; &nbsp;&nbsp; | STRING_CONTINUE\
327327
> &nbsp;&nbsp; )<sup>\*</sup> `"` SUFFIX<sup>?</sup>
328328
@@ -355,10 +355,6 @@ starts with a `U+005C` (`\`) and continues with one of the following forms:
355355
* The _backslash escape_ is the character `U+005C` (`\`) which must be
356356
escaped in order to denote its ASCII encoding `0x5C`.
357357

358-
The escape sequences `\0`, `\x00`, and `\u{0000}` are permitted within the token
359-
but will be rejected as invalid, as C strings may not contain byte `0x00` except
360-
as the implicit terminator.
361-
362358
A C string represents bytes with no defined encoding, but a C string literal
363359
may contain Unicode characters above `U+007F`. Such characters will be replaced
364360
with the bytes of that character's UTF-8 representation.
@@ -381,16 +377,16 @@ c"\xC3\xA6";
381377
> &nbsp;&nbsp; `cr` RAW_C_STRING_CONTENT SUFFIX<sup>?</sup>
382378
>
383379
> RAW_C_STRING_CONTENT :\
384-
> &nbsp;&nbsp; &nbsp;&nbsp; `"` ( ~ _IsolatedCR_ )<sup>* (non-greedy)</sup> `"`\
380+
> &nbsp;&nbsp; &nbsp;&nbsp; `"` ( ~ _IsolatedCR_ _NUL_ )<sup>* (non-greedy)</sup> `"`\
385381
> &nbsp;&nbsp; | `#` RAW_C_STRING_CONTENT `#`
386382
387383
Raw C string literals do not process any escapes. They start with the
388384
character `U+0063` (`c`), followed by `U+0072` (`r`), followed by fewer than 256
389385
of the character `U+0023` (`#`), and a `U+0022` (double-quote) character. The
390-
_raw C string body_ can contain any sequence of Unicode characters and is
391-
terminated only by another `U+0022` (double-quote) character, followed by the
392-
same number of `U+0023` (`#`) characters that preceded the opening `U+0022`
393-
(double-quote) character.
386+
_raw C string body_ can contain any sequence of Unicode characters (other than
387+
`U+0000`) and is terminated only by another `U+0022` (double-quote) character,
388+
followed by the same number of `U+0023` (`#`) characters that preceded the
389+
opening `U+0022` (double-quote) character.
394390

395391
All characters contained in the raw C string body represent themselves in UTF-8
396392
encoding. The characters `U+0022` (double-quote) (except when followed by at

0 commit comments

Comments
 (0)