Skip to content

Commit 8b1673a

Browse files
authored
Merge pull request #14553 from rintaro/5.0-lex-escaped-eof
[5.0][Lexer] Don't setEscapedIdentifier(true) for tok::eof at ArtificialEOF
2 parents 67f936a + d358a50 commit 8b1673a

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
@@ -281,6 +281,10 @@ void Lexer::formEscapedIdentifierToken(const char *TokStart) {
281281
TrailingTrivia.push_back(TriviaPiece::backtick());
282282
}
283283
formToken(tok::identifier, TokStart);
284+
// If this token is at ArtificialEOF, it's forced to be tok::eof. Don't mark
285+
// this as escaped-identifier in this case.
286+
if (NextToken.is(tok::eof))
287+
return;
284288
NextToken.setEscapedIdentifier(true);
285289
}
286290

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
{
@@ -1095,6 +1095,113 @@
10951095
key.bodylength: 1
10961096
}
10971097
]
1098+
},
1099+
{
1100+
key.kind: source.lang.swift.expr.call,
1101+
key.name: "`init`",
1102+
key.offset: 1764,
1103+
key.length: 25,
1104+
key.nameoffset: 1764,
1105+
key.namelength: 6,
1106+
key.bodyoffset: 1771,
1107+
key.bodylength: 17,
1108+
key.substructure: [
1109+
{
1110+
key.kind: source.lang.swift.expr.argument,
1111+
key.name: "x",
1112+
key.offset: 1771,
1113+
key.length: 6,
1114+
key.nameoffset: 1771,
1115+
key.namelength: 1,
1116+
key.bodyoffset: 1774,
1117+
key.bodylength: 3
1118+
},
1119+
{
1120+
key.kind: source.lang.swift.expr.argument,
1121+
key.name: "y",
1122+
key.offset: 1779,
1123+
key.length: 6,
1124+
key.nameoffset: 1779,
1125+
key.namelength: 1,
1126+
key.bodyoffset: 1782,
1127+
key.bodylength: 3
1128+
},
1129+
{
1130+
key.kind: source.lang.swift.expr.argument,
1131+
key.offset: 1787,
1132+
key.length: 2,
1133+
key.nameoffset: 0,
1134+
key.namelength: 0,
1135+
key.bodyoffset: 1787,
1136+
key.bodylength: 2,
1137+
key.substructure: [
1138+
{
1139+
key.kind: source.lang.swift.expr.closure,
1140+
key.offset: 1787,
1141+
key.length: 2,
1142+
key.nameoffset: 0,
1143+
key.namelength: 0,
1144+
key.bodyoffset: 1788,
1145+
key.bodylength: 0,
1146+
key.substructure: [
1147+
{
1148+
key.kind: source.lang.swift.stmt.brace,
1149+
key.offset: 1787,
1150+
key.length: 2,
1151+
key.nameoffset: 0,
1152+
key.namelength: 0,
1153+
key.bodyoffset: 1788,
1154+
key.bodylength: 0
1155+
}
1156+
]
1157+
}
1158+
]
1159+
}
1160+
]
1161+
},
1162+
{
1163+
key.kind: source.lang.swift.decl.class,
1164+
key.accessibility: source.lang.swift.accessibility.internal,
1165+
key.name: "C",
1166+
key.offset: 1790,
1167+
key.length: 119,
1168+
key.runtime_name: "_TtC13StructureTest1C",
1169+
key.nameoffset: 1796,
1170+
key.namelength: 1,
1171+
key.bodyoffset: 1799,
1172+
key.bodylength: 109
1173+
},
1174+
{
1175+
key.kind: source.lang.swift.decl.var.global,
1176+
key.accessibility: source.lang.swift.accessibility.internal,
1177+
key.setter_accessibility: source.lang.swift.accessibility.internal,
1178+
key.name: "$",
1179+
key.offset: 1910,
1180+
key.length: 24,
1181+
key.nameoffset: 1927,
1182+
key.namelength: 1
1183+
},
1184+
{
1185+
key.kind: source.lang.swift.decl.function.free,
1186+
key.accessibility: source.lang.swift.accessibility.internal,
1187+
key.name: "foo(x:)",
1188+
key.offset: 1935,
1189+
key.length: 34,
1190+
key.nameoffset: 1953,
1191+
key.namelength: 13,
1192+
key.bodyoffset: 1968,
1193+
key.bodylength: 0,
1194+
key.substructure: [
1195+
{
1196+
key.kind: source.lang.swift.decl.var.parameter,
1197+
key.name: "x",
1198+
key.offset: 1959,
1199+
key.length: 6,
1200+
key.typename: "Int",
1201+
key.nameoffset: 1959,
1202+
key.namelength: 1
1203+
}
1204+
]
10981205
}
10991206
],
11001207
key.diagnostics: [
@@ -1119,6 +1226,23 @@
11191226
key.length: 30
11201227
}
11211228
]
1229+
},
1230+
{
1231+
key.line: 116,
1232+
key.column: 1,
1233+
key.filepath: main.swift,
1234+
key.severity: source.diagnostic.severity.error,
1235+
key.description: "expected declaration",
1236+
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
1237+
key.diagnostics: [
1238+
{
1239+
key.line: 114,
1240+
key.column: 7,
1241+
key.filepath: main.swift,
1242+
key.severity: source.diagnostic.severity.note,
1243+
key.description: "in declaration of 'C'"
1244+
}
1245+
]
11221246
}
11231247
]
11241248
}

0 commit comments

Comments
 (0)