Skip to content

Commit 8d745dc

Browse files
authored
Merge pull request #14505 from rintaro/lex-escaped-eof
[Lexer] Don't setEscapedIdentifier(true) for tok::eof at ArtificialEOF
2 parents e9b9f0f + 7667742 commit 8d745dc

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

lib/Parse/Lexer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ void Lexer::formEscapedIdentifierToken(const char *TokStart) {
279279
TrailingTrivia.push_back(TriviaPiece::backtick());
280280
}
281281
formToken(tok::identifier, TokStart);
282+
// If this token is at ArtificialEOF, it's forced to be tok::eof. Don't mark
283+
// this as escaped-identifier in this case.
284+
if (NextToken.is(tok::eof))
285+
return;
282286
NextToken.setEscapedIdentifier(true);
283287
}
284288

test/SourceKit/DocumentStructure/Inputs/main.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,14 @@ protocol FooProtocol {
107107

108108
// SR-5717
109109
a.b(c: d?.e?.f, h: i)
110+
111+
// SR-6926
112+
/* 👨‍👩‍👧‍👦👨‍👩‍👧‍👦👨‍👩‍👧‍👦 */
113+
`init`(x: Int, y: Int) {}
114+
class C {
115+
/* 👨‍👩‍👧‍👦👨‍👩‍👧‍👦👨‍👩‍👧‍👦 */
116+
`init`(x: Int, y: Int) {}
117+
}
118+
var // comment
119+
`$` = 1
120+
func /* comment */`foo`(x: Int) {}

test/SourceKit/DocumentStructure/structure.swift.response

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 1670,
3+
key.length: 1970,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1101,6 +1101,113 @@
11011101
key.bodylength: 1
11021102
}
11031103
]
1104+
},
1105+
{
1106+
key.kind: source.lang.swift.expr.call,
1107+
key.name: "`init`",
1108+
key.offset: 1764,
1109+
key.length: 25,
1110+
key.nameoffset: 1764,
1111+
key.namelength: 6,
1112+
key.bodyoffset: 1771,
1113+
key.bodylength: 17,
1114+
key.substructure: [
1115+
{
1116+
key.kind: source.lang.swift.expr.argument,
1117+
key.name: "x",
1118+
key.offset: 1771,
1119+
key.length: 6,
1120+
key.nameoffset: 1771,
1121+
key.namelength: 1,
1122+
key.bodyoffset: 1774,
1123+
key.bodylength: 3
1124+
},
1125+
{
1126+
key.kind: source.lang.swift.expr.argument,
1127+
key.name: "y",
1128+
key.offset: 1779,
1129+
key.length: 6,
1130+
key.nameoffset: 1779,
1131+
key.namelength: 1,
1132+
key.bodyoffset: 1782,
1133+
key.bodylength: 3
1134+
},
1135+
{
1136+
key.kind: source.lang.swift.expr.argument,
1137+
key.offset: 1787,
1138+
key.length: 2,
1139+
key.nameoffset: 0,
1140+
key.namelength: 0,
1141+
key.bodyoffset: 1787,
1142+
key.bodylength: 2,
1143+
key.substructure: [
1144+
{
1145+
key.kind: source.lang.swift.expr.closure,
1146+
key.offset: 1787,
1147+
key.length: 2,
1148+
key.nameoffset: 0,
1149+
key.namelength: 0,
1150+
key.bodyoffset: 1788,
1151+
key.bodylength: 0,
1152+
key.substructure: [
1153+
{
1154+
key.kind: source.lang.swift.stmt.brace,
1155+
key.offset: 1787,
1156+
key.length: 2,
1157+
key.nameoffset: 0,
1158+
key.namelength: 0,
1159+
key.bodyoffset: 1788,
1160+
key.bodylength: 0
1161+
}
1162+
]
1163+
}
1164+
]
1165+
}
1166+
]
1167+
},
1168+
{
1169+
key.kind: source.lang.swift.decl.class,
1170+
key.accessibility: source.lang.swift.accessibility.internal,
1171+
key.name: "C",
1172+
key.offset: 1790,
1173+
key.length: 119,
1174+
key.runtime_name: "_TtC13StructureTest1C",
1175+
key.nameoffset: 1796,
1176+
key.namelength: 1,
1177+
key.bodyoffset: 1799,
1178+
key.bodylength: 109
1179+
},
1180+
{
1181+
key.kind: source.lang.swift.decl.var.global,
1182+
key.accessibility: source.lang.swift.accessibility.internal,
1183+
key.setter_accessibility: source.lang.swift.accessibility.internal,
1184+
key.name: "$",
1185+
key.offset: 1910,
1186+
key.length: 24,
1187+
key.nameoffset: 1927,
1188+
key.namelength: 1
1189+
},
1190+
{
1191+
key.kind: source.lang.swift.decl.function.free,
1192+
key.accessibility: source.lang.swift.accessibility.internal,
1193+
key.name: "foo(x:)",
1194+
key.offset: 1935,
1195+
key.length: 34,
1196+
key.nameoffset: 1953,
1197+
key.namelength: 13,
1198+
key.bodyoffset: 1968,
1199+
key.bodylength: 0,
1200+
key.substructure: [
1201+
{
1202+
key.kind: source.lang.swift.decl.var.parameter,
1203+
key.name: "x",
1204+
key.offset: 1959,
1205+
key.length: 6,
1206+
key.typename: "Int",
1207+
key.nameoffset: 1959,
1208+
key.namelength: 1
1209+
}
1210+
]
11041211
}
11051212
],
11061213
key.diagnostics: [
@@ -1125,6 +1232,23 @@
11251232
key.length: 30
11261233
}
11271234
]
1235+
},
1236+
{
1237+
key.line: 116,
1238+
key.column: 1,
1239+
key.filepath: main.swift,
1240+
key.severity: source.diagnostic.severity.error,
1241+
key.description: "expected declaration",
1242+
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
1243+
key.diagnostics: [
1244+
{
1245+
key.line: 114,
1246+
key.column: 7,
1247+
key.filepath: main.swift,
1248+
key.severity: source.diagnostic.severity.note,
1249+
key.description: "in declaration of 'C'"
1250+
}
1251+
]
11281252
}
11291253
]
11301254
}

0 commit comments

Comments
 (0)