@@ -65,27 +65,6 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
65
65
self . handledNodes. append ( contentsOf: handledNodes)
66
66
}
67
67
68
- /// Produce a diagnostic.
69
- func addDiagnostic< T: SyntaxProtocol > (
70
- _ node: T ,
71
- position: AbsolutePosition ? = nil ,
72
- _ message: StaticParserError ,
73
- highlights: [ Syntax ] = [ ] ,
74
- notes: [ Note ] = [ ] ,
75
- fixIts: [ FixIt ] = [ ] ,
76
- handledNodes: [ SyntaxIdentifier ] = [ ]
77
- ) {
78
- addDiagnostic (
79
- node,
80
- position: position,
81
- message as DiagnosticMessage ,
82
- highlights: highlights,
83
- notes: notes,
84
- fixIts: fixIts,
85
- handledNodes: handledNodes
86
- )
87
- }
88
-
89
68
/// Whether the node should be skipped for diagnostic emission.
90
69
/// Every visit method must check this at the beginning.
91
70
func shouldSkip< T: SyntaxProtocol > ( _ node: T ) -> Bool {
@@ -99,11 +78,11 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
99
78
///
100
79
/// If `incorrectContainer` contains only tokens that satisfy `unexpectedTokenCondition`, emit a diagnostic with message `message` that marks this token as misplaced.
101
80
/// If `correctTokens` contains missing tokens, also emit a Fix-It with message `fixIt` that marks the unexpected token as missing and instead inserts `correctTokens`.
102
- public func exchangeTokens(
81
+ public func exchangeTokens< Message : DiagnosticMessage > (
103
82
unexpected: UnexpectedNodesSyntax ? ,
104
83
unexpectedTokenCondition: ( TokenSyntax ) -> Bool ,
105
84
correctTokens: [ TokenSyntax ? ] ,
106
- message: ( _ misplacedTokens: [ TokenSyntax ] ) -> DiagnosticMessage ,
85
+ message: ( _ misplacedTokens: [ TokenSyntax ] ) -> Message ,
107
86
moveFixIt: ( _ misplacedTokens: [ TokenSyntax ] ) -> FixItMessage ,
108
87
removeRedundantFixIt: ( _ misplacedTokens: [ TokenSyntax ] ) -> FixItMessage ? = { _ in nil }
109
88
) {
@@ -146,10 +125,10 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
146
125
}
147
126
148
127
/// Utility function to remove a misplaced token with a custom error message.
149
- public func removeToken(
128
+ public func removeToken< Message : DiagnosticMessage > (
150
129
_ unexpected: UnexpectedNodesSyntax ? ,
151
130
where predicate: ( TokenSyntax ) -> Bool ,
152
- message: ( TokenSyntax ) -> DiagnosticMessage
131
+ message: ( TokenSyntax ) -> Message
153
132
) {
154
133
guard let unexpected = unexpected,
155
134
let misplacedToken = unexpected. onlyToken ( where: predicate)
@@ -464,7 +443,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
464
443
unexpected: node. output? . unexpectedBetweenArrowAndReturnType,
465
444
unexpectedTokenCondition: { $0. tokenKind == . throwsKeyword } ,
466
445
correctTokens: [ node. throwsOrRethrowsKeyword] ,
467
- message: { _ in StaticParserError . throwsInReturnPosition } ,
446
+ message: { _ in . throwsInReturnPosition } ,
468
447
moveFixIt: { MoveTokensInFrontOfFixIt ( movedTokens: $0, inFrontOf: . arrow) }
469
448
)
470
449
return . visitChildren
@@ -501,7 +480,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
501
480
unexpected: node. unexpectedBeforeReturnKeyword,
502
481
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
503
482
correctTokens: [ node. expression? . as ( TryExprSyntax . self) ? . tryKeyword] ,
504
- message: { _ in StaticParserError . tryMustBePlacedOnReturnedExpr } ,
483
+ message: { _ in . tryMustBePlacedOnReturnedExpr } ,
505
484
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . returnKeyword) }
506
485
)
507
486
}
@@ -540,7 +519,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
540
519
unexpected: node. unexpectedBeforeThrowKeyword,
541
520
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
542
521
correctTokens: [ node. expression. as ( TryExprSyntax . self) ? . tryKeyword] ,
543
- message: { _ in StaticParserError . tryMustBePlacedOnThrownExpr } ,
522
+ message: { _ in . tryMustBePlacedOnThrownExpr } ,
544
523
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . throwKeyword) }
545
524
)
546
525
return . visitChildren
@@ -595,7 +574,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
595
574
removeToken (
596
575
node. unexpectedBetweenIdentifierAndInheritanceClause,
597
576
where: { $0. tokenKind == . ellipsis } ,
598
- message: { _ in StaticParserError . associatedTypeCannotUsePack }
577
+ message: { _ in . associatedTypeCannotUsePack }
599
578
)
600
579
return . visitChildren
601
580
}
@@ -611,7 +590,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
611
590
unexpected: node. unexpectedBetweenModifiersAndLetOrVarKeyword,
612
591
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
613
592
correctTokens: missingTries,
614
- message: { _ in StaticParserError . tryOnInitialValueExpression } ,
593
+ message: { _ in . tryOnInitialValueExpression } ,
615
594
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . equal) } ,
616
595
removeRedundantFixIt: { RemoveRedundantFixIt ( removeTokens: $0) }
617
596
)
0 commit comments