@@ -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
) {
@@ -147,10 +126,10 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
147
126
148
127
/// If `unexpected` only contains a single token that satisfies `predicate`,
149
128
/// emits a diagnostic with `message` that removes this token.
150
- public func removeToken(
129
+ public func removeToken< Message : DiagnosticMessage > (
151
130
_ unexpected: UnexpectedNodesSyntax ? ,
152
131
where predicate: ( TokenSyntax ) -> Bool ,
153
- message: ( TokenSyntax ) -> DiagnosticMessage
132
+ message: ( TokenSyntax ) -> Message
154
133
) {
155
134
guard let unexpected = unexpected,
156
135
let misplacedToken = unexpected. onlyToken ( where: predicate)
@@ -486,7 +465,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
486
465
unexpected: node. output? . unexpectedBetweenArrowAndReturnType,
487
466
unexpectedTokenCondition: { $0. tokenKind == . throwsKeyword } ,
488
467
correctTokens: [ node. throwsOrRethrowsKeyword] ,
489
- message: { _ in StaticParserError . throwsInReturnPosition } ,
468
+ message: { _ in . throwsInReturnPosition } ,
490
469
moveFixIt: { MoveTokensInFrontOfFixIt ( movedTokens: $0, inFrontOf: . arrow) }
491
470
)
492
471
return . visitChildren
@@ -538,7 +517,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
538
517
unexpected: node. unexpectedBeforeReturnKeyword,
539
518
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
540
519
correctTokens: [ node. expression? . as ( TryExprSyntax . self) ? . tryKeyword] ,
541
- message: { _ in StaticParserError . tryMustBePlacedOnReturnedExpr } ,
520
+ message: { _ in . tryMustBePlacedOnReturnedExpr } ,
542
521
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . returnKeyword) }
543
522
)
544
523
}
@@ -577,7 +556,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
577
556
unexpected: node. unexpectedBeforeThrowKeyword,
578
557
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
579
558
correctTokens: [ node. expression. as ( TryExprSyntax . self) ? . tryKeyword] ,
580
- message: { _ in StaticParserError . tryMustBePlacedOnThrownExpr } ,
559
+ message: { _ in . tryMustBePlacedOnThrownExpr } ,
581
560
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . throwKeyword) }
582
561
)
583
562
return . visitChildren
@@ -647,7 +626,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
647
626
removeToken (
648
627
node. unexpectedBetweenIdentifierAndInheritanceClause,
649
628
where: { $0. tokenKind == . ellipsis } ,
650
- message: { _ in StaticParserError . associatedTypeCannotUsePack }
629
+ message: { _ in . associatedTypeCannotUsePack }
651
630
)
652
631
return . visitChildren
653
632
}
@@ -663,7 +642,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
663
642
unexpected: node. unexpectedBetweenModifiersAndLetOrVarKeyword,
664
643
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
665
644
correctTokens: missingTries,
666
- message: { _ in StaticParserError . tryOnInitialValueExpression } ,
645
+ message: { _ in . tryOnInitialValueExpression } ,
667
646
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . equal) } ,
668
647
removeRedundantFixIt: { RemoveRedundantFixIt ( removeTokens: $0) }
669
648
)
0 commit comments