Skip to content

Commit 16baa8b

Browse files
committed
Stop parsing #assert with a special production.
It's subsumed by macro expansion declarations.
1 parent 00c6476 commit 16baa8b

File tree

4 files changed

+8
-47
lines changed

4 files changed

+8
-47
lines changed

Sources/SwiftParser/Lexer/Cursor.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,6 @@ extension Lexer.Cursor {
14581458

14591459
let kind: RawTokenKind
14601460
switch literal {
1461-
case "assert": kind = .poundAssertKeyword
14621461
case "sourceLocation": kind = .poundSourceLocationKeyword
14631462
case "warning": kind = .poundWarningKeyword
14641463
case "error": kind = .poundErrorKeyword

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
104104
case forKeyword
105105
case guardKeyword
106106
case ifKeyword
107-
case poundAssertKeyword
108107
case repeatKeyword
109108
case returnKeyword
110109
case switchKeyword
@@ -122,7 +121,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
122121
case RawTokenKindMatch(.for): self = .forKeyword
123122
case RawTokenKindMatch(.guard): self = .guardKeyword
124123
case RawTokenKindMatch(.if): self = .ifKeyword
125-
case RawTokenKindMatch(.poundAssertKeyword): self = .poundAssertKeyword
126124
case RawTokenKindMatch(.repeat): self = .repeatKeyword
127125
case RawTokenKindMatch(.return): self = .returnKeyword
128126
case RawTokenKindMatch(.switch): self = .switchKeyword
@@ -143,7 +141,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
143141
case .forKeyword: return .keyword(.for)
144142
case .guardKeyword: return .keyword(.guard)
145143
case .ifKeyword: return .keyword(.if)
146-
case .poundAssertKeyword: return .poundAssertKeyword
147144
case .repeatKeyword: return .keyword(.repeat)
148145
case .returnKeyword: return .keyword(.return)
149146
case .switchKeyword: return .keyword(.switch)

Sources/SwiftParser/Statements.swift

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ extension Parser {
116116
return label(self.parseDeferStatement(deferHandle: handle), with: optLabel)
117117
case (.doKeyword, let handle)?:
118118
return label(self.parseDoStatement(doHandle: handle), with: optLabel)
119-
case (.poundAssertKeyword, let handle)?:
120-
return label(self.parsePoundAssertStatement(poundAssertHandle: handle), with: optLabel)
121119
case (.yield, let handle)?:
122120
return label(self.parseYieldStatement(yieldHandle: handle), with: optLabel)
123121
case nil:
@@ -1175,35 +1173,6 @@ extension Parser {
11751173
}
11761174
}
11771175

1178-
extension Parser {
1179-
@_spi(RawSyntax)
1180-
public mutating func parsePoundAssertStatement(poundAssertHandle: RecoveryConsumptionHandle) -> RawPoundAssertStmtSyntax {
1181-
let (unexpectedBeforePoundAssert, poundAssert) = self.eat(poundAssertHandle)
1182-
let (unexpectedBeforeLParen, lparen) = self.expect(.leftParen)
1183-
let condition = self.parseExpression()
1184-
let comma = self.consume(if: .comma)
1185-
let message: RawStringLiteralExprSyntax?
1186-
if comma != nil {
1187-
message = self.parseStringLiteral()
1188-
} else {
1189-
message = nil
1190-
}
1191-
let (unexpectedBeforeRParen, rparen) = self.expect(.rightParen)
1192-
return RawPoundAssertStmtSyntax(
1193-
unexpectedBeforePoundAssert,
1194-
poundAssert: poundAssert,
1195-
unexpectedBeforeLParen,
1196-
leftParen: lparen,
1197-
condition: condition,
1198-
comma: comma,
1199-
message: message,
1200-
unexpectedBeforeRParen,
1201-
rightParen: rparen,
1202-
arena: self.arena
1203-
)
1204-
}
1205-
}
1206-
12071176
// MARK: Lookahead
12081177

12091178
extension Parser.Lookahead {
@@ -1237,8 +1206,7 @@ extension Parser.Lookahead {
12371206
.breakKeyword?,
12381207
.continueKeyword?,
12391208
.fallthroughKeyword?,
1240-
.switchKeyword?,
1241-
.poundAssertKeyword?:
1209+
.switchKeyword?:
12421210
return true
12431211
case .repeatKeyword?:
12441212
// 'repeat' followed by anything other than a brace stmt

Tests/SwiftParserTest/translated/PoundAssertTests.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ final class PoundAssertTests: XCTestCase {
1919
AssertParse(
2020
"""
2121
#assert(true, 1️⃣123)
22-
""",
23-
diagnostics: [
24-
DiagnosticSpec(message: "expected string literal in '#assert' directive"),
25-
DiagnosticSpec(message: "unexpected code '123' in '#assert' directive"),
26-
]
22+
"""
2723
)
2824
}
2925

@@ -38,10 +34,11 @@ final class PoundAssertTests: XCTestCase {
3834
func testPoundAssert3() {
3935
AssertParse(
4036
#"""
41-
#assert 1️⃣true, "error message")
37+
#assert1️⃣ true2️⃣, "error message")
4238
"""#,
4339
diagnostics: [
44-
DiagnosticSpec(message: "expected '(' in '#assert' directive")
40+
DiagnosticSpec(message: "consecutive statements on a line must be separated by ';'"),
41+
DiagnosticSpec(locationMarker: "2️⃣", message: #"extraneous code ', "error message")' at top level"#)
4542
]
4643
)
4744
}
@@ -52,7 +49,7 @@ final class PoundAssertTests: XCTestCase {
5249
#assert(1️⃣, "error message")
5350
"""#,
5451
diagnostics: [
55-
DiagnosticSpec(message: "expected condition in '#assert' directive")
52+
DiagnosticSpec(message: "expected value in pound literal declaration")
5653
]
5754
)
5855
}
@@ -66,7 +63,7 @@ final class PoundAssertTests: XCTestCase {
6663
""",
6764
diagnostics: [
6865
DiagnosticSpec(
69-
message: "expected ')' to end '#assert' directive",
66+
message: "expected ')' to end pound literal declaration",
7067
notes: [
7168
NoteSpec(message: "to match this opening '('")
7269
]
@@ -84,7 +81,7 @@ final class PoundAssertTests: XCTestCase {
8481
"""#,
8582
diagnostics: [
8683
DiagnosticSpec(
87-
message: "expected ')' to end '#assert' directive",
84+
message: "expected ')' to end pound literal declaration",
8885
notes: [
8986
NoteSpec(message: "to match this opening '('")
9087
]

0 commit comments

Comments
 (0)