@@ -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)
@@ -485,7 +464,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
485
464
unexpected: node. output? . unexpectedBetweenArrowAndReturnType,
486
465
unexpectedTokenCondition: { $0. tokenKind == . throwsKeyword } ,
487
466
correctTokens: [ node. throwsOrRethrowsKeyword] ,
488
- message: { _ in StaticParserError . throwsInReturnPosition } ,
467
+ message: { _ in . throwsInReturnPosition } ,
489
468
moveFixIt: { MoveTokensInFrontOfFixIt ( movedTokens: $0, inFrontOf: . arrow) }
490
469
)
491
470
return . visitChildren
@@ -537,7 +516,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
537
516
unexpected: node. unexpectedBeforeReturnKeyword,
538
517
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
539
518
correctTokens: [ node. expression? . as ( TryExprSyntax . self) ? . tryKeyword] ,
540
- message: { _ in StaticParserError . tryMustBePlacedOnReturnedExpr } ,
519
+ message: { _ in . tryMustBePlacedOnReturnedExpr } ,
541
520
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . returnKeyword) }
542
521
)
543
522
}
@@ -576,7 +555,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
576
555
unexpected: node. unexpectedBeforeThrowKeyword,
577
556
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
578
557
correctTokens: [ node. expression. as ( TryExprSyntax . self) ? . tryKeyword] ,
579
- message: { _ in StaticParserError . tryMustBePlacedOnThrownExpr } ,
558
+ message: { _ in . tryMustBePlacedOnThrownExpr } ,
580
559
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . throwKeyword) }
581
560
)
582
561
return . visitChildren
@@ -646,7 +625,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
646
625
removeToken (
647
626
node. unexpectedBetweenIdentifierAndInheritanceClause,
648
627
where: { $0. tokenKind == . ellipsis } ,
649
- message: { _ in StaticParserError . associatedTypeCannotUsePack }
628
+ message: { _ in . associatedTypeCannotUsePack }
650
629
)
651
630
return . visitChildren
652
631
}
@@ -662,7 +641,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
662
641
unexpected: node. unexpectedBetweenModifiersAndLetOrVarKeyword,
663
642
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
664
643
correctTokens: missingTries,
665
- message: { _ in StaticParserError . tryOnInitialValueExpression } ,
644
+ message: { _ in . tryOnInitialValueExpression } ,
666
645
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . equal) } ,
667
646
removeRedundantFixIt: { RemoveRedundantFixIt ( removeTokens: $0) }
668
647
)
0 commit comments