@@ -57,22 +57,19 @@ public extension Child {
57
57
return self . type. optionalWrapped ( type: SimpleTypeIdentifierSyntax ( name: . identifier( parameterBaseType) ) )
58
58
}
59
59
60
- /// If the child node has a default value, return an expression of the form
61
- /// ` = default_value` that can be used as the default value to for a
62
- /// function parameter. Otherwise, return `nil`.
63
- var defaultInitialization : InitializerClauseSyntax ? {
60
+ var defaultValue : ExprSyntax ? {
64
61
if isOptional || isUnexpectedNodes {
65
62
if type. isBaseType && kind. isNodeChoicesEmpty {
66
- return InitializerClauseSyntax ( value : ExprSyntax ( " \( type. buildable) .none " ) )
63
+ return ExprSyntax ( " \( type. buildable) .none " )
67
64
} else {
68
- return InitializerClauseSyntax ( value : NilLiteralExprSyntax ( ) )
65
+ return ExprSyntax ( " nil " )
69
66
}
70
67
}
71
68
guard let token = token, isToken else {
72
- return type. defaultValue. map { InitializerClauseSyntax ( value : $0 ) }
69
+ return type. defaultValue
73
70
}
74
71
if token. text != nil {
75
- return InitializerClauseSyntax ( value : ExprSyntax ( " . \( raw: token. swiftKind) Token() " ) )
72
+ return ExprSyntax ( " . \( raw: token. swiftKind) Token() " )
76
73
}
77
74
guard case . token( let choices, _, _) = kind, choices. count == 1 , token. associatedValueClass != nil else {
78
75
return nil
@@ -85,7 +82,18 @@ public extension Child {
85
82
if textChoice == " init " {
86
83
textChoice = " `init` "
87
84
}
88
- return InitializerClauseSyntax ( value: ExprSyntax ( " . \( raw: token. swiftKind) (. \( raw: textChoice) ) " ) )
85
+ return ExprSyntax ( " . \( raw: token. swiftKind) (. \( raw: textChoice) ) " )
86
+ }
87
+
88
+ /// If the child node has a default value, return an expression of the form
89
+ /// ` = default_value` that can be used as the default value to for a
90
+ /// function parameter. Otherwise, return `nil`.
91
+ var defaultInitialization : InitializerClauseSyntax ? {
92
+ if let defaultValue {
93
+ return InitializerClauseSyntax ( equal: . equalToken( leadingTrivia: . space, trailingTrivia: . space) , value: defaultValue)
94
+ } else {
95
+ return nil
96
+ }
89
97
}
90
98
91
99
/// If this node is a token that can't contain arbitrary text, generate a Swift
0 commit comments