Skip to content

Commit c706d4c

Browse files
committed
tbs
1 parent 6268c80 commit c706d4c

File tree

7 files changed

+55
-9
lines changed

7 files changed

+55
-9
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public let COMMON_NODES: [Node] = [
177177
kind: .decl,
178178
base: .syntax,
179179
nameForDiagnostics: "declaration",
180-
parserFunction: "parseDeclaration"
180+
parserFunction: "parseDeclarationOrIfConfig"
181181
),
182182

183183
Node(

CodeGeneration/Sources/generate-swift-syntax/templates/swiftparser/LayoutNodesParsableFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ let layoutNodesParsableFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
6868
DeclSyntax(
6969
"""
7070
mutating func parseNonOptionalCodeBlockItem() -> RawCodeBlockItemSyntax {
71-
guard let node = self.parseCodeBlockItem(isAtTopLevel: false, allowInitDecl: true) else {
71+
guard let node = self.self.parseCodeBlockItem(allowInitDecl: true, until: { _ in false }) else {
7272
// The missing item is not necessary to be a declaration,
7373
// which is just a placeholder here
7474
return RawCodeBlockItemSyntax(

Sources/SwiftParser/Declarations.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,3 +2368,17 @@ extension Parser {
23682368
)
23692369
}
23702370
}
2371+
2372+
extension Parser {
2373+
mutating func parseDeclarationOrIfConfig() -> RawDeclSyntax {
2374+
if self.at(.poundIf) {
2375+
return RawDeclSyntax(
2376+
self.parsePoundIfDirective({
2377+
.decls($0.parseMemberDeclList(until: { $0.atEndOfIfConfigClauseBody() }))
2378+
})
2379+
)
2380+
} else {
2381+
return parseDeclaration(in: .memberDeclList)
2382+
}
2383+
}
2384+
}

Sources/SwiftParser/Statements.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,6 @@ extension Parser.Lookahead {
10301030
/// - Note: This function must be kept in sync with `parseStatement()`.
10311031
/// - Seealso: ``Parser/parseStatement()``
10321032
mutating func atStartOfStatement(preferExpr: Bool) -> Bool {
1033-
// if self.atStartOfSwitchCase() {
1034-
// // We consider 'case' statements so we don't parse the start of a new case item as trailing parts of an expression.
1035-
// return true
1036-
// }
1037-
10381033
_ = self.consume(if: .identifier, followedBy: .colon)
10391034
switch self.at(anyIn: CanBeStatementStart.self)?.0 {
10401035
case .return?,

Sources/SwiftParser/generated/LayoutNodes+Parsable.swift

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SwiftParserTest/Parser+EntryTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,39 @@ class EntryTests: ParserTestCase {
3737
)
3838
}
3939

40+
func testDeclSyntaxParseIfConfig() throws {
41+
assertParse(
42+
"""
43+
#if FLAG
44+
func test() {}
45+
#endif
46+
""",
47+
{ DeclSyntax.parse(from: &$0) },
48+
substructure: IfConfigDeclSyntax(
49+
clauses: IfConfigClauseListSyntax([
50+
IfConfigClauseSyntax(
51+
poundKeyword: .poundIfToken(),
52+
condition: ExprSyntax(DeclReferenceExprSyntax(baseName: .identifier("FLAG"))),
53+
elements: .init([
54+
MemberBlockItemSyntax(
55+
decl: DeclSyntax(
56+
FunctionDeclSyntax(
57+
funcKeyword: .keyword(.func),
58+
name: .identifier("test"),
59+
signature: FunctionSignatureSyntax(
60+
parameterClause: FunctionParameterClauseSyntax(parameters: [])
61+
),
62+
body: CodeBlockSyntax(statements: [])
63+
)
64+
)
65+
)
66+
])
67+
)
68+
])
69+
)
70+
)
71+
}
72+
4073
func testRemainderUnexpected() throws {
4174
assertParse(
4275
"func test() {} 1️⃣other tokens",

0 commit comments

Comments
 (0)