Skip to content

Commit 933affc

Browse files
committed
redo parsing of without operator to match C++ parser
This basically moves the logic out from only when encountering an inheritance entry and instead when generally parsing a type, since that was a better way to go on the C++ side. (cherry picked from commit d141df5)
1 parent 6b6e7d8 commit 933affc

File tree

21 files changed

+812
-96
lines changed

21 files changed

+812
-96
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -992,14 +992,6 @@ public let DECL_NODES: [Node] = [
992992
"WithTrailingComma"
993993
],
994994
children: [
995-
/// Indicates whether the 'without' operator was applied to the type to
996-
/// indicate the suppression of implicit conformance to this type.
997-
/// This child stores the token representing the 'without' operator.
998-
Child(
999-
name: "WithoutTilde",
1000-
kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")]),
1001-
isOptional: true
1002-
),
1003995
Child(
1004996
name: "TypeName",
1005997
kind: .node(kind: "Type")

CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,23 @@ public let TYPE_NODES: [Node] = [
349349
]
350350
),
351351

352+
// suppressed-type -> '~' type
353+
Node(
354+
name: "SuppressedType",
355+
nameForDiagnostics: "suppressed type conformance",
356+
kind: "Type",
357+
children: [
358+
Child(
359+
name: "WithoutTilde",
360+
kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")])
361+
),
362+
Child(
363+
name: "PatternType",
364+
kind: .node(kind: "Type")
365+
),
366+
]
367+
),
368+
352369
// pack-expansion-type -> type '...'
353370
Node(
354371
name: "PackExpansionType",

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ extension Parser {
497497
let unexpectedBeforeInherited: RawUnexpectedNodesSyntax?
498498
let inherited: RawTypeSyntax?
499499
if colon != nil {
500-
if self.at(.identifier, .keyword(.protocol), .keyword(.Any)) {
500+
if self.at(.identifier, .keyword(.protocol), .keyword(.Any)) || self.atContextualPunctuator("~") {
501501
unexpectedBeforeInherited = nil
502502
inherited = self.parseType()
503503
} else if let classKeyword = self.consume(if: .keyword(.class)) {

Sources/SwiftParser/Nominals.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ extension Parser {
219219
var keepGoing: RawTokenSyntax? = nil
220220
var loopProgress = LoopProgressCondition()
221221
repeat {
222-
var withoutToken: RawTokenSyntax? = nil
223222
let type: RawTypeSyntax
224223
if let classKeyword = self.consume(if: .keyword(.class)) {
225224
type = RawTypeSyntax(
@@ -229,14 +228,12 @@ extension Parser {
229228
)
230229
)
231230
} else {
232-
withoutToken = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator)
233231
type = self.parseType()
234232
}
235233

236234
keepGoing = self.consume(if: .comma)
237235
elements.append(
238236
RawInheritedTypeSyntax(
239-
withoutTilde: withoutToken,
240237
typeName: type,
241238
trailingComma: keepGoing,
242239
arena: self.arena

Sources/SwiftParser/Types.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ extension Parser {
3737
)
3838
}
3939

40+
// Parse without operator preceding a type '~ T'.
41+
if let withoutTilde = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator) {
42+
let type = self.parseTypeScalar(misplacedSpecifiers: misplacedSpecifiers)
43+
return RawTypeSyntax(
44+
RawSuppressedTypeSyntax(
45+
withoutTilde: withoutTilde,
46+
patternType: type,
47+
arena: self.arena
48+
)
49+
)
50+
}
51+
4052
return self.parseTypeScalar(misplacedSpecifiers: misplacedSpecifiers)
4153
}
4254

0 commit comments

Comments
 (0)