diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-11-16 21:58:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-16 21:58:02 +0100 |
commit | 55cff2cfa3f615f9eac158b1d2394ebbf473c6fb (patch) | |
tree | 651990bd0c117065edb6ab20cef5c4ffc4ddc408 | |
parent | 06b2b382a80fd4a53c3e6cf7119822319b87e3df (diff) | |
parent | 3dfcb1577d87ed817da0a1445ba414b2ec4c616d (diff) | |
download | scala-55cff2cfa3f615f9eac158b1d2394ebbf473c6fb.tar.gz scala-55cff2cfa3f615f9eac158b1d2394ebbf473c6fb.tar.bz2 scala-55cff2cfa3f615f9eac158b1d2394ebbf473c6fb.zip |
Merge pull request #5440 from som-snytt/issue/9944
SI-9944 Scan after interp expr keeps CR
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 13 | ||||
-rwxr-xr-x | test/files/run/t9944.check | 12 | ||||
-rw-r--r-- | test/files/run/t9944.scala | 7 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 3a659fd0f0..a8cc7f91c2 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -261,6 +261,14 @@ trait Scanners extends ScannersCommon { private def inMultiLineInterpolation = inStringInterpolation && sepRegions.tail.nonEmpty && sepRegions.tail.head == STRINGPART + /** Are we in a `${ }` block? such that RBRACE exits back into multiline string. */ + private def inMultiLineInterpolatedExpression = { + sepRegions match { + case RBRACE :: STRINGLIT :: STRINGPART :: rest => true + case _ => false + } + } + /** read next token and return last offset */ def skipToken(): Offset = { @@ -327,7 +335,7 @@ trait Scanners extends ScannersCommon { lastOffset -= 1 } if (inStringInterpolation) fetchStringPart() else fetchToken() - if(token == ERROR) { + if (token == ERROR) { if (inMultiLineInterpolation) sepRegions = sepRegions.tail.tail else if (inStringInterpolation) @@ -562,7 +570,8 @@ trait Scanners extends ScannersCommon { case ')' => nextChar(); token = RPAREN case '}' => - nextChar(); token = RBRACE + if (inMultiLineInterpolatedExpression) nextRawChar() else nextChar() + token = RBRACE case '[' => nextChar(); token = LBRACKET case ']' => diff --git a/test/files/run/t9944.check b/test/files/run/t9944.check new file mode 100755 index 0000000000..c2b0adf311 --- /dev/null +++ b/test/files/run/t9944.check @@ -0,0 +1,12 @@ +[[syntax trees at end of parser]] // newSource1.scala +package <empty> { + class C extends scala.AnyRef { + def <init>() = { + super.<init>(); + () + }; + def g = 42; + def f = StringContext("123\r\n", "\r\n123\r\n").s(g) + } +} + diff --git a/test/files/run/t9944.scala b/test/files/run/t9944.scala new file mode 100644 index 0000000000..01cd481266 --- /dev/null +++ b/test/files/run/t9944.scala @@ -0,0 +1,7 @@ + +import scala.tools.partest.ParserTest + +object Test extends ParserTest { + + def code = s"""class C { def g = 42 ; def f = s""\"123\r\n$${ g }\r\n123\r\n""\"}""" +} |