@@ -39,6 +39,10 @@ private class InitializerExprFormat: BasicFormat {
39
39
override func visit( _ node: TupleExprElementListSyntax ) -> TupleExprElementListSyntax {
40
40
let children = node. children ( viewMode: . all)
41
41
// If the function only takes a single argument, display it on the same line
42
+ if let callee = node. parent? . as ( FunctionCallExprSyntax . self) ? . calledExpression. as ( MemberAccessExprSyntax . self) , callee. base == nil {
43
+ // This is a constructor for tokens. Write them on a single line
44
+ return super. visit ( node)
45
+ }
42
46
if children. count > 1 {
43
47
return TupleExprElementListSyntax ( formatChildrenSeparatedByNewline ( children: children, elementType: TupleExprElementSyntax . self) )
44
48
} else {
@@ -127,24 +131,25 @@ extension SyntaxProtocol {
127
131
} else if let token = Syntax ( self ) . as ( TokenSyntax . self) {
128
132
let tokenKind = token. tokenKind
129
133
let tokenInitializerName : String
130
- let requiresExplicitText : Bool
134
+ let tokenKindArgument : ExprSyntax ?
131
135
if tokenKind. isLexerClassifiedKeyword || tokenKind == . eof {
132
136
tokenInitializerName = String ( describing: tokenKind)
133
- requiresExplicitText = false
137
+ tokenKindArgument = nil
138
+ } else if case . keyword( let keyword) = tokenKind {
139
+ tokenInitializerName = " keyword "
140
+ tokenKindArgument = ExprSyntax ( MemberAccessExprSyntax ( name: String ( describing: keyword) ) )
134
141
} else if tokenKind. decomposeToRaw ( ) . rawKind. defaultText != nil {
135
142
tokenInitializerName = " \( String ( describing: tokenKind) ) Token "
136
- requiresExplicitText = false
143
+ tokenKindArgument = nil
137
144
} else {
138
145
let tokenKindStr = String ( describing: tokenKind)
139
146
tokenInitializerName = String ( tokenKindStr [ ..< tokenKindStr. firstIndex ( of: " ( " ) !] )
140
- requiresExplicitText = true
147
+ tokenKindArgument = ExprSyntax ( StringLiteralExprSyntax ( content : token . text ) )
141
148
}
142
149
return ExprSyntax (
143
150
FunctionCallExprSyntax ( callee: MemberAccessExprSyntax ( name: tokenInitializerName) ) {
144
- if requiresExplicitText {
145
- TupleExprElementSyntax (
146
- expression: StringLiteralExprSyntax ( content: token. text)
147
- )
151
+ if let tokenKindArgument = tokenKindArgument {
152
+ TupleExprElementSyntax ( expression: tokenKindArgument)
148
153
}
149
154
if includeTrivia && !token. leadingTrivia. isEmpty {
150
155
TupleExprElementSyntax (
0 commit comments