diff options
author | odersky <odersky@gmail.com> | 2016-12-15 15:47:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-15 15:47:24 +0100 |
commit | 1773b37286e1b3363b756f0c061ae429b94d9b5d (patch) | |
tree | b07b326cc35966bf28de5ce10668d2759afc589b /compiler | |
parent | ba14bbea35c3c61f13885b42d371283c98a14650 (diff) | |
parent | 628a177f7f5654f4c388b944a098c3723cf7f950 (diff) | |
download | dotty-1773b37286e1b3363b756f0c061ae429b94d9b5d.tar.gz dotty-1773b37286e1b3363b756f0c061ae429b94d9b5d.tar.bz2 dotty-1773b37286e1b3363b756f0c061ae429b94d9b5d.zip |
Merge pull request #1780 from dotty-staging/fix-i1779
fix #1779: support $_ and $_id in interpolated string
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 14 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 51dafc928..704f399ca 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -597,7 +597,7 @@ object Parsers { val isNegated = negOffset < in.offset atPos(negOffset) { if (in.token == SYMBOLLIT) atPos(in.skipToken()) { SymbolLit(in.strVal) } - else if (in.token == INTERPOLATIONID) interpolatedString() + else if (in.token == INTERPOLATIONID) interpolatedString(inPattern) else finish(in.token match { case CHARLIT => in.charVal case INTLIT => in.intVal(isNegated).toInt @@ -621,10 +621,14 @@ object Parsers { in.nextToken() while (in.token == STRINGPART) { segmentBuf += Thicket( - literal(), + literal(inPattern = inPattern), atPos(in.offset) { if (in.token == IDENTIFIER) termIdent() + else if (in.token == USCORE && inPattern) { + in.nextToken() + Ident(nme.WILDCARD) + } else if (in.token == THIS) { in.nextToken() This(EmptyTypeIdent) @@ -633,12 +637,12 @@ object Parsers { if (inPattern) Block(Nil, inBraces(pattern())) else expr() else { - ctx.error(InterpolatedStringError()) + ctx.error(InterpolatedStringError(), source atPos Position(in.offset)) EmptyTree } }) } - if (in.token == STRINGLIT) segmentBuf += literal() + if (in.token == STRINGLIT) segmentBuf += literal(inPattern = inPattern) InterpolatedString(interpolator, segmentBuf.toList) } @@ -1444,7 +1448,7 @@ object Parsers { case XMLSTART => xmlLiteralPattern() case _ => - if (isLiteral) literal() + if (isLiteral) literal(inPattern = true) else { syntaxErrorOrIncomplete(IllegalStartOfSimplePattern()) errorTermTree diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 60003d098..101be167e 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -758,7 +758,7 @@ object Scanners { finishStringPart() nextRawChar() next.token = LBRACE - } else if (Character.isUnicodeIdentifierStart(ch)) { + } else if (Character.isUnicodeIdentifierStart(ch) || ch == '_') { finishStringPart() do { putChar(ch) |