Skip to content

Commit 632d0b9

Browse files
committed
[NFC] Refactor parsing of suppressed types
1 parent 885bf06 commit 632d0b9

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ extension Parser {
193193
mutating func parseSimpleType(
194194
allowMemberTypes: Bool = true,
195195
forAttributeName: Bool = false
196+
) -> RawTypeSyntax {
197+
let tilde = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator)
198+
199+
let baseType = self.parseUnsuppressedSimpleType(
200+
allowMemberTypes: allowMemberTypes,
201+
forAttributeName: forAttributeName
202+
)
203+
204+
guard let tilde else {
205+
return baseType
206+
}
207+
208+
return RawTypeSyntax(RawSuppressedTypeSyntax(withoutTilde: tilde, type: baseType, arena: self.arena)
209+
)
210+
}
211+
212+
mutating func parseUnsuppressedSimpleType(
213+
allowMemberTypes: Bool = true,
214+
forAttributeName: Bool = false
196215
) -> RawTypeSyntax {
197216
enum TypeBaseStart: TokenSpecSet {
198217
case `Self`
@@ -226,23 +245,6 @@ extension Parser {
226245
}
227246
}
228247

229-
// Eat any '~' preceding the type.
230-
let maybeTilde = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator)
231-
232-
// Wrap as a suppressed type if needed.
233-
func wrapInTilde(_ node: RawTypeSyntax) -> RawTypeSyntax {
234-
if let tilde = maybeTilde {
235-
return RawTypeSyntax(
236-
RawSuppressedTypeSyntax(
237-
withoutTilde: tilde,
238-
type: node,
239-
arena: self.arena
240-
)
241-
)
242-
}
243-
return node
244-
}
245-
246248
var base: RawTypeSyntax
247249
switch self.at(anyIn: TypeBaseStart.self)?.spec {
248250
case .Self, .Any, .identifier:
@@ -254,7 +256,7 @@ extension Parser {
254256
case .wildcard:
255257
base = RawTypeSyntax(self.parsePlaceholderType())
256258
case nil:
257-
return wrapInTilde(RawTypeSyntax(RawMissingTypeSyntax(arena: self.arena)))
259+
return RawTypeSyntax(RawMissingTypeSyntax(arena: self.arena))
258260
}
259261

260262
var loopProgress = LoopProgressCondition()
@@ -331,8 +333,6 @@ extension Parser {
331333
break
332334
}
333335

334-
base = wrapInTilde(base)
335-
336336
return base
337337
}
338338

0 commit comments

Comments
 (0)