Skip to content

Commit ef80186

Browse files
authored
Merge pull request #792 from CodaFi/action!
2 parents b287015 + ded0898 commit ef80186

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Sources/SwiftParser/Declarations.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
@_spi(RawSyntax) import SwiftSyntax
1414

1515
extension TokenConsumer {
16-
func atStartOfDeclaration(isAtTopLevel: Bool = false, allowRecovery: Bool = false) -> Bool {
16+
func atStartOfDeclaration(
17+
isAtTopLevel: Bool = false,
18+
allowRecovery: Bool = false
19+
) -> Bool {
1720
if self.at(anyIn: PoundDeclarationStart.self) != nil {
1821
return true
1922
}
@@ -54,6 +57,19 @@ extension TokenConsumer {
5457
declStartKeyword = subparser.at(anyIn: DeclarationStart.self)?.0
5558
}
5659
switch declStartKeyword {
60+
case .actorContextualKeyword:
61+
// actor Foo {}
62+
if subparser.peek().tokenKind == .identifier {
63+
return true
64+
}
65+
// actor may be somewhere in the modifier list. Eat the tokens until we get
66+
// to something that isn't the start of a decl. If that is an identifier,
67+
// it's an actor declaration, otherwise, it isn't.
68+
var lookahead = subparser.lookahead()
69+
repeat {
70+
lookahead.consumeAnyToken()
71+
} while lookahead.atStartOfDeclaration()
72+
return lookahead.at(.identifier)
5773
case .caseKeyword, nil:
5874
// When 'case' appears inside a function, it's probably a switch
5975
// case, not an enum case declaration.

Tests/SwiftParserTest/Declarations.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,12 +953,6 @@ final class DeclarationTests: XCTestCase {
953953
}
954954

955955
func testBogusTypeDeclName() {
956-
AssertParse("actor #^DIAG_BEFORE^#5s#^DIAG_AFTER^#",
957-
diagnostics: [
958-
DiagnosticSpec(locationMarker: "DIAG_BEFORE", message: "identifier can only start with a letter or underscore, not a number"),
959-
DiagnosticSpec(locationMarker: "DIAG_AFTER", message: "Expected '{' to start actor"),
960-
DiagnosticSpec(locationMarker: "DIAG_AFTER", message: "Expected '}' to end actor")
961-
])
962956
AssertParse("associatedtype #^DIAG_BEFORE^#5s#^DIAG_AFTER^#",
963957
diagnostics: [
964958
DiagnosticSpec(locationMarker: "DIAG_BEFORE", message: "identifier can only start with a letter or underscore, not a number"),

Tests/SwiftParserTest/Statements.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ final class StatementTests: XCTestCase {
9191
}
9292

9393
func testReturn() {
94+
AssertParse("return actor", { $0.parseReturnStatement() })
95+
9496
AssertParse("{ #^ASYNC^#return 0 }",
9597
{ $0.parseClosureExpression() },
9698
substructure: Syntax(ReturnStmtSyntax(returnKeyword: .returnKeyword(),

0 commit comments

Comments
 (0)