Skip to content

Commit 50b4924

Browse files
committed
Eliminate more vestiges of #line/#column/etc as special syntax nodes.
... along with __LINE__, __FILE__, etc., which have no business being keywords. This can be handled in semantic analysis.
1 parent b7cfd13 commit 50b4924

File tree

6 files changed

+3
-160
lines changed

6 files changed

+3
-160
lines changed

Diff for: Sources/SwiftParser/Expressions.swift

-32
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,6 @@ extension Parser {
973973
/// primary-expression → implicit-member-expression
974974
/// primary-expression → wildcard-expression
975975
/// primary-expression → key-path-expression
976-
/// primary-expression → selector-expression
977-
/// primary-expression → key-path-string-expression
978976
/// primary-expression → macro-expansion-expression
979977
@_spi(RawSyntax)
980978
public mutating func parsePrimaryExpression(
@@ -1011,36 +1009,6 @@ extension Parser {
10111009
booleanLiteral: tok,
10121010
arena: self.arena
10131011
))
1014-
case (.__file__Keyword, let handle)?:
1015-
let tok = self.eat(handle)
1016-
return RawExprSyntax(RawPoundFileExprSyntax(
1017-
poundFile: tok,
1018-
arena: self.arena
1019-
))
1020-
case (.__function__Keyword, let handle)?:
1021-
let tok = self.eat(handle)
1022-
return RawExprSyntax(RawPoundFunctionExprSyntax(
1023-
poundFunction: tok,
1024-
arena: self.arena
1025-
))
1026-
case (.__line__Keyword, let handle)?:
1027-
let tok = self.eat(handle)
1028-
return RawExprSyntax(RawPoundLineExprSyntax(
1029-
poundLine: tok,
1030-
arena: self.arena
1031-
))
1032-
case (.__column__Keyword, let handle)?:
1033-
let tok = self.eat(handle)
1034-
return RawExprSyntax(RawPoundColumnExprSyntax(
1035-
poundColumn: tok,
1036-
arena: self.arena
1037-
))
1038-
case (.__dso_handle__Keyword, let handle)?:
1039-
let tok = self.eat(handle)
1040-
return RawExprSyntax(RawPoundDsohandleExprSyntax(
1041-
poundDsohandle: tok,
1042-
arena: self.arena
1043-
))
10441012
case (.identifier, let handle)?, (.selfKeyword, let handle)?, (.initKeyword, let handle)?:
10451013
// If we have "case let x." or "case let x(", we parse x as a normal
10461014
// name, not a binding, because it is the start of an enum pattern or

Diff for: Sources/SwiftParser/RawTokenKindSubset.swift

-15
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,6 @@ enum ParameterModifier: RawTokenKindSubset {
681681
}
682682

683683
enum PrimaryExpressionStart: RawTokenKindSubset {
684-
case __column__Keyword
685-
case __dso_handle__Keyword
686-
case __file__Keyword
687-
case __function__Keyword
688-
case __line__Keyword
689684
case anyKeyword
690685
case capitalSelfKeyword
691686
case dollarIdentifier
@@ -710,11 +705,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
710705

711706
init?(lexeme: Lexer.Lexeme) {
712707
switch lexeme.tokenKind {
713-
case .__column__Keyword: self = .__column__Keyword
714-
case .__dso_handle__Keyword: self = .__dso_handle__Keyword
715-
case .__file__Keyword: self = .__file__Keyword
716-
case .__function__Keyword: self = .__function__Keyword
717-
case .__line__Keyword: self = .__line__Keyword
718708
case .anyKeyword: self = .anyKeyword
719709
case .capitalSelfKeyword: self = .capitalSelfKeyword
720710
case .dollarIdentifier: self = .dollarIdentifier
@@ -742,11 +732,6 @@ enum PrimaryExpressionStart: RawTokenKindSubset {
742732

743733
var rawTokenKind: SwiftSyntax.RawTokenKind {
744734
switch self {
745-
case .__column__Keyword: return .__column__Keyword
746-
case .__dso_handle__Keyword: return .__dso_handle__Keyword
747-
case .__file__Keyword: return .__file__Keyword
748-
case .__function__Keyword: return .__function__Keyword
749-
case .__line__Keyword: return .__line__Keyword
750735
case .anyKeyword: return .anyKeyword
751736
case .capitalSelfKeyword: return .capitalSelfKeyword
752737
case .dollarIdentifier: return .dollarIdentifier

Diff for: Sources/SwiftParser/TokenPrecedence.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,14 @@ public enum TokenPrecedence: Comparable {
108108
case
109109
// Literals
110110
.capitalSelfKeyword, .falseKeyword, .floatingLiteral, .integerLiteral, .nilKeyword, .regexLiteral, .selfKeyword, .stringLiteral, .superKeyword, .trueKeyword,
111-
// Legacy literals
112-
.__column__Keyword, .__dso_handle__Keyword, .__file__Keyword, .__function__Keyword, .__line__Keyword,
113111
// Pound literals
114-
.poundAvailableKeyword, .poundColorLiteralKeyword, .poundColumnKeyword, .poundDsohandleKeyword, .poundFileIDKeyword, .poundFileKeyword, .poundFileLiteralKeyword, .poundFilePathKeyword, .poundFunctionKeyword, .poundImageLiteralKeyword, .poundKeyPathKeyword, .poundLineKeyword, .poundSelectorKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword, .poundHasSymbolKeyword,
112+
.poundAvailableKeyword, .poundSourceLocationKeyword, .poundUnavailableKeyword, .poundHasSymbolKeyword, .pound,
115113
// Identifiers
116114
.dollarIdentifier, .identifier,
117115
// '_' can occur in types to replace a type identifier
118116
.wildcardKeyword,
119-
// String segment, string interpolation anchor and pound don't really fit anywhere else
120-
.pound, .stringInterpolationAnchor, .stringSegment:
117+
// String segment and string interpolation anchor don't really fit anywhere else
118+
.stringInterpolationAnchor, .stringSegment:
121119
self = .identifierLike
122120

123121
// MARK: Expr keyword

Diff for: Tests/SwiftSyntaxParserTest/TokenTest.swift

-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ public class TokenTests: XCTestCase {
120120
TokenKind.trueKeyword,
121121
TokenKind.tryKeyword,
122122
TokenKind.throwsKeyword,
123-
TokenKind.__file__Keyword,
124-
TokenKind.__line__Keyword,
125-
TokenKind.__column__Keyword,
126-
TokenKind.__function__Keyword,
127-
TokenKind.__dso_handle__Keyword,
128123
TokenKind.wildcardKeyword,
129124
]
130125

Diff for: gyb_syntax_support/ExprNodes.py

-57
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
Child('Expression', kind='Expr'),
1111
]),
1212

13-
# A #column expression.
14-
Node('PoundColumnExpr', name_for_diagnostics=None, kind='Expr',
15-
children=[
16-
Child('PoundColumn', kind='PoundColumnToken'),
17-
]),
18-
1913
Node('TupleExprElementList', name_for_diagnostics=None, kind='SyntaxCollection',
2014
element='TupleExprElement'),
2115

@@ -135,42 +129,6 @@
135129
by a `SequenceExprSyntax`.
136130
'''),
137131

138-
# A #line expression.
139-
Node('PoundLineExpr', name_for_diagnostics=None, kind='Expr',
140-
children=[
141-
Child('PoundLine', kind='PoundLineToken'),
142-
]),
143-
144-
# A #file expression.
145-
Node('PoundFileExpr', name_for_diagnostics=None, kind='Expr',
146-
children=[
147-
Child('PoundFile', kind='PoundFileToken'),
148-
]),
149-
150-
# A #fileID expression.
151-
Node('PoundFileIDExpr', name_for_diagnostics=None, kind='Expr',
152-
children=[
153-
Child('PoundFileID', kind='PoundFileIDToken'),
154-
]),
155-
156-
# A #filePath expression.
157-
Node('PoundFilePathExpr', name_for_diagnostics=None, kind='Expr',
158-
children=[
159-
Child('PoundFilePath', kind='PoundFilePathToken'),
160-
]),
161-
162-
# A #function expression.
163-
Node('PoundFunctionExpr', name_for_diagnostics=None, kind='Expr',
164-
children=[
165-
Child('PoundFunction', kind='PoundFunctionToken'),
166-
]),
167-
168-
# A #dsohandle expression.
169-
Node('PoundDsohandleExpr', name_for_diagnostics=None, kind='Expr',
170-
children=[
171-
Child('PoundDsohandle', kind='PoundDsohandleToken'),
172-
]),
173-
174132
# symbolic-reference-expression -> identifier generic-argument-clause?
175133
Node('SymbolicReferenceExpr', name_for_diagnostics=None, kind='Expr',
176134
children=[
@@ -718,21 +676,6 @@
718676
children=[
719677
Child('Identifier', kind='IdentifierToken'),
720678
]),
721-
# #fileLiteral(a, b, c)
722-
Node('ObjectLiteralExpr', name_for_diagnostics='object literal', kind='Expr',
723-
traits=['Parenthesized'],
724-
children=[
725-
Child('Identifier', kind='Token',
726-
token_choices=[
727-
'PoundColorLiteralToken',
728-
'PoundFileLiteralToken',
729-
'PoundImageLiteralToken',
730-
]),
731-
Child('LeftParen', kind='LeftParenToken'),
732-
Child('Arguments', kind='TupleExprElementList',
733-
collection_element_name='Argument'),
734-
Child('RightParen', kind='RightParenToken'),
735-
]),
736679

737680
Node('YieldExprList', name_for_diagnostics='yield list',
738681
kind='SyntaxCollection',

Diff for: gyb_syntax_support/Token.py

-46
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,6 @@ def macro_name(self):
9999
return "POUND_KEYWORD"
100100

101101

102-
class PoundObjectLiteral(PoundKeyword):
103-
def __init__(self, name, kind, text, name_for_diagnostics,
104-
protocol, classification='ObjectLiteral'):
105-
PoundKeyword.__init__(
106-
self,
107-
name=name,
108-
kind=kind,
109-
text=text,
110-
name_for_diagnostics=name_for_diagnostics,
111-
classification=classification
112-
)
113-
self.description = name_for_diagnostics
114-
self.protocol = protocol
115-
116-
def macro_name(self):
117-
return "POUND_OBJECT_LITERAL"
118-
119-
120102
class PoundConfig(PoundKeyword):
121103
def macro_name(self):
122104
return "POUND_CONFIG"
@@ -244,12 +226,6 @@ def macro_name(self):
244226
ExprKeyword('Try', 'try'),
245227
ExprKeyword('Throws', 'throws'),
246228

247-
Keyword('__FILE__', '__FILE__'),
248-
Keyword('__LINE__', '__LINE__'),
249-
Keyword('__COLUMN__', '__COLUMN__'),
250-
Keyword('__FUNCTION__', '__FUNCTION__'),
251-
Keyword('__DSO_HANDLE__', '__DSO_HANDLE__'),
252-
253229
# Pattern keywords
254230
PatternKeyword('Wildcard', '_'),
255231

@@ -298,15 +274,6 @@ def macro_name(self):
298274

299275
# Keywords prefixed with a '#'.
300276

301-
PoundKeyword('PoundKeyPath', 'keyPath', text='#keyPath'),
302-
PoundKeyword('PoundLine', 'line', text='#line'),
303-
PoundKeyword('PoundSelector', 'selector', text='#selector'),
304-
PoundKeyword('PoundFile', 'file', text='#file'),
305-
PoundKeyword('PoundFileID', 'fileID', text='#fileID'),
306-
PoundKeyword('PoundFilePath', 'filePath', text='#filePath'),
307-
PoundKeyword('PoundColumn', 'column', text='#column'),
308-
PoundKeyword('PoundFunction', 'function', text='#function'),
309-
PoundKeyword('PoundDsohandle', 'dsohandle', text='#dsohandle'),
310277
PoundKeyword('PoundAssert', 'assert', text='#assert'),
311278

312279
PoundDirectiveKeyword('PoundSourceLocation', 'sourceLocation',
@@ -324,19 +291,6 @@ def macro_name(self):
324291
PoundConfig('PoundAvailable', 'available', text='#available'),
325292
PoundConfig('PoundUnavailable', 'unavailable', text='#unavailable'),
326293

327-
PoundObjectLiteral('PoundFileLiteral', 'fileLiteral',
328-
text='#fileLiteral',
329-
name_for_diagnostics='file reference',
330-
protocol='ExpressibleByFileReferenceLiteral'),
331-
PoundObjectLiteral('PoundImageLiteral', 'imageLiteral',
332-
text='#imageLiteral',
333-
name_for_diagnostics='image',
334-
protocol='ExpressibleByImageLiteral'),
335-
PoundObjectLiteral('PoundColorLiteral', 'colorLiteral',
336-
text='#colorLiteral',
337-
name_for_diagnostics='color',
338-
protocol='ExpressibleByColorLiteral'),
339-
340294
PoundConfig('PoundHasSymbol', '_hasSymbol', text='#_hasSymbol'),
341295

342296
Literal('IntegerLiteral', 'integer_literal', name_for_diagnostics='integer literal',

0 commit comments

Comments
 (0)