未验证 提交 a75d0d67 编写于 作者: R Roman Starkov 提交者: GitHub

Fix parsing of nested verbatim interpolated strings started with @$ (#44924)

* Fix parsing of nested verbatim interpolated strings started with @$

* Issue error for alt nested interpolated string in 7.3 or below. Better unit tests and test the error.
上级 295a4208
......@@ -612,6 +612,27 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool
ScanInterpolatedStringLiteralNestedVerbatimString();
continue;
}
else if (lexer.TextWindow.PeekChar(1) == '$' && lexer.TextWindow.PeekChar(2) == '"')
{
lexer.CheckFeatureAvailability(MessageID.IDS_FeatureAltInterpolatedVerbatimStrings);
var interpolations = (ArrayBuilder<Interpolation>)null;
var info = default(TokenInfo);
bool wasVerbatim = this.isVerbatim;
bool wasAllowNewlines = this.allowNewlines;
try
{
this.isVerbatim = true;
this.allowNewlines = true;
bool closeQuoteMissing;
ScanInterpolatedStringLiteralTop(interpolations, ref info, out closeQuoteMissing);
}
finally
{
this.isVerbatim = wasVerbatim;
this.allowNewlines = wasAllowNewlines;
}
continue;
}
goto default;
case '/':
......
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
......@@ -92,6 +92,79 @@ public void TestAltInterpolatedVerbatimString_CSharp8()
EOF();
}
[Fact]
public void TestNestedAltInterpolatedVerbatimString_CSharp73()
{
UsingExpression("$@\"aaa{@$\"bbb\nccc\"}ddd\"", TestOptions.Regular7_3,
// (1,8): error CS8401: To use '@$' instead of '$@' for an interpolated verbatim string, please use language version '8.0' or greater.
// $@"aaa{@$"bbb
Diagnostic(ErrorCode.ERR_AltInterpolatedVerbatimStringsNotAvailable, @"@$""").WithArguments("8.0").WithLocation(1, 8)
);
N(SyntaxKind.InterpolatedStringExpression);
{
N(SyntaxKind.InterpolatedVerbatimStringStartToken);
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken, "aaa");
}
N(SyntaxKind.Interpolation);
{
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.InterpolatedStringExpression);
{
N(SyntaxKind.InterpolatedVerbatimStringStartToken);
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken, "bbb\nccc");
}
N(SyntaxKind.InterpolatedStringEndToken);
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken, "ddd");
}
N(SyntaxKind.InterpolatedStringEndToken);
}
EOF();
}
[Fact]
public void TestNestedAltInterpolatedVerbatimString_CSharp8()
{
UsingExpression("$@\"aaa{@$\"bbb\nccc\"}ddd\"", TestOptions.Regular8);
N(SyntaxKind.InterpolatedStringExpression);
{
N(SyntaxKind.InterpolatedVerbatimStringStartToken);
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken, "aaa");
}
N(SyntaxKind.Interpolation);
{
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.InterpolatedStringExpression);
{
N(SyntaxKind.InterpolatedVerbatimStringStartToken);
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken, "bbb\nccc");
}
N(SyntaxKind.InterpolatedStringEndToken);
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.InterpolatedStringText);
{
N(SyntaxKind.InterpolatedStringTextToken, "ddd");
}
N(SyntaxKind.InterpolatedStringEndToken);
}
EOF();
}
[Fact]
public void TestName()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册