Skip to content

Commit 0db788c

Browse files
committed
Stop parsing into PoundColumnExprSyntax, add a macro instead
1 parent f228056 commit 0db788c

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,12 +1053,6 @@ extension Parser {
10531053
poundLine: tok,
10541054
arena: self.arena
10551055
))
1056-
case (.poundColumnKeyword, let handle)?:
1057-
let tok = self.eat(handle)
1058-
return RawExprSyntax(RawPoundColumnExprSyntax(
1059-
poundColumn: tok,
1060-
arena: self.arena
1061-
))
10621056
case (.__column__Keyword, let handle)?:
10631057
let tok = self.eat(handle)
10641058
return RawExprSyntax(RawPoundColumnExprSyntax(

Sources/SwiftParser/Lexer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,6 @@ extension Lexer.Cursor {
15431543
case "file": kind = .poundFileKeyword
15441544
case "fileID": kind = .poundFileIDKeyword
15451545
case "filePath": kind = .poundFilePathKeyword
1546-
case "column": kind = .poundColumnKeyword
15471546
case "function": kind = .poundFunctionKeyword
15481547
case "dsohandle": kind = .poundDsohandleKeyword
15491548
case "assert": kind = .poundAssertKeyword

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
739739
case period
740740
case pound
741741
case poundColorLiteralKeyword
742-
case poundColumnKeyword
743742
case poundDsohandleKeyword
744743
case poundFileIDKeyword
745744
case poundFileKeyword
@@ -778,7 +777,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
778777
case .period: self = .period
779778
case .pound: self = .pound
780779
case .poundColorLiteralKeyword: self = .poundColorLiteralKeyword
781-
case .poundColumnKeyword: self = .poundColumnKeyword
782780
case .poundDsohandleKeyword: self = .poundDsohandleKeyword
783781
case .poundFileIDKeyword: self = .poundFileIDKeyword
784782
case .poundFileKeyword: self = .poundFileKeyword
@@ -820,7 +818,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
820818
case .period: return .period
821819
case .pound: return .pound
822820
case .poundColorLiteralKeyword: return .poundColorLiteralKeyword
823-
case .poundColumnKeyword: return .poundColumnKeyword
824821
case .poundDsohandleKeyword: return .poundDsohandleKeyword
825822
case .poundFileIDKeyword: return .poundFileIDKeyword
826823
case .poundFileKeyword: return .poundFileKeyword

Sources/SwiftSyntaxMacros/MacroSystem+Examples.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import SwiftSyntax
22
import SwiftSyntaxBuilder
33

44
// Macros used for testing purposes
5+
struct ColumnMacro: ExpressionMacro {
6+
static var name: String { "column" }
7+
8+
static func apply(
9+
_ macro: MacroExpansionExprSyntax, in context: MacroEvaluationContext
10+
) -> MacroResult<ExprSyntax> {
11+
let line = macro.startLocation(
12+
converter: context.sourceLocationConverter
13+
).column ?? 0
14+
return .init("\(line)")
15+
}
16+
}
17+
518
struct LineMacro: ExpressionMacro {
619
static var name: String { "line" }
720

@@ -47,6 +60,7 @@ struct ColorLiteral: ExpressionMacro {
4760
extension MacroSystem {
4861
public static var exampleSystem: MacroSystem {
4962
var macroSystem = MacroSystem()
63+
try! macroSystem.add(ColumnMacro.self)
5064
try! macroSystem.add(LineMacro.self)
5165
try! macroSystem.add(Stringify.self)
5266
try! macroSystem.add(ColorLiteral.self)

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class MacroSystemTests: XCTestCase {
1212
let a = (#line)
1313
let b = #stringify(x + y)
1414
#myColorLiteral(red: 0.5, green: 0.5, blue: 0.25, alpha: 1.0)
15+
let c = #column
1516
"""
1617
let converter = SourceLocationConverter(file: "test.swift", tree: sf)
1718
let context = MacroEvaluationContext(sourceLocationConverter: converter)
@@ -25,6 +26,7 @@ final class MacroSystemTests: XCTestCase {
2526
let a = (2)
2627
let b = (x + y, #"x + y"#)
2728
.init(red: 0.5, green: 0.5, blue: 0.25, alpha: 1.0)
29+
let c = 9
2830
"""
2931
)
3032
}

0 commit comments

Comments
 (0)