Skip to content

Commit d439993

Browse files
authored
Merge pull request #8 from scribd/eze/type-casting-reference
Add direct casting type to .as reference
2 parents 09c41d9 + 581b695 commit d439993

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

Sources/Meta/Reference.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ public enum ReferenceName: Hashable, MetaSwiftConvertible {
1616
case custom(String)
1717
}
1818

19+
public enum CastingType: Hashable, MetaSwiftConvertible {
20+
case strict(TypeIdentifier)
21+
case optional(TypeIdentifier)
22+
23+
public var swiftString: String {
24+
switch self {
25+
case .strict(let typeIdentifier):
26+
return " as \(typeIdentifier.reference.swiftString)"
27+
case .optional(let typeIdentifier):
28+
return " as? \(typeIdentifier.reference.swiftString)"
29+
}
30+
}
31+
}
32+
1933
public enum Reference: Hashable, MetaSwiftConvertible, Node {
2034
case type(TypeIdentifier)
2135
case name(ReferenceName)
@@ -25,7 +39,7 @@ public enum Reference: Hashable, MetaSwiftConvertible, Node {
2539
case optionalTry
2640
case `throw`
2741
case block(FunctionBody)
28-
case `as`
42+
case `as`(CastingType)
2943
case none
3044
indirect case dot(Reference, Reference)
3145
indirect case assemble(Reference, Reference)
@@ -147,8 +161,8 @@ extension Reference {
147161
return "throw "
148162
case .block(let block):
149163
return block.swiftString.prefixed(" ")
150-
case .as:
151-
return " as "
164+
case .as(let castingType):
165+
return castingType.swiftString
152166
case .none:
153167
return ""
154168
}

0 commit comments

Comments
 (0)