Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note that raw string literals are context-sensitive #1185

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ the characters `U+0022` (double-quote) (except when followed by at least as
many `U+0023` (`#`) characters as were used to start the raw string literal) or
`U+005C` (`\`) do not have any special meaning.

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

Gankra marked this conversation as resolved.
Show resolved Hide resolved
Examples for string literals:

```rust
Expand Down