@@ -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)
@@ -462,7 +441,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
462
441
unexpected: node. output? . unexpectedBetweenArrowAndReturnType,
463
442
unexpectedTokenCondition: { $0. tokenKind == . throwsKeyword } ,
464
443
correctTokens: [ node. throwsOrRethrowsKeyword] ,
465
- message: { _ in StaticParserError . throwsInReturnPosition } ,
444
+ message: { _ in . throwsInReturnPosition } ,
466
445
moveFixIt: { MoveTokensInFrontOfFixIt ( movedTokens: $0, inFrontOf: . arrow) }
467
446
)
468
447
return . visitChildren
@@ -514,7 +493,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
514
493
unexpected: node. unexpectedBeforeReturnKeyword,
515
494
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
516
495
correctTokens: [ node. expression? . as ( TryExprSyntax . self) ? . tryKeyword] ,
517
- message: { _ in StaticParserError . tryMustBePlacedOnReturnedExpr } ,
496
+ message: { _ in . tryMustBePlacedOnReturnedExpr } ,
518
497
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . returnKeyword) }
519
498
)
520
499
}
@@ -553,7 +532,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
553
532
unexpected: node. unexpectedBeforeThrowKeyword,
554
533
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
555
534
correctTokens: [ node. expression. as ( TryExprSyntax . self) ? . tryKeyword] ,
556
- message: { _ in StaticParserError . tryMustBePlacedOnThrownExpr } ,
535
+ message: { _ in . tryMustBePlacedOnThrownExpr } ,
557
536
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . throwKeyword) }
558
537
)
559
538
return . visitChildren
@@ -623,7 +602,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
623
602
removeToken (
624
603
node. unexpectedBetweenIdentifierAndInheritanceClause,
625
604
where: { $0. tokenKind == . ellipsis } ,
626
- message: { _ in StaticParserError . associatedTypeCannotUsePack }
605
+ message: { _ in . associatedTypeCannotUsePack }
627
606
)
628
607
return . visitChildren
629
608
}
@@ -639,7 +618,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
639
618
unexpected: node. unexpectedBetweenModifiersAndLetOrVarKeyword,
640
619
unexpectedTokenCondition: { $0. tokenKind == . tryKeyword } ,
641
620
correctTokens: missingTries,
642
- message: { _ in StaticParserError . tryOnInitialValueExpression } ,
621
+ message: { _ in . tryOnInitialValueExpression } ,
643
622
moveFixIt: { MoveTokensAfterFixIt ( movedTokens: $0, after: . equal) } ,
644
623
removeRedundantFixIt: { RemoveRedundantFixIt ( removeTokens: $0) }
645
624
)
0 commit comments