swiftlang / swiftlang/swift-syntax
Refactor `IfConfigClauseSyntax` to disallow starting an if config clause with `#else`
- Dominant language
- Swift
- Stars
- 3.7k
- Forks
- 553
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 16
Description
Currently, `IfConfigClause` can happily represent the following code
```swift
#else
doSomeStuff()
#if true
doSomeStuff()
#elseif true
doSomeStuff()
#if true
doSomeStuff()
#endif
```
While the parser won’t accept it, the syntax tree just shouldn’t be able to represent it. We should refactor the parser to disallow this.
`IfConfigClause` should have a structure that looks like the following (subject to change if I change my mind):
- `IfConfigElementList`: `(CodeBlockItemListSyntax | SwitchCaseListSyntax | MemberBlockItemListSyntax | ExprSyntax | AttributeListSyntax)`
- `IfConfigDeclSyntax`
- poundIfKeyword: `'#if'`
- ifCondition: `ExprSyntax`
- ifElements: `IfConfigElementList`
- elseIfClauses: `IfConfigElseIfClause*`
- elseClause: `IfConfigElseClause?`
- poundEndIfKeyword: `#endif`
- `IfConfigElseIfClause`
- elseIfKeyword: `#elseif`
- condition: `ExprSyntax`
- elements: `IfConfigElementList`
- `IfConfigElseClause`
- elseKeyword: `#else`
- elements: `IfConfigElementList`
Contributor guide
Assessment
This issue has not been assessed yet.