Skip to content

Commit c25f524

Browse files
committed
---
yaml --- r: 126695 b: refs/heads/snap-stage3 c: 1a1a9d5 h: refs/heads/master i: 126693: b5323b5 126691: 0f926f3 126687: 3504803 v: v3
1 parent bebc840 commit c25f524

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 7be8f0af0393dcdb077c2f6b1653836fd3fba235
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 19e1f5cdb6a47070fd5f12993e947ea6db0eb5dd
4+
refs/heads/snap-stage3: 1a1a9d54456355cc0ebdd397fd04871abe27f78c
55
refs/heads/try: 502e4c045236682e9728539dc0d2b3d0b237f55c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Rust's lexical grammar is not context-free. Raw string literals are the source
2+
of the problem. Informally, a raw string literal is an `r`, followed by `N`
3+
hashes (where N can be zero), a quote, any characters, then a quote followed
4+
by `N` hashes. This grammar describes this as best possible:
5+
6+
R -> 'r' S
7+
S -> '"' B '"'
8+
S -> '#' S '#'
9+
B -> . B
10+
B -> ε
11+
12+
Where `.` represents any character, and `ε` the empty string. Consider the
13+
string `r#""#"#`. This string is not a valid raw string literal, but can be
14+
accepted as one by the above grammar, using the derivation:
15+
16+
R : #""#"#
17+
S : ""#"
18+
S : "#
19+
B : #
20+
B : ε
21+
22+
(Where `T : U` means the rule `T` is applied, and `U` is the remainder of the
23+
string.) The difficulty arises from the fact that it is fundamentally
24+
context-sensitive. In particular, the context needed is the number of hashes.
25+
I know of no way to resolve this, but also have not come up with a proof that
26+
it is not context sensitive. Such a proof would probably use the pumping lemma
27+
for context-free languages, but I (cmr) could not come up with a proof after
28+
spending a few hours on it, and decided my time best spent elsewhere. Pull
29+
request welcome!

0 commit comments

Comments
 (0)