File tree 6 files changed +54
-6
lines changed
src/compiler/scala/tools/nsc/ast/parser 6 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -1152,7 +1152,7 @@ self =>
1152
1152
val exprBuf = new ListBuffer [Tree ]
1153
1153
in.nextToken()
1154
1154
while (in.token == STRINGPART ) {
1155
- partsBuf += literal()
1155
+ partsBuf += atPos(in.offset)( literal() )
1156
1156
exprBuf += {
1157
1157
if (inPattern) dropAnyBraces(pattern())
1158
1158
else {
@@ -1166,7 +1166,7 @@ self =>
1166
1166
}
1167
1167
}
1168
1168
}
1169
- if (in.token == STRINGLIT ) partsBuf += literal()
1169
+ if (in.token == STRINGLIT ) partsBuf += atPos(in.offset)( literal() )
1170
1170
1171
1171
val t1 = atPos(o2p(start)) { Ident (nme.StringContext ) }
1172
1172
val t2 = atPos(start) { Apply (t1, partsBuf.toList) }
Original file line number Diff line number Diff line change @@ -425,6 +425,7 @@ trait Scanners extends ScannersCommon {
425
425
if (ch == '\" ' ) {
426
426
nextRawChar()
427
427
if (ch == '\" ' ) {
428
+ offset += 3
428
429
nextRawChar()
429
430
getStringPart(multiLine = true )
430
431
sepRegions = STRINGPART :: sepRegions // indicate string part
@@ -434,6 +435,7 @@ trait Scanners extends ScannersCommon {
434
435
strVal = " "
435
436
}
436
437
} else {
438
+ offset += 1
437
439
getStringPart(multiLine = false )
438
440
sepRegions = STRINGLIT :: sepRegions // indicate single line string part
439
441
}
Original file line number Diff line number Diff line change 1
1
t5510.scala:2: error: unclosed string literal
2
2
val s1 = s"xxx
3
- ^
3
+ ^
4
4
t5510.scala:3: error: unclosed string literal
5
5
val s2 = s"xxx $x
6
6
^
7
7
t5510.scala:4: error: unclosed string literal
8
8
val s3 = s"xxx $$
9
- ^
9
+ ^
10
10
t5510.scala:5: error: unclosed string literal
11
11
val s4 = ""s"
12
- ^
12
+ ^
13
13
t5510.scala:6: error: unclosed multi-line string literal
14
14
val s5 = ""s""" $s1 $s2 s"
15
15
^
Original file line number Diff line number Diff line change 1
1
t5856.scala:10: error: invalid string interpolation: `$$', `$'ident or `$'BlockExpr expected
2
2
val s9 = s"$"
3
- ^
3
+ ^
4
4
t5856.scala:10: error: unclosed string literal
5
5
val s9 = s"$"
6
6
^
Original file line number Diff line number Diff line change
1
+ [[syntax trees at end of parser]] // newSource1
2
+ [0:91]package [0:0]<empty> {
3
+ [0:91]class C extends [8:91][91]scala.AnyRef {
4
+ [8]def <init>() = [8]{
5
+ [8][8][8]super.<init>();
6
+ [8]()
7
+ };
8
+ [16:44]def quote = [28:44]<28:44><28:44>[28]StringContext([30:34]"foo", [40:44]"baz").s([35:39]this);
9
+ [51:85]def tripleQuote = [69:85]<69:85><69:85>[69]StringContext([71:75]"foo", [81:85]"baz").s([76:80]this)
10
+ }
11
+ }
12
+
Original file line number Diff line number Diff line change
1
+ import scala .tools .partest ._
2
+ import java .io ._
3
+ import scala .tools .nsc ._
4
+ import scala .tools .nsc .util .CommandLineParser
5
+ import scala .tools .nsc .{Global , Settings , CompilerCommand }
6
+ import scala .tools .nsc .reporters .ConsoleReporter
7
+
8
+ object Test extends DirectTest {
9
+
10
+ override def extraSettings : String = " -usejavacp -Xprint:parser -Ystop-after:parser -d " + testOutput.path
11
+
12
+ override def code = """
13
+ class C {
14
+ def quote = s"foo${this}baz"
15
+ def tripleQuote = s"foo${this}baz"
16
+ }
17
+ """ .trim
18
+
19
+ override def show (): Unit = {
20
+ // redirect err to out, for logging
21
+ val prevErr = System .err
22
+ System .setErr(System .out)
23
+ compile()
24
+ System .setErr(prevErr)
25
+ }
26
+
27
+ override def newCompiler (args : String * ): Global = {
28
+
29
+ val settings = new Settings ()
30
+ settings.Xprintpos .value = true
31
+ val command = new CompilerCommand ((CommandLineParser tokenize extraSettings) ++ args.toList, settings)
32
+ new Global (command.settings, new ConsoleReporter (settings)) with interactive.RangePositions
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments