Skip to content

Commit ab73c54

Browse files
committed
Merge 'yield' to new keyword infrastructure
1 parent 8432c4b commit ab73c54

File tree

13 files changed

+13
-81
lines changed

13 files changed

+13
-81
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/StmtNodes.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,12 @@ public let STMT_NODES: [Node] = [
311311
kind: "Stmt",
312312
children: [
313313
Child(name: "YieldKeyword",
314-
kind: "YieldToken",
314+
kind: "KeywordToken",
315315
tokenChoices: [
316-
"Yield"
316+
"Keyword"
317+
],
318+
textChoices: [
319+
"yield"
317320
]),
318321
Child(name: "Yields",
319322
kind: "Syntax",

CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ public let SYNTAX_TOKENS: [TokenSpec] = [
267267
MiscSpec(name: "Keyword", kind: "keyword", nameForDiagnostics: "keyword", classification: "Keyword", associatedValueClass: "Keyword"),
268268
MiscSpec(name: "RawStringDelimiter", kind: "raw_string_delimiter", nameForDiagnostics: "raw string delimiter"),
269269
MiscSpec(name: "StringSegment", kind: "string_segment", nameForDiagnostics: "string segment", classification: "StringLiteral"),
270-
MiscSpec(name: "Yield", kind: "kw_yield", nameForDiagnostics: "yield", text: "yield"),
271270
]
272271

273272
public let SYNTAX_TOKEN_MAP = Dictionary(uniqueKeysWithValues: SYNTAX_TOKENS.map { ("\($0.name)Token", $0) })

Sources/IDEUtils/generated/SyntaxClassification.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ extension RawTokenKind {
266266
return .none
267267
case .stringSegment:
268268
return .stringLiteral
269-
case .yield:
270-
return .none
271269
case .eof:
272270
return .none
273271
}

Sources/SwiftParser/RawTokenKindSubset.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ enum CanBeStatementStart: RawTokenKindSubset {
111111
case throwKeyword
112112
case whileKeyword
113113
case yield
114-
case yieldAsIdentifier
115114

116115
init?(lexeme: Lexer.Lexeme) {
117116
switch lexeme {
@@ -129,8 +128,7 @@ enum CanBeStatementStart: RawTokenKindSubset {
129128
case RawTokenKindMatch(.switch): self = .switchKeyword
130129
case RawTokenKindMatch(.throw): self = .throwKeyword
131130
case RawTokenKindMatch(.while): self = .whileKeyword
132-
case RawTokenKindMatch(RawTokenKind.yield): self = .yield
133-
case RawTokenKindMatch(Keyword.yield): self = .yieldAsIdentifier
131+
case RawTokenKindMatch(.yield): self = .yield
134132
default: return nil
135133
}
136134
}
@@ -151,15 +149,7 @@ enum CanBeStatementStart: RawTokenKindSubset {
151149
case .switchKeyword: return .keyword(.switch)
152150
case .throwKeyword: return .keyword(.throw)
153151
case .whileKeyword: return .keyword(.while)
154-
case .yield: return .yield
155-
case .yieldAsIdentifier: return .keyword(.yield)
156-
}
157-
}
158-
159-
var precedence: TokenPrecedence? {
160-
switch self {
161-
case .yieldAsIdentifier: return .stmtKeyword
162-
default: return nil
152+
case .yield: return .keyword(.yield)
163153
}
164154
}
165155
}

Sources/SwiftParser/Statements.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ extension Parser {
118118
return label(self.parseDoStatement(doHandle: handle), with: optLabel)
119119
case (.poundAssertKeyword, let handle)?:
120120
return label(self.parsePoundAssertStatement(poundAssertHandle: handle), with: optLabel)
121-
case (.yieldAsIdentifier, let handle)?,
122-
(.yield, let handle)?:
121+
case (.yield, let handle)?:
123122
return label(self.parseYieldStatement(yieldHandle: handle), with: optLabel)
124123
case nil:
125124
let missingStmt = RawStmtSyntax(RawMissingStmtSyntax(arena: self.arena))
@@ -1257,7 +1256,6 @@ extension Parser.Lookahead {
12571256
.continueKeyword?,
12581257
.fallthroughKeyword?,
12591258
.switchKeyword?,
1260-
.yield?,
12611259
.poundAssertKeyword?:
12621260
return true
12631261
case .repeatKeyword?:
@@ -1266,7 +1264,7 @@ extension Parser.Lookahead {
12661264
// FIXME: 'repeat' followed by '{' could be a pack expansion
12671265
// with a closure pattern.
12681266
return self.peek().rawTokenKind == .leftBrace
1269-
case .yieldAsIdentifier?:
1267+
case .yield?:
12701268
switch self.peek().rawTokenKind {
12711269
case .prefixAmpersand:
12721270
// "yield &" always denotes a yield statement.

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public enum TokenPrecedence: Comparable {
159159
// Secondary parts of control-flow constructs
160160
.keyword(.case), .keyword(.catch), .keyword(.default), .keyword(.else),
161161
// Return-like statements
162-
.keyword(.break), .keyword(.continue), .keyword(.fallthrough), .keyword(.return), .keyword(.throw), .yield,
162+
.keyword(.break), .keyword(.continue), .keyword(.fallthrough), .keyword(.return), .keyword(.throw), .keyword(.yield),
163163
// #error, #warning and #assert are statement-like
164164
.poundErrorKeyword, .poundWarningKeyword, .poundAssertKeyword:
165165
self = .stmtKeyword

Sources/SwiftSyntax/generated/TokenKind.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ public enum TokenKind: Hashable {
131131

132132
case stringSegment(String)
133133

134-
case yield
135-
136134
/// Initializes a keyword token kind from its string representation. If the
137135
/// given string is not a keyword, this function returns `nil`.
138136
public init?(keyword: String) {
@@ -320,8 +318,6 @@ public enum TokenKind: Hashable {
320318
return text
321319
case .stringSegment(let text):
322320
return text
323-
case .yield:
324-
return #"yield"#
325321
case .eof:
326322
return ""
327323
}
@@ -433,8 +429,6 @@ public enum TokenKind: Hashable {
433429
return #"#_hasSymbol"#
434430
case .keyword(let assoc):
435431
return assoc.defaultText
436-
case .yield:
437-
return #"yield"#
438432
case .eof:
439433
return ""
440434
default:
@@ -575,8 +569,6 @@ public enum TokenKind: Hashable {
575569
return false
576570
case .stringSegment:
577571
return false
578-
case .yield:
579-
return false
580572
case .keyword(let keyword):
581573
return keyword.isLexerClassified
582574
}
@@ -717,8 +709,6 @@ public enum TokenKind: Hashable {
717709
return false
718710
case .stringSegment:
719711
return false
720-
case .yield:
721-
return false
722712
}
723713
}
724714
}
@@ -854,8 +844,6 @@ extension TokenKind: Equatable {
854844
return lhsText == rhsText
855845
case (.stringSegment(let lhsText), .stringSegment(let rhsText)):
856846
return lhsText == rhsText
857-
case (.yield, .yield):
858-
return true
859847
default:
860848
return false
861849
}
@@ -993,8 +981,6 @@ public enum RawTokenKind: Equatable, Hashable {
993981

994982
case stringSegment
995983

996-
case yield
997-
998984
@_spi(RawSyntax)
999985
public var defaultText: SyntaxText? {
1000986
switch self {
@@ -1102,8 +1088,6 @@ public enum RawTokenKind: Equatable, Hashable {
11021088
return #"#_hasSymbol"#
11031089
case .keyword(let assoc):
11041090
return assoc.defaultText
1105-
case .yield:
1106-
return #"yield"#
11071091
default:
11081092
return nil
11091093
}
@@ -1237,8 +1221,6 @@ public enum RawTokenKind: Equatable, Hashable {
12371221
return #"raw string delimiter"#
12381222
case .stringSegment:
12391223
return #"string segment"#
1240-
case .yield:
1241-
return #"yield"#
12421224
case .keyword(let keyword):
12431225
return String(syntaxText: keyword.defaultText)
12441226
}
@@ -1377,8 +1359,6 @@ public enum RawTokenKind: Equatable, Hashable {
13771359
return false
13781360
case .stringSegment:
13791361
return false
1380-
case .yield:
1381-
return false
13821362
case .keyword(let keyword):
13831363
return keyword.isLexerClassified
13841364
}
@@ -1519,8 +1499,6 @@ public enum RawTokenKind: Equatable, Hashable {
15191499
return false
15201500
case .stringSegment:
15211501
return false
1522-
case .yield:
1523-
return false
15241502
}
15251503
}
15261504

@@ -1825,9 +1803,6 @@ extension TokenKind {
18251803
return .rawStringDelimiter(text)
18261804
case .stringSegment:
18271805
return .stringSegment(text)
1828-
case .yield:
1829-
assert(text.isEmpty || rawKind.defaultText.map(String.init ) == text)
1830-
return .yield
18311806
}
18321807
}
18331808

@@ -1964,8 +1939,6 @@ extension TokenKind {
19641939
return (.rawStringDelimiter, str)
19651940
case .stringSegment(let str):
19661941
return (.stringSegment, str)
1967-
case .yield:
1968-
return (.yield, nil)
19691942
}
19701943
}
19711944
}

Sources/SwiftSyntax/generated/Tokens.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -847,19 +847,6 @@ extension TokenSyntax {
847847
)
848848
}
849849

850-
public static func yieldToken(
851-
leadingTrivia: Trivia = [],
852-
trailingTrivia: Trivia = [],
853-
presence: SourcePresence = .present
854-
) -> TokenSyntax {
855-
return TokenSyntax(
856-
.yield,
857-
leadingTrivia: leadingTrivia,
858-
trailingTrivia: trailingTrivia,
859-
presence: presence
860-
)
861-
}
862-
863850
public static func eof(
864851
leadingTrivia: Trivia = [],
865852
presence: SourcePresence = .present

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6200,7 +6200,7 @@ public enum SyntaxFactory {
62006200
let data = SyntaxData.forRoot(RawSyntax.makeLayout(kind: .yieldStmt,
62016201
from: [
62026202
nil,
6203-
RawSyntax.makeMissingToken(kind: TokenKind.yield, arena: arena),
6203+
RawSyntax.makeMissingToken(kind: TokenKind.keyword(.yield), arena: arena),
62046204
nil,
62056205
RawSyntax.makeEmptyLayout(kind: SyntaxKind.missing, arena: arena),
62066206
nil,
@@ -9077,15 +9077,6 @@ public enum SyntaxFactory {
90779077
leadingTrivia: leadingTrivia,
90789078
trailingTrivia: trailingTrivia)
90799079
}
9080-
@available(*, deprecated, message: "Use TokenSyntax.yieldToken instead")
9081-
public static func makeYieldToken(
9082-
leadingTrivia: Trivia = [],
9083-
trailingTrivia: Trivia = []
9084-
) -> TokenSyntax {
9085-
return makeToken(.yield, presence: .present,
9086-
leadingTrivia: leadingTrivia,
9087-
trailingTrivia: trailingTrivia)
9088-
}
90899080

90909081
/// MARK: Convenience APIs
90919082

Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxStmtNodes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3066,7 +3066,7 @@ public struct YieldStmtSyntax: StmtSyntaxProtocol, SyntaxHashable {
30663066
public init(
30673067
leadingTrivia: Trivia? = nil,
30683068
_ unexpectedBeforeYieldKeyword: UnexpectedNodesSyntax? = nil,
3069-
yieldKeyword: TokenSyntax = .yieldToken(),
3069+
yieldKeyword: TokenSyntax = .keyword(.yield),
30703070
_ unexpectedBetweenYieldKeywordAndYields: UnexpectedNodesSyntax? = nil,
30713071
yields: Yields,
30723072
_ unexpectedAfterYields: UnexpectedNodesSyntax? = nil,

Sources/SwiftSyntaxBuilder/generated/Token.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,6 @@ public extension TokenSyntax {
266266
return .poundHasSymbolKeyword()
267267
}
268268

269-
/// The `yield` token
270-
static var `yield`: TokenSyntax {
271-
return .yieldToken()
272-
}
273-
274269
/// The `eof` token
275270
static var eof: TokenSyntax {
276271
return .eof()

gyb_syntax_support/StmtNodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
# yield-stmt -> 'yield' '('? expr-list? ')'?
133133
Node('YieldStmt', name_for_diagnostics="'yield' statement", kind='Stmt',
134134
children=[
135-
Child('YieldKeyword', kind='YieldToken'),
135+
Child('YieldKeyword', kind='KeywordToken', text_choices=['yield']),
136136
Child('Yields', kind='Syntax',
137137
node_choices=[
138138
Child('YieldList', kind='YieldList'),

gyb_syntax_support/Token.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,6 @@ def macro_name(self):
300300
name_for_diagnostics='raw string delimiter'),
301301
Misc('StringSegment', 'string_segment', name_for_diagnostics='string segment',
302302
classification='StringLiteral'),
303-
Misc('Yield', 'kw_yield', name_for_diagnostics='yield',
304-
text='yield'),
305303
]
306304

307305
SYNTAX_TOKEN_MAP = {token.name + 'Token': token for token in SYNTAX_TOKENS}

0 commit comments

Comments
 (0)