Skip to content

Commit 20ff3b6

Browse files
committed
[Parser] Stop producing PoundLineExprSyntax nodes.
Instead, have `#line` create the more general `MacroExpansionExprSyntax` node.
1 parent 22b87b2 commit 20ff3b6

File tree

6 files changed

+6
-32
lines changed

6 files changed

+6
-32
lines changed

Sources/SwiftParser/Directives.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,6 @@ extension Parser {
123123
}
124124

125125
extension Parser {
126-
/// Parse a #line literal.
127-
///
128-
/// Grammar
129-
/// =======
130-
///
131-
/// literal-expression → '#line'
132-
@_spi(RawSyntax)
133-
public mutating func parsePoundLineDirective() -> RawPoundLineExprSyntax {
134-
let (unexpectedBeforeToken, token) = self.expect(.poundLineKeyword)
135-
return RawPoundLineExprSyntax(
136-
unexpectedBeforeToken,
137-
poundLine: token,
138-
arena: self.arena
139-
)
140-
}
141-
142126
/// Parse a line control directive.
143127
///
144128
/// Grammar

Sources/SwiftParser/Expressions.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,12 +1047,6 @@ extension Parser {
10471047
poundFunction: tok,
10481048
arena: self.arena
10491049
))
1050-
case (.poundLineKeyword, let handle)?:
1051-
let tok = self.eat(handle)
1052-
return RawExprSyntax(RawPoundLineExprSyntax(
1053-
poundLine: tok,
1054-
arena: self.arena
1055-
))
10561050
case (.__line__Keyword, let handle)?:
10571051
let tok = self.eat(handle)
10581052
return RawExprSyntax(RawPoundLineExprSyntax(

Sources/SwiftParser/Lexer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,6 @@ extension Lexer.Cursor {
15391539
let kind: RawTokenKind
15401540
switch literal {
15411541
case "keyPath": kind = .poundKeyPathKeyword
1542-
case "line": kind = .poundLineKeyword
15431542
case "selector": kind = .poundSelectorKeyword
15441543
case "file": kind = .poundFileKeyword
15451544
case "fileID": kind = .poundFileIDKeyword

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ enum CanBeDeclaratinStart: RawTokenKindSubset {
110110
case operatorKeyword
111111
case poundErrorKeyword
112112
case poundIfKeyword
113-
case poundLineKeyword
114113
case poundSourceLocationKeyword
115114
case poundWarningKeyword
116115
case precedencegroupKeyword
@@ -142,7 +141,6 @@ enum CanBeDeclaratinStart: RawTokenKindSubset {
142141
case .operatorKeyword: self = .operatorKeyword
143142
case .poundErrorKeyword: self = .poundErrorKeyword
144143
case .poundIfKeyword: self = .poundIfKeyword
145-
case .poundLineKeyword where lexeme.isAtStartOfLine: self = .poundLineKeyword
146144
case .poundSourceLocationKeyword: self = .poundSourceLocationKeyword
147145
case .poundWarningKeyword: self = .poundWarningKeyword
148146
case .precedencegroupKeyword: self = .precedencegroupKeyword
@@ -177,7 +175,6 @@ enum CanBeDeclaratinStart: RawTokenKindSubset {
177175
case .operatorKeyword: return .operatorKeyword
178176
case .poundErrorKeyword: return .poundErrorKeyword
179177
case .poundIfKeyword: return .poundIfKeyword
180-
case .poundLineKeyword: return .poundLineKeyword
181178
case .poundSourceLocationKeyword: return .poundSourceLocationKeyword
182179
case .poundWarningKeyword: return .poundWarningKeyword
183180
case .precedencegroupKeyword: return .precedencegroupKeyword
@@ -751,7 +748,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
751748
case poundFunctionKeyword
752749
case poundImageLiteralKeyword
753750
case poundKeyPathKeyword
754-
case poundLineKeyword
755751
case poundSelectorKeyword
756752
case prefixPeriod
757753
case regexLiteral
@@ -791,7 +787,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
791787
case .poundFunctionKeyword: self = .poundFunctionKeyword
792788
case .poundImageLiteralKeyword: self = .poundImageLiteralKeyword
793789
case .poundKeyPathKeyword: self = .poundKeyPathKeyword
794-
case .poundLineKeyword: self = .poundLineKeyword
795790
case .poundSelectorKeyword: self = .poundSelectorKeyword
796791
case .prefixPeriod: self = .prefixPeriod
797792
case .regexLiteral: self = .regexLiteral
@@ -834,7 +829,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
834829
case .poundFunctionKeyword: return .poundFunctionKeyword
835830
case .poundImageLiteralKeyword: return .poundImageLiteralKeyword
836831
case .poundKeyPathKeyword: return .poundKeyPathKeyword
837-
case .poundLineKeyword: return .poundLineKeyword
838832
case .poundSelectorKeyword: return .poundSelectorKeyword
839833
case .prefixPeriod: return .prefixPeriod
840834
case .regexLiteral: return .regexLiteral

Sources/SwiftParser/TopLevel.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ extension Parser {
172172
return RawSyntax(RawCodeBlockItemListSyntax(elements: items, arena: parser.arena))
173173
}
174174
return RawSyntax(directive)
175-
} else if self.at(.poundLineKeyword) {
176-
return RawSyntax(self.parsePoundLineDirective())
177175
} else if self.at(.poundSourceLocationKeyword) {
178176
return RawSyntax(self.parsePoundSourceLocationDirective())
179177
} else if self.atStartOfDeclaration() {

Tests/SwiftParserTest/Expressions.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ final class ExpressionTests: XCTestCase {
301301
]
302302
""",
303303
substructure: Syntax(DictionaryElementSyntax.init(
304-
keyExpression: ExprSyntax(PoundLineExprSyntax(poundLine: .poundLineKeyword())),
304+
keyExpression: ExprSyntax(
305+
MacroExpansionExprSyntax(
306+
poundToken: .poundToken(), macro: .identifier("line"),
307+
leftParen: nil, argumentList: TupleExprElementListSyntax([]),
308+
rightParen: nil, trailingClosure: nil,
309+
additionalTrailingClosures: nil)),
305310
colon: .colonToken(),
306311
valueExpression: ExprSyntax(FunctionCallExprSyntax(
307312
calledExpression: ExprSyntax(IdentifierExprSyntax(identifier: .identifier("Calendar"), declNameArguments: nil)),

0 commit comments

Comments
 (0)