Skip to content

Commit 5a4f8b1

Browse files
Note that raw string literals are context-sensitive
See https://github.com/rust-lang/rust/blob/5187be620c76a313a19b9b596e1bce3a80a345dd/src/grammar/raw-string-literal-ambiguity.md for the original formal proof of this fact.
1 parent b829849 commit 5a4f8b1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/tokens.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ the characters `U+0022` (double-quote) (except when followed by at least as
208208
many `U+0023` (`#`) characters as were used to start the raw string literal) or
209209
`U+005C` (`\`) do not have any special meaning.
210210

211+
**Note that this is a _context-sensitive_ grammar, as opposed to _context-free_.**
212+
This is because strings like `r###"I contain only 2 "##s so I'm ok"###` require
213+
a parser to properly count the number of opening #'s and compare that count to two
214+
different values. In practical terms this is very easy for a parser to do, but
215+
a context-free language can't because the only way to express "counting" is
216+
as a destructive operation which forces you to forget the count. This allows
217+
for the "comparison" of two counts (such (as (balanced) (parens))) but not 3+.
218+
211219
Examples for string literals:
212220

213221
```rust

0 commit comments

Comments
 (0)