@@ -445,6 +445,32 @@ func printParserDiags(args: CommandLineArguments) throws {
445
445
_ = try SyntaxParser . parse ( treeURL, diagnosticEngine: diagEngine)
446
446
}
447
447
448
+ func diagnose( args: CommandLineArguments ) throws {
449
+ let treeURL = URL ( fileURLWithPath: try args. getRequired ( " -source-file " ) )
450
+ let diagEngine = DiagnosticEngine ( )
451
+ diagEngine. addConsumer ( PrintingDiagnosticConsumer ( ) )
452
+ let tree = try SyntaxParser . parse ( treeURL, diagnosticEngine: diagEngine)
453
+ struct DiagnoseUnknown : SyntaxAnyVisitor {
454
+ let diagEngine : DiagnosticEngine
455
+ let converter : SourceLocationConverter
456
+ init ( _ diagEngine: DiagnosticEngine , _ converter: SourceLocationConverter ) {
457
+ self . diagEngine = diagEngine
458
+ self . converter = converter
459
+ }
460
+ func visitAny( _ node: Syntax ) -> SyntaxVisitorContinueKind {
461
+ if node. isUnknown {
462
+ diagEngine. diagnose ( Diagnostic . Message ( . warning, " unknown syntax exists " ) ,
463
+ location: node. startLocation ( converter: converter,
464
+ afterLeadingTrivia: true ) )
465
+ }
466
+ return . visitChildren
467
+ }
468
+ }
469
+ var visitor = DiagnoseUnknown ( diagEngine,
470
+ SourceLocationConverter ( file: treeURL. path, tree: tree) )
471
+ tree. walk ( & visitor)
472
+ }
473
+
448
474
do {
449
475
let args = try CommandLineArguments . parse ( CommandLine . arguments. dropFirst ( ) )
450
476
458
484
try printSyntaxTree ( args: args)
459
485
} else if args. has ( " -dump-diags " ) {
460
486
try printParserDiags ( args: args)
487
+ } else if args. has ( " -diagnose " ) {
488
+ try diagnose ( args: args)
461
489
} else if args. has ( " -help " ) {
462
490
printHelp ( )
463
491
} else {
0 commit comments