Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
f6cd1b07
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f6cd1b07
编写于
1月 09, 2015
作者:
N
nmgafter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1099238-Lost lexical errors from literal parts of interpolated strings (changeset 1395214)
上级
d57807dd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
13 deletion
+53
-13
Src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs
...harp/Portable/Parser/LanguageParser_InterpolatedString.cs
+21
-10
Src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs
Src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs
+2
-2
Src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs
...lers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs
+30
-1
未找到文件。
Src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs
浏览文件 @
f6cd1b07
...
...
@@ -189,24 +189,35 @@ private InterpolationSyntax ParseInterpolation(string text, Lexer.Interpolation
/// <param name="kind">The token kind to be assigned to the resulting token</param>
SyntaxToken
MakeStringToken
(
string
text
,
string
bodyText
,
bool
isVerbatim
,
SyntaxKind
kind
)
{
var
fakeString
=
(
isVerbatim
?
"@\""
:
"\""
)
+
bodyText
+
"\""
;
var
prefix
=
isVerbatim
?
"@\""
:
"\""
;
var
fakeString
=
prefix
+
bodyText
+
"\""
;
using
(
var
tempLexer
=
new
Lexer
(
Text
.
SourceText
.
From
(
fakeString
),
this
.
Options
,
allowPreprocessorDirectives
:
false
))
{
var
info
=
default
(
Lexer
.
TokenInfo
);
if
(
isVerbatim
)
{
tempLexer
.
ScanVerbatimStringLiteral
(
ref
info
);
}
else
LexerMode
mode
=
LexerMode
.
Syntax
;
SyntaxToken
token
=
tempLexer
.
Lex
(
ref
mode
);
Debug
.
Assert
(
token
.
Kind
==
SyntaxKind
.
StringLiteralToken
);
var
result
=
SyntaxFactory
.
Literal
(
null
,
text
,
kind
,
token
.
ValueText
,
null
);
if
(
token
.
ContainsDiagnostics
)
{
tempLexer
.
ScanStringLiteral
(
ref
info
);
result
=
result
.
WithDiagnosticsGreen
(
MoveDiagnostics
(
token
.
GetDiagnostics
(),
-
prefix
.
Length
)
);
}
Debug
.
Assert
(
info
.
Kind
==
SyntaxKind
.
StringLiteralToken
);
return
SyntaxFactory
.
Literal
(
null
,
text
,
kind
,
info
.
StringValue
,
null
);
return
result
;
}
}
DiagnosticInfo
[]
MoveDiagnostics
(
DiagnosticInfo
[]
infos
,
int
offset
)
{
var
builder
=
ArrayBuilder
<
DiagnosticInfo
>.
GetInstance
();
foreach
(
var
info
in
infos
)
{
var
sd
=
info
as
SyntaxDiagnosticInfo
;
builder
.
Add
(
sd
?.
WithOffset
(
sd
.
Offset
+
offset
)
??
info
);
}
return
builder
.
ToArrayAndFree
();
}
private
void
ParseInterpolationStart
(
out
SyntaxToken
openBraceToken
,
out
ExpressionSyntax
expr
,
out
SyntaxToken
commaToken
,
out
ExpressionSyntax
alignmentExpression
)
{
openBraceToken
=
this
.
EatToken
(
SyntaxKind
.
OpenBraceToken
);
...
...
Src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs
浏览文件 @
f6cd1b07
...
...
@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax
{
internal
partial
class
Lexer
{
internal
void
ScanStringLiteral
(
ref
TokenInfo
info
,
bool
allowEscapes
=
true
)
private
void
ScanStringLiteral
(
ref
TokenInfo
info
,
bool
allowEscapes
=
true
)
{
var
quoteCharacter
=
TextWindow
.
PeekChar
();
if
(
quoteCharacter
==
'\''
||
quoteCharacter
==
'"'
)
...
...
@@ -151,7 +151,7 @@ private char ScanEscapeSequence(out char surrogateCharacter)
return
ch
;
}
internal
void
ScanVerbatimStringLiteral
(
ref
TokenInfo
info
,
bool
allowNewlines
=
true
)
private
void
ScanVerbatimStringLiteral
(
ref
TokenInfo
info
,
bool
allowNewlines
=
true
)
{
this
.
builder
.
Length
=
0
;
...
...
Src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs
浏览文件 @
f6cd1b07
...
...
@@ -1018,7 +1018,10 @@ static void Main(string[] args)
CreateCompilationWithMscorlib
(
text
).
VerifyDiagnostics
(
// (6,40): error CS8087: A '}' character may only be escaped by doubling '}}' in an interpolated string.
// var x = $"{ Math.Abs(value: 1):\}";
Diagnostic
(
ErrorCode
.
ERR_EscapedCurly
,
@"\"
).
WithArguments
(
"}"
).
WithLocation
(
6
,
40
)
Diagnostic
(
ErrorCode
.
ERR_EscapedCurly
,
@"\"
).
WithArguments
(
"}"
).
WithLocation
(
6
,
40
),
// (6,40): error CS1009: Unrecognized escape sequence
// var x = $"{ Math.Abs(value: 1):\}";
Diagnostic
(
ErrorCode
.
ERR_IllegalEscape
,
@"\}"
).
WithLocation
(
6
,
40
)
);
}
...
...
@@ -1106,5 +1109,31 @@ public void Dynamic01()
);
}
[
WorkItem
(
1099238
,
"DevDiv"
)]
[
Fact
]
public
void
Syntax04
()
{
var
text
=
@"using System;
using System.Linq.Expressions;
class Program
{
static void Main()
{
Expression<Func<string>> e = () => $""\u1{0:\u2}"";
Console.WriteLine(e);
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
text
).
VerifyDiagnostics
(
// (8,46): error CS1009: Unrecognized escape sequence
// Expression<Func<string>> e = () => $"\u1{0:\u2}";
Diagnostic
(
ErrorCode
.
ERR_IllegalEscape
,
@"\u1"
).
WithLocation
(
8
,
46
),
// (8,52): error CS1009: Unrecognized escape sequence
// Expression<Func<string>> e = () => $"\u1{0:\u2}";
Diagnostic
(
ErrorCode
.
ERR_IllegalEscape
,
@"\u2"
).
WithLocation
(
8
,
52
)
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录