File tree 8 files changed +71
-3
lines changed
compiler/src/dotty/tools/dotc/parsing
8 files changed +71
-3
lines changed Original file line number Diff line number Diff line change @@ -1065,6 +1065,7 @@ object Scanners {
1065
1065
getRawStringLit()
1066
1066
}
1067
1067
1068
+ // for interpolated strings
1068
1069
@ annotation.tailrec private def getStringPart (multiLine : Boolean ): Unit =
1069
1070
if (ch == '"' )
1070
1071
if (multiLine) {
@@ -1081,6 +1082,14 @@ object Scanners {
1081
1082
setStrVal()
1082
1083
token = STRINGLIT
1083
1084
}
1085
+ else if (ch == '\\ ' && ! multiLine) {
1086
+ putChar(ch)
1087
+ nextRawChar()
1088
+ if (ch == '"' || ch == '\\ ' )
1089
+ putChar(ch)
1090
+ nextRawChar()
1091
+ getStringPart(multiLine)
1092
+ }
1084
1093
else if (ch == '$' ) {
1085
1094
nextRawChar()
1086
1095
if (ch == '$' || ch == '"' ) {
Original file line number Diff line number Diff line change @@ -70,8 +70,10 @@ stringElement ::= printableChar \ (‘"’ | ‘\’)
70
70
| charEscapeSeq
71
71
multiLineChars ::= {[‘"’] [‘"’] char \ ‘"’} {‘"’}
72
72
processedStringLiteral
73
- ::= alphaid ‘"’ {printableChar \ (‘"’ | ‘$’) | escape } ‘"’
73
+ ::= alphaid ‘"’ {[‘\’] processedStringPart | ‘\\’ | ‘\"’ } ‘"’
74
74
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’
75
+ processedStringPart
76
+ ::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
75
77
escape ::= ‘$$’
76
78
| ‘$’ letter { letter | digit }
77
79
| ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’
Original file line number Diff line number Diff line change @@ -69,8 +69,10 @@ stringElement ::= printableChar \ (‘"’ | ‘\’)
69
69
| charEscapeSeq
70
70
multiLineChars ::= {[‘"’] [‘"’] char \ ‘"’} {‘"’}
71
71
processedStringLiteral
72
- ::= alphaid ‘"’ {printableChar \ (‘"’ | ‘$’) | escape } ‘"’
72
+ ::= alphaid ‘"’ {[‘\’] processedStringPart | ‘\\’ | ‘\"’ } ‘"’
73
73
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’
74
+ processedStringPart
75
+ ::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
74
76
escape ::= ‘$$’
75
77
| ‘$’ letter { letter | digit }
76
78
| ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’
Original file line number Diff line number Diff line change @@ -69,8 +69,10 @@ stringElement ::= printableChar \ (‘"’ | ‘\’)
69
69
| charEscapeSeq
70
70
multiLineChars ::= {[‘"’] [‘"’] char \ ‘"’} {‘"’}
71
71
processedStringLiteral
72
- ::= alphaid ‘"’ {printableChar \ (‘"’ | ‘$’) | escape } ‘"’
72
+ ::= alphaid ‘"’ {[‘\’] processedStringPart | ‘\\’ | ‘\"’ } ‘"’
73
73
| alphaid ‘"""’ {[‘"’] [‘"’] char \ (‘"’ | ‘$’) | escape} {‘"’} ‘"""’
74
+ processedStringPart
75
+ ::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
74
76
escape ::= ‘$$’
75
77
| ‘$’ letter { letter | digit }
76
78
| ‘{’ Block [‘;’ whiteSpace stringFormat whiteSpace] ‘}’
Original file line number Diff line number Diff line change
1
+ // only the last one doesn't parse
2
+ class C {
3
+ s """ \ """
4
+ s """ \\ """
5
+ s """ \ """
6
+ s " \ "
7
+ s " \\ "
8
+ s " \" // error
9
+ } // error (should not be one)
Original file line number Diff line number Diff line change
1
+ class C {
2
+ val sa = s """ \ """ // error: invalid escape
3
+ val sb = s """ \\ """
4
+ val sc = s """ \ """ // error: invalid escape
5
+ val ra = raw """ \ """
6
+ val rb = raw """ \\ """
7
+ val rc = raw """ \ """
8
+ }
Original file line number Diff line number Diff line change
1
+ "Hello", Alice
2
+ "Hello", Alice
3
+ \"Hello\", Alice
4
+ \"Hello\", Alice
5
+ \"Hello\", Alice
6
+ \"Hello\", Alice
7
+ \TILT\
8
+ \\TILT\\
9
+ \\TILT\\
10
+ \TILT\
11
+ \\TILT\\
12
+ \\TILT\\
13
+ \TILT\
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ def main (args : Array [String ]): Unit = {
3
+ val person = " Alice"
4
+ println(s " \" Hello \" , $person" )
5
+ println(s """ \"Hello\", $person""" )
6
+
7
+ println(f " \" Hello \" , $person" )
8
+ println(f """ \"Hello\", $person""" )
9
+
10
+ println(raw " \ " Hello \ " , $person" )
11
+ println(raw """ \"Hello\", $person""" )
12
+
13
+ println(s " \\ TILT \\ " )
14
+ println(f " \\ TILT \\ " )
15
+ println(raw " \\TILT\\ " )
16
+
17
+ println(s """ \\ TILT \\ """ )
18
+ println(f """ \\ TILT \\ """ )
19
+ println(raw """ \\TILT\\ """ )
20
+
21
+ println(raw """ \TILT\ """ )
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments