@@ -19,10 +19,10 @@ import Utils
19
19
let basicFormatFile = SourceFile {
20
20
ImportDecl (
21
21
leadingTrivia: . docLineComment( copyrightHeader) ,
22
- path: " SwiftSyntax "
22
+ path: [ AccessPathComponent ( name : " SwiftSyntax " ) ]
23
23
)
24
24
25
- ClassDecl ( modifiers: [ Token . open] , identifier: " BasicFormat " , inheritanceClause: TypeInheritanceClause { InheritedType ( typeName: " SyntaxRewriter " ) } ) {
25
+ ClassDecl ( modifiers: [ DeclModifier ( name : . open) ] , identifier: " BasicFormat " , inheritanceClause: TypeInheritanceClause { InheritedType ( typeName: Type ( " SyntaxRewriter " ) ) } ) {
26
26
VariableDecl ( " public var indentationLevel: Int = 0 " )
27
27
VariableDecl ( " open var indentation: TriviaPiece { .spaces(indentationLevel * 4) } " )
28
28
VariableDecl ( " public var indentedNewline: Trivia { Trivia(pieces: [.newlines(1), indentation]) } " )
@@ -40,15 +40,15 @@ let basicFormatFile = SourceFile {
40
40
}
41
41
}
42
42
43
- private func createChildVisitCall( childType: SyntaxBuildableType , rewrittenExpr: ExprBuildable ) -> ExprBuildable {
43
+ private func createChildVisitCall( childType: SyntaxBuildableType , rewrittenExpr: ExprSyntaxProtocol ) -> FunctionCallExpr {
44
44
let visitCall : FunctionCallExpr
45
45
if childType. isOptional {
46
46
visitCall = FunctionCallExpr ( " \( rewrittenExpr) .map(self.visit) " )
47
47
} else {
48
48
visitCall = FunctionCallExpr ( " self.visit( \( rewrittenExpr) ) " )
49
49
}
50
50
if childType. baseType? . baseName != " Syntax " , childType. baseType? . isSyntaxCollection != true , childType. baseType != nil {
51
- let optionalChained = childType. optionalChained ( expr: visitCall) . createExprBuildable ( )
51
+ let optionalChained = childType. optionalChained ( expr: visitCall)
52
52
return FunctionCallExpr ( " \( optionalChained) .cast( \( childType. syntaxBaseName) .self) " )
53
53
} else {
54
54
return visitCall
@@ -64,19 +64,19 @@ private func makeLayoutNodeRewriteFunc(node: Node) -> FunctionDecl {
64
64
}
65
65
return FunctionDecl (
66
66
leadingTrivia: . newline,
67
- modifiers: [ Token . open, Token ( tokenSyntax : TokenSyntax . contextualKeyword ( " override " , trailingTrivia: . space) ) ] ,
67
+ modifiers: [ DeclModifier ( name : . open) , DeclModifier ( name : TokenSyntax . contextualKeyword ( " override " , trailingTrivia: . space) ) ] ,
68
68
identifier: . identifier( " visit " ) ,
69
69
signature: FunctionSignature (
70
70
input: ParameterClause ( parameterList: [
71
71
FunctionParameter (
72
72
firstName: Token . wildcard,
73
73
secondName: . identifier( " node " ) ,
74
74
colon: . colon,
75
- type: node. type. syntaxBaseName
75
+ type: Type ( node. type. syntaxBaseName)
76
76
77
77
)
78
78
] ) ,
79
- output: rewriteResultType
79
+ output: ReturnClause ( returnType : Type ( rewriteResultType) )
80
80
)
81
81
) {
82
82
for child in node. children {
@@ -98,11 +98,11 @@ private func makeLayoutNodeRewriteFunc(node: Node) -> FunctionDecl {
98
98
SequenceExpr ( " indentationLevel -= 1 " )
99
99
}
100
100
}
101
- let reconstructed = FunctionCallExpr ( calledExpression: " \( node. type. syntaxBaseName) " ) {
101
+ let reconstructed = FunctionCallExpr ( calledExpression: Expr ( " \( node. type. syntaxBaseName) " ) ) {
102
102
for child in node. children {
103
103
TupleExprElement (
104
104
label: child. isUnexpectedNodes ? nil : child. swiftName,
105
- expression: child. swiftName
105
+ expression: Expr ( child. swiftName)
106
106
)
107
107
}
108
108
}
@@ -118,19 +118,19 @@ private func makeSyntaxCollectionRewriteFunc(node: Node) -> FunctionDecl {
118
118
let rewriteResultType = node. type. syntaxBaseName
119
119
return FunctionDecl (
120
120
leadingTrivia: . newline,
121
- modifiers: [ Token . open, Token ( tokenSyntax : TokenSyntax . contextualKeyword ( " override " , trailingTrivia: . space) ) ] ,
121
+ modifiers: [ DeclModifier ( name : . open) , DeclModifier ( name : TokenSyntax . contextualKeyword ( " override " , trailingTrivia: . space) ) ] ,
122
122
identifier: . identifier( " visit " ) ,
123
123
signature: FunctionSignature (
124
124
input: ParameterClause ( parameterList: [
125
125
FunctionParameter (
126
126
firstName: Token . wildcard,
127
127
secondName: . identifier( " node " ) ,
128
128
colon: . colon,
129
- type: node. type. syntaxBaseName
129
+ type: Type ( node. type. syntaxBaseName)
130
130
131
131
)
132
132
] ) ,
133
- output: rewriteResultType
133
+ output: ReturnClause ( returnType : Type ( rewriteResultType) )
134
134
)
135
135
) {
136
136
let formattedChildrenVarLet = node. elementsSeparatedByNewline ? " var " : " let "
@@ -161,26 +161,26 @@ private func makeSyntaxCollectionRewriteFunc(node: Node) -> FunctionDecl {
161
161
private func createTokenFormatFunction( ) -> FunctionDecl {
162
162
return FunctionDecl (
163
163
leadingTrivia: . newline,
164
- modifiers: [ Token . open, Token ( tokenSyntax : TokenSyntax . contextualKeyword ( " override " , trailingTrivia: . space) ) ] ,
164
+ modifiers: [ DeclModifier ( name : . open) , DeclModifier ( name : TokenSyntax . contextualKeyword ( " override " , trailingTrivia: . space) ) ] ,
165
165
identifier: . identifier( " visit " ) ,
166
166
signature: FunctionSignature (
167
167
input: ParameterClause ( parameterList: [
168
168
FunctionParameter (
169
169
firstName: Token . wildcard,
170
170
secondName: . identifier( " node " ) ,
171
171
colon: . colon,
172
- type: " TokenSyntax "
172
+ type: Type ( " TokenSyntax " )
173
173
174
174
)
175
175
] ) ,
176
- output: " TokenSyntax "
176
+ output: ReturnClause ( returnType : Type ( " TokenSyntax " ) )
177
177
)
178
178
) {
179
179
VariableDecl ( " var leadingTrivia = node.leadingTrivia " )
180
180
VariableDecl ( " var trailingTrivia = node.trailingTrivia " )
181
181
SwitchStmt ( expression: MemberAccessExpr ( base: " node " , name: " tokenKind " ) ) {
182
182
for token in SYNTAX_TOKENS where token. name != " ContextualKeyword " {
183
- SwitchCase ( label: SwitchCaseLabel ( caseItems: CaseItem ( pattern: ExpressionPattern ( expression: MemberAccessExpr ( name: token. swiftKind) ) ) ) ) {
183
+ SwitchCase ( label: SwitchCaseLabel ( caseItems: [ CaseItem ( pattern: ExpressionPattern ( expression: MemberAccessExpr ( name: token. swiftKind) ) ) ] ) ) {
184
184
if token. requiresLeadingSpace {
185
185
IfStmt (
186
186
"""
@@ -204,10 +204,10 @@ private func createTokenFormatFunction() -> FunctionDecl {
204
204
}
205
205
}
206
206
}
207
- SwitchCase ( label: SwitchCaseLabel ( caseItems: CaseItem ( pattern: ExpressionPattern ( expression: MemberAccessExpr ( name: " eof " ) ) ) ) ) {
207
+ SwitchCase ( label: SwitchCaseLabel ( caseItems: [ CaseItem ( pattern: ExpressionPattern ( expression: MemberAccessExpr ( name: " eof " ) ) ) ] ) ) {
208
208
BreakStmt ( " break " )
209
209
}
210
- SwitchCase ( label: SwitchCaseLabel ( caseItems: CaseItem ( pattern: ExpressionPattern ( expression: MemberAccessExpr ( name: " contextualKeyword " ) ) ) ) ) {
210
+ SwitchCase ( label: SwitchCaseLabel ( caseItems: [ CaseItem ( pattern: ExpressionPattern ( expression: MemberAccessExpr ( name: " contextualKeyword " ) ) ) ] ) ) {
211
211
SwitchStmt (
212
212
"""
213
213
switch node.text {
0 commit comments