File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,27 @@ func performClassifySyntax(args: CommandLineArguments) throws {
124
124
}
125
125
}
126
126
127
+ class NodePrinter : SyntaxVisitor {
128
+ override func visitPre( _ node: Syntax ) {
129
+ assert ( !node. isUnknown)
130
+ print ( " < \( type ( of: node) ) > " , terminator: " " )
131
+ }
132
+ override func visitPost( _ node: Syntax ) {
133
+ print ( " </ \( type ( of: node) ) > " , terminator: " " )
134
+ }
135
+ override func visit( _ token: TokenSyntax ) -> SyntaxVisitorContinueKind {
136
+ print ( token, terminator: " " )
137
+ return . visitChildren
138
+ }
139
+ }
140
+
141
+ func printSyntaxTree( args: CommandLineArguments ) throws {
142
+ let treeURL = URL ( fileURLWithPath: try args. getRequired ( " -source-file " ) )
143
+ let swiftcURL = args [ " -swiftc " ] . map ( URL . init ( fileURLWithPath: ) )
144
+ let tree = try SyntaxTreeParser . parse ( treeURL, swiftcURL: swiftcURL)
145
+ tree. walk ( NodePrinter ( ) )
146
+ }
147
+
127
148
do {
128
149
let args = try CommandLineArguments . parse ( CommandLine . arguments. dropFirst ( ) )
129
150
133
154
try performClassifySyntax ( args: args)
134
155
} else if args. has ( " -deserialize " ) {
135
156
try performDeserialize ( args: args)
157
+ } else if args. has ( " -print-source " ) {
158
+ try printSyntaxTree ( args: args)
136
159
} else if args. has ( " -help " ) {
137
160
printHelp ( )
138
161
} else {
You can’t perform that action at this time.
0 commit comments