@@ -18,23 +18,28 @@ import SwiftDiagnostics
1818extension ASTGenVisitor {
1919 func generate( pattern node: PatternSyntax ) -> BridgedPattern {
2020 switch node. as ( PatternSyntaxEnum . self) {
21- case . expressionPattern:
22- break
21+ case . expressionPattern( let node ) :
22+ return self . generate ( expressionPattern : node ) . asPattern
2323 case . identifierPattern( let node) :
2424 return self . generate ( identifierPattern: node) . asPattern
25- case . isTypePattern:
26- break
27- case . missingPattern:
28- break
29- case . tuplePattern:
30- break
31- case . valueBindingPattern:
32- break
33- case . wildcardPattern:
34- break
25+ case . isTypePattern( let node ) :
26+ return self . generate ( isTypePattern : node ) . asPattern
27+ case . missingPattern( let node ) :
28+ return self . generate ( missingPattern : node )
29+ case . tuplePattern( let node ) :
30+ return self . generate ( tuplePattern : node )
31+ case . valueBindingPattern( let node ) :
32+ return self . generate ( valueBindingPattern : node ) . asPattern
33+ case . wildcardPattern( let node ) :
34+ return self . generate ( wildcardPattern : node ) . asPattern
3535 }
36+ }
3637
37- preconditionFailure ( " unimplemented " )
38+ func generate( expressionPattern node: ExpressionPatternSyntax ) -> BridgedExprPattern {
39+ return . createParsed(
40+ self . declContext,
41+ expr: self . generate ( expr: node. expression)
42+ )
3843 }
3944
4045 func generate( identifierPattern node: IdentifierPatternSyntax ) -> BridgedNamedPattern {
@@ -45,6 +50,60 @@ extension ASTGenVisitor {
4550 loc: nameLoc
4651 )
4752 }
53+
54+ func generate( isTypePattern node: IsTypePatternSyntax ) -> BridgedIsPattern {
55+ return . createParsed(
56+ self . ctx,
57+ isLoc: self . generateSourceLoc ( node. isKeyword) ,
58+ typeExpr: . createParsed(
59+ self . ctx,
60+ type: self . generate ( type: node. type)
61+ )
62+ )
63+ }
64+
65+ func generate( missingPattern node: MissingPatternSyntax ) -> BridgedPattern {
66+ fatalError ( " unimplemented " )
67+ }
68+
69+ func generate( tuplePattern node: TuplePatternSyntax ) -> BridgedPattern {
70+ if node. elements. count == 1 , let firstElement = node. elements. first, firstElement. label == nil {
71+ return BridgedParenPattern . createParsed (
72+ self . ctx,
73+ lParenLoc: self . generateSourceLoc ( node. leftParen) ,
74+ subPattern: self . generate ( pattern: firstElement. pattern) ,
75+ rParenLoc: self . generateSourceLoc ( node. rightParen)
76+ ) . asPattern
77+ }
78+ return BridgedTuplePattern . createParsed (
79+ self . ctx,
80+ lParenLoc: self . generateSourceLoc ( node. leftParen) ,
81+ elements: node. elements. lazy. map {
82+ BridgedTuplePatternElt (
83+ Label: self . generateIdentifier ( $0. label) ,
84+ LabelLoc: self . generateSourceLoc ( $0. label) ,
85+ ThePattern: self . generate ( pattern: $0. pattern)
86+ )
87+ } . bridgedArray ( in: self ) ,
88+ rParenLoc: self . generateSourceLoc ( node. rightParen)
89+ ) . asPattern
90+ }
91+
92+ func generate( valueBindingPattern node: ValueBindingPatternSyntax ) -> BridgedBindingPattern {
93+ return . createParsed(
94+ self . ctx,
95+ keywordLoc: self . generateSourceLoc ( node. bindingSpecifier) ,
96+ isLet: node. bindingSpecifier. keywordKind == . let,
97+ subPattern: self . generate ( pattern: node. pattern)
98+ )
99+ }
100+
101+ func generate( wildcardPattern node: WildcardPatternSyntax ) -> BridgedAnyPattern {
102+ return . createParsed(
103+ self . ctx,
104+ loc: self . generateSourceLoc ( node. wildcard)
105+ )
106+ }
48107}
49108
50109
0 commit comments