Skip to content

Commit b9c7b10

Browse files
committed
Disallow multipe node_choices of the same type
This stops us from using `token_choices` in the `SyntaxChildChoices` initializer and thus means that we no longer need to enforce that only expected `token_choices` exist in the syntax tree.
1 parent 53942bd commit b9c7b10

File tree

15 files changed

+131
-395
lines changed

15 files changed

+131
-395
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,15 @@ public let ATTRIBUTE_NODES: [Node] = [
8484
description: "The arguments of the attribute. In case the attributetakes multiple arguments, they are gather in theappropriate takes first.",
8585
isOptional: true,
8686
nodeChoices: [
87-
Child(name: "Identifier",
88-
kind: "IdentifierToken",
87+
Child(name: "Token",
88+
kind: "Token",
8989
tokenChoices: [
90-
"Identifier"
91-
]),
92-
Child(name: "String",
93-
kind: "StringLiteralToken",
94-
tokenChoices: [
95-
"StringLiteral"
90+
"Identifier",
91+
"StringLiteral",
92+
"IntegerLiteral"
9693
]),
9794
Child(name: "StringExpr",
9895
kind: "StringLiteralExpr"),
99-
Child(name: "Integer",
100-
kind: "IntegerLiteralToken",
101-
tokenChoices: [
102-
"IntegerLiteral"
103-
]),
10496
Child(name: "Availability",
10597
kind: "AvailabilitySpecList"),
10698
Child(name: "SpecializeArguments",
@@ -279,19 +271,11 @@ public let ATTRIBUTE_NODES: [Node] = [
279271
kind: "Syntax",
280272
children: [
281273
Child(name: "DeclBaseName",
282-
kind: "Syntax",
274+
kind: "Token",
283275
description: "The base name of the protocol's requirement.",
284-
nodeChoices: [
285-
Child(name: "Identifier",
286-
kind: "IdentifierToken",
287-
tokenChoices: [
288-
"Identifier"
289-
]),
290-
Child(name: "Operator",
291-
kind: "PrefixOperatorToken",
292-
tokenChoices: [
293-
"PrefixOperator"
294-
])
276+
tokenChoices: [
277+
"Identifier",
278+
"PrefixOperator"
295279
]),
296280
Child(name: "DeclNameArguments",
297281
kind: "DeclNameArguments",
@@ -449,23 +433,11 @@ public let ATTRIBUTE_NODES: [Node] = [
449433
],
450434
children: [
451435
Child(name: "Parameter",
452-
kind: "Syntax",
453-
nodeChoices: [
454-
Child(name: "Self",
455-
kind: "SelfToken",
456-
tokenChoices: [
457-
"Self"
458-
]),
459-
Child(name: "Name",
460-
kind: "IdentifierToken",
461-
tokenChoices: [
462-
"Identifier"
463-
]),
464-
Child(name: "Index",
465-
kind: "IntegerLiteralToken",
466-
tokenChoices: [
467-
"IntegerLiteral"
468-
])
436+
kind: "Token",
437+
tokenChoices: [
438+
"Self",
439+
"Identifier",
440+
"IntegerLiteral"
469441
]),
470442
Child(name: "TrailingComma",
471443
kind: "CommaToken",
@@ -565,24 +537,12 @@ public let ATTRIBUTE_NODES: [Node] = [
565537
kind: "Syntax",
566538
children: [
567539
Child(name: "Name",
568-
kind: "Syntax",
540+
kind: "Token",
569541
description: "The base name of the referenced function.",
570-
nodeChoices: [
571-
Child(name: "Identifier",
572-
kind: "IdentifierToken",
573-
tokenChoices: [
574-
"Identifier"
575-
]),
576-
Child(name: "PrefixOperator",
577-
kind: "PrefixOperatorToken",
578-
tokenChoices: [
579-
"PrefixOperator"
580-
]),
581-
Child(name: "SpacedBinaryOperator",
582-
kind: "SpacedBinaryOperatorToken",
583-
tokenChoices: [
584-
"SpacedBinaryOperator"
585-
])
542+
tokenChoices: [
543+
"Identifier",
544+
"PrefixOperator",
545+
"SpacedBinaryOperator"
586546
]),
587547
Child(name: "Arguments",
588548
kind: "DeclNameArguments",

CodeGeneration/Sources/SyntaxSupport/gyb_generated/AvailabilityNodes.swift

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,10 @@ public let AVAILABILITY_NODES: [Node] = [
2727
kind: "Syntax",
2828
description: "The actual argument",
2929
nodeChoices: [
30-
Child(name: "Star",
31-
kind: "SpacedBinaryOperatorToken",
32-
tokenChoices: [
33-
"SpacedBinaryOperator"
34-
],
35-
textChoices: [
36-
"*"
37-
]),
38-
Child(name: "IdentifierRestriction",
39-
kind: "IdentifierToken",
30+
Child(name: "Token",
31+
kind: "Token",
4032
tokenChoices: [
33+
"SpacedBinaryOperator",
4134
"Identifier"
4235
]),
4336
Child(name: "AvailabilityVersionRestriction",
@@ -110,19 +103,11 @@ public let AVAILABILITY_NODES: [Node] = [
110103
kind: "Syntax",
111104
children: [
112105
Child(name: "MajorMinor",
113-
kind: "Syntax",
106+
kind: "Token",
114107
description: "In case the version consists only of the major version, aninteger literal that specifies the major version. In casethe version consists of major and minor version number, afloating literal in which the decimal part is interpretedas the minor version.",
115-
nodeChoices: [
116-
Child(name: "Major",
117-
kind: "IntegerLiteralToken",
118-
tokenChoices: [
119-
"IntegerLiteral"
120-
]),
121-
Child(name: "MajorMinor",
122-
kind: "FloatingLiteralToken",
123-
tokenChoices: [
124-
"FloatingLiteral"
125-
])
108+
tokenChoices: [
109+
"IntegerLiteral",
110+
"FloatingLiteral"
126111
]),
127112
Child(name: "PatchPeriod",
128113
kind: "PeriodToken",

Sources/SwiftParser/Attributes.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ extension Parser {
268268
// If no opening '(' for parameter list, parse a single parameter.
269269
let param = self.parseDifferentiabilityParameter()
270270
?? RawDifferentiabilityParamSyntax(
271-
parameter: .name(missingToken(.identifier)),
271+
parameter: missingToken(.identifier),
272272
trailingComma: nil,
273273
arena: self.arena
274274
)
@@ -338,17 +338,17 @@ extension Parser {
338338
let token = self.eat(handle)
339339
let comma = self.consume(if: .comma)
340340
return RawDifferentiabilityParamSyntax(
341-
parameter: .name(token), trailingComma: comma, arena: self.arena)
341+
parameter: token, trailingComma: comma, arena: self.arena)
342342
case (.integerLiteral, let handle)?:
343343
let token = self.eat(handle)
344344
let comma = self.consume(if: .comma)
345345
return RawDifferentiabilityParamSyntax(
346-
parameter: .index(token), trailingComma: comma, arena: self.arena)
346+
parameter: token, trailingComma: comma, arena: self.arena)
347347
case (.selfKeyword, let handle)?:
348348
let token = self.eat(handle)
349349
let comma = self.consume(if: .comma)
350350
return RawDifferentiabilityParamSyntax(
351-
parameter: .self(token),
351+
parameter: token,
352352
trailingComma: comma,
353353
arena: self.arena
354354
)
@@ -546,7 +546,7 @@ extension Parser {
546546
let (unexpectedBeforeColon, colon) = self.expect(.colon)
547547
let (targetFunction, args) = self.parseDeclNameRef([ .zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators ])
548548
let declName = RawDeclNameSyntax(
549-
declBaseName: .identifier(targetFunction),
549+
declBaseName: targetFunction,
550550
declNameArguments: args,
551551
arena: self.arena)
552552
let comma = self.consume(if: .comma)
@@ -701,7 +701,7 @@ extension Parser {
701701
.zeroArgCompoundNames, .keywordsUsingSpecialNames, .operators,
702702
])
703703
}
704-
let method = RawDeclNameSyntax(declBaseName: .identifier(base), declNameArguments: args, arena: self.arena)
704+
let method = RawDeclNameSyntax(declBaseName: base, declNameArguments: args, arena: self.arena)
705705
let (unexpectedBeforeRightParen, rightParen) = self.expect(.rightParen)
706706
return RawAttributeSyntax(
707707
unexpectedBeforeAtSign,
@@ -739,7 +739,7 @@ extension Parser {
739739
attributeName: spiToken,
740740
unexpectedBeforeLeftParen,
741741
leftParen: leftParen,
742-
argument: .identifier(label),
742+
argument: .token(label),
743743
unexpectedBeforeRightParen,
744744
rightParen: rightParen,
745745
tokenList: nil,

Sources/SwiftParser/Availability.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extension Parser {
8484
let platform = self.consumeAnyToken()
8585
var keepGoing: RawTokenSyntax? = self.consume(if: .comma)
8686
elements.append(RawAvailabilityArgumentSyntax(
87-
entry: .identifierRestriction(platform), trailingComma: keepGoing, arena: self.arena))
87+
entry: .token(platform), trailingComma: keepGoing, arena: self.arena))
8888

8989
do {
9090
var loopProgressCondition = LoopProgressCondition()
@@ -128,14 +128,14 @@ extension Parser {
128128
arena: self.arena
129129
))
130130
} else {
131-
entry = .identifierRestriction(argumentLabel)
131+
entry = .token(argumentLabel)
132132
}
133133
case (.unavailable, let handle)?,
134134
(.noasync, let handle)?:
135135
let argument = self.eat(handle)
136136
// FIXME: Can we model this in SwiftSyntax by making the
137137
// 'labeled' argument part optional?
138-
entry = .identifierRestriction(argument)
138+
entry = .token(argument)
139139
case nil:
140140
// Not sure what this label is but, let's just eat it and
141141
// keep going.
@@ -165,7 +165,7 @@ extension Parser {
165165
if let star = self.consumeIfContextualPunctuator("*") {
166166
// FIXME: Use makeAvailabilityVersionRestriction here - but swift-format
167167
// doesn't expect it.
168-
return .star(star)
168+
return .token(star)
169169
}
170170

171171
if self.at(any: [.identifier, .wildcardKeyword]) {
@@ -245,7 +245,7 @@ extension Parser {
245245
mutating func parseVersionTuple() -> RawVersionTupleSyntax {
246246
if let major = self.consume(if: .integerLiteral) {
247247
return RawVersionTupleSyntax(
248-
majorMinor: .major(major), patchPeriod: nil, patchVersion: nil,
248+
majorMinor: major, patchPeriod: nil, patchVersion: nil,
249249
arena: self.arena)
250250
}
251251

@@ -260,7 +260,7 @@ extension Parser {
260260
}
261261

262262
return RawVersionTupleSyntax(
263-
majorMinor: .majorMinor(majorMinor), patchPeriod: period, patchVersion: patch,
263+
majorMinor: majorMinor, patchPeriod: period, patchVersion: patch,
264264
arena: self.arena)
265265
}
266266
}

0 commit comments

Comments
 (0)