File: ParserDiagnosticMessages.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (766 lines) | stat: -rw-r--r-- 24,959 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#if swift(>=6)
public import SwiftDiagnostics
@_spi(Diagnostics) internal import SwiftParser
@_spi(RawSyntax) public import SwiftSyntax
#else
import SwiftDiagnostics
@_spi(Diagnostics) import SwiftParser
@_spi(RawSyntax) import SwiftSyntax
#endif

fileprivate let diagnosticDomain: String = "SwiftParser"

/// An error diagnostic whose ID is determined by the diagnostic's type.
public protocol ParserError: DiagnosticMessage {
  var diagnosticID: MessageID { get }
}

extension ParserError {
  public static var diagnosticID: MessageID {
    return MessageID(domain: diagnosticDomain, id: "\(self)")
  }

  public var diagnosticID: MessageID {
    return Self.diagnosticID
  }

  public var severity: DiagnosticSeverity {
    return .error
  }
}

public protocol ParserNote: NoteMessage {
  var noteID: MessageID { get }
}

extension ParserNote {
  @available(*, deprecated, message: "Use noteID instead.", renamed: "noteID")
  public static var fixItID: MessageID {
    return Self.noteID
  }

  public static var noteID: MessageID {
    return MessageID(domain: diagnosticDomain, id: "\(self)")
  }

  public var noteID: MessageID {
    return Self.noteID
  }
}

public protocol ParserFixIt: FixItMessage {
  var fixItID: MessageID { get }
}

extension ParserFixIt {
  public static var fixItID: MessageID {
    return MessageID(domain: diagnosticDomain, id: "\(self)")
  }

  public var fixItID: MessageID {
    return Self.fixItID
  }
}

// MARK: - Errors (please sort alphabetically)

/// A parser error with a static message.
public struct StaticParserError: DiagnosticMessage {
  public let message: String
  private let messageID: String

  /// This should only be called within a static var on DiagnosticMessage, such
  /// as the examples below. This allows us to pick up the messageID from the
  /// var name.
  fileprivate init(_ message: String, messageID: String = #function) {
    self.message = message
    self.messageID = messageID
  }

  public var diagnosticID: MessageID {
    MessageID(domain: diagnosticDomain, id: "\(type(of: self)).\(messageID)")
  }

  public var severity: DiagnosticSeverity { .error }
}

extension DiagnosticMessage where Self == StaticParserError {
  /// Please order the diagnostics alphabetically by property name.
  public static var allStatementsInSwitchMustBeCoveredByCase: Self {
    .init("all statements inside a switch must be covered by a 'case' or 'default' label")
  }
  public static var associatedTypeCannotUsePack: Self {
    .init("associated types cannot be variadic")
  }
  public static var caseOutsideOfSwitchOrEnum: Self {
    .init("'case' can only appear inside a 'switch' statement or 'enum' declaration")
  }
  public static var classConstraintCanOnlyBeUsedInProtocol: Self {
    .init("'class' constraint can only appear on protocol declarations")
  }
  public static var consecutiveDeclarationsOnSameLine: Self {
    .init("consecutive declarations on a line must be separated by newline or ';'")
  }
  public static var consecutiveStatementsOnSameLine: Self {
    .init("consecutive statements on a line must be separated by newline or ';'")
  }
  public static var cStyleForLoop: Self {
    .init("C-style for statement has been removed in Swift 3")
  }
  public static var defaultCannotBeUsedWithWhere: Self {
    .init("'default' cannot be used with a 'where' guard expression")
  }
  public static var defaultOutsideOfSwitch: Self {
    .init("'default' label can only appear inside a 'switch' statement")
  }
  public static var deinitCannotThrow: Self {
    .init("deinitializers cannot throw")
  }
  public static var editorPlaceholderInSourceFile: Self {
    .init("editor placeholder in source file")
  }
  public static var escapedNewlineAtLastLineOfMultiLineStringLiteralNotAllowed: Self {
    .init("escaped newline at the last line of a multi-line string literal is not allowed")
  }
  public static var expectedColonClass: Self {
    .init("expected ':' to begin inheritance clause")
  }
  public static var expectedExpressionAfterTry: Self {
    .init("expected expression after 'try'")
  }
  public static var expectedAssignmentInsteadOfComparisonOperator: Self {
    .init("expected '=' instead of '==' to assign default value for parameter")
  }
  public static var expectedCommaInWhereClause: Self {
    .init("expected ',' to separate the requirements of this 'where' clause")
  }
  public static var expectedLeftBraceOrIfAfterElse: Self {
    .init("expected '{' or 'if' after 'else'")
  }
  public static var expectedSequenceExpressionInForEachLoop: Self {
    .init("expected Sequence expression for for-each loop")
  }
  public static var extraTokensAtTheEndOfSourceLocationDirective: Self {
    .init("extra tokens following the #sourceLocation directive")
  }
  public static var extraTokensFollowingConditionalCompilationDirective: Self {
    .init("extra tokens following conditional compilation directive")
  }
  public static var extraRightBracket: Self {
    .init("unexpected ']' in type; did you mean to write an array type?")
  }
  public static var forbiddenExtendedEscapingString: Self {
    .init("argument cannot be an extended escaping string literal")
  }
  public static var forbiddenInterpolatedString: Self {
    return .init("argument cannot be an interpolated string literal")
  }
  public static var genericParamCantBeUsedInEnumCaseDecl: Self {
    return .init("generic signature cannot be declared in enum 'case'")
  }
  public static var initializerInPattern: Self {
    .init("unexpected initializer in pattern; did you mean to use '='?")
  }
  public static var initializerCannotHaveName: Self {
    .init("initializers cannot have a name")
  }
  public static var invalidFlagAfterPrecedenceGroupAssignment: Self {
    .init("expected 'true' or 'false' after 'assignment'")
  }
  public static var invalidPrecedenceGroupAssociativity: Self {
    .init("Expected 'none', 'left', or 'right' after 'associativity'")
  }
  public static var joinConditionsUsingComma: Self {
    .init("expected ',' joining parts of a multi-clause condition")
  }
  public static var joinPlatformsUsingComma: Self {
    .init("expected ',' joining platforms in availability condition")
  }
  public static var maximumNestingLevelOverflow: Self {
    .init("parsing has exceeded the maximum nesting level")
  }
  public static var missingColonAndExprInTernaryExpr: Self {
    .init("expected ':' and expression after '? ...' in ternary expression")
  }
  public static var missingColonInTernaryExpr: Self {
    .init("expected ':' after '? ...' in ternary expression")
  }
  public static var missingConformanceRequirement: Self {
    .init("expected ':' or '==' to indicate a conformance or same-type requirement")
  }
  public static var misspelledAsync: Self {
    .init("expected async specifier; did you mean 'async'?")
  }
  public static var misspelledThrows: Self {
    .init("expected throwing specifier; did you mean 'throws'?")
  }
  public static var missingFixityInOperatorDeclaration: Self {
    .init("operator must be declared as 'prefix', 'postfix', or 'infix'")
  }
  public static var multiLineStringLiteralMustBeginOnNewLine: Self {
    .init("multi-line string literal content must begin on a new line")
  }
  public static var multiLineStringLiteralMustHaveClosingDelimiterOnNewLine: Self {
    .init("multi-line string literal closing delimiter must begin on a new line")
  }
  public static var operatorShouldBeDeclaredWithoutBody: Self {
    .init("operator should not be declared with body")
  }
  public static var singleQuoteStringLiteral: Self {
    .init(#"Single-quoted string literal found, use '"'"#)
  }
  public static var standaloneSemicolonStatement: Self {
    .init("standalone ';' statements are not allowed")
  }
  public static var stringLiteralAtSign: Self {
    .init("string literals in Swift are not preceded by an '@' sign")
  }
  public static var subscriptsCannotHaveNames: Self {
    .init("subscripts cannot have a name")
  }
  public static var tooManyClosingPoundDelimiters: Self {
    .init("too many '#' characters in closing delimiter")
  }
  public static var tooFewClosingPoundDelimiters: Self {
    .init("expected additional '#' characters in closing delimiter")
  }
  public static var tooManyRawStringDelimitersToStartInterpolation: Self {
    .init("too many '#' characters to start string interpolation")
  }
  public static var tryMustBePlacedOnReturnedExpr: Self {
    .init("'try' must be placed on the returned expression")
  }
  public static var tryMustBePlacedOnThrownExpr: Self {
    .init("'try' must be placed on the thrown expression")
  }
  public static var tryMustBePlacedOnThenExpr: Self {
    .init("'try' must be placed on the produced expression")
  }
  public static var tryOnInitialValueExpression: Self {
    .init("'try' must be placed on the initial value expression")
  }
  public static var typeParameterPackEllipsis: Self {
    .init("ellipsis operator cannot be used with a type parameter pack")
  }
  public static var unexpectedPoundElseSpaceIf: Self {
    .init("unexpected 'if' keyword following '#else' conditional compilation directive; did you mean '#elseif'?")
  }
  public static var unexpectedSemicolon: Self {
    .init("unexpected ';' separator")
  }
  public static var versionComparisonNotNeeded: Self {
    .init("version comparison not needed")
  }
}

// MARK: - Diagnostics (please sort alphabetically)

public struct AsyncMustPrecedeThrows: ParserError {
  public let asyncKeywords: [TokenSyntax]
  public let throwsKeyword: TokenSyntax

  public var message: String {
    return
      "\(nodesDescription(asyncKeywords, format: false)) must precede \(nodesDescription([throwsKeyword], format: false))"
  }
}

public struct AvailabilityConditionAsExpression: ParserError {
  public let availabilityToken: TokenSyntax
  public let negatedAvailabilityToken: TokenSyntax

  public var message: String {
    return "\(availabilityToken) cannot be used as an expression, did you mean to use '\(negatedAvailabilityToken)'?"
  }
}

public struct AvailabilityConditionInExpression: ParserError {
  public let availabilityCondition: AvailabilityConditionSyntax

  public var message: String {
    return
      "\(nodesDescription([availabilityCondition], format: false)) cannot be used in an expression, only as a condition of 'if' or 'guard'"
  }
}

public struct CannotParseVersionTuple: ParserError {
  public let versionTuple: UnexpectedNodesSyntax

  public var message: String {
    return "cannot parse version component \(versionTuple.shortSingleLineContentDescription)"
  }
}

public struct DeinitializerSignatureError: ParserError {
  public let name: TokenSyntax?
  public let params: FunctionParameterClauseSyntax?
  public let returnClause: ReturnClauseSyntax?

  public var message: String {
    var descriptions: [String] = []

    if name != nil {
      descriptions.append("a name")
    }

    if params != nil {
      descriptions.append("parameters")
    }

    if returnClause != nil {
      var message = "return clause"

      if descriptions.isEmpty {
        message = "a " + message
      }

      descriptions.append(message)
    }

    return "deinitializers cannot have \(formatDescriptions(descriptions))"
  }
}

public struct DuplicateEffectSpecifiers: ParserError {
  public let correctSpecifier: TokenSyntax
  public let unexpectedSpecifier: TokenSyntax

  public var message: String {
    if correctSpecifier.tokenKind == unexpectedSpecifier.tokenKind {
      return "\(nodesDescription([unexpectedSpecifier], format: false)) has already been specified"
    } else {
      return
        "\(nodesDescription([unexpectedSpecifier], format: false)) conflicts with \(nodesDescription([correctSpecifier], format: false))"
    }
  }
}

public struct EffectsSpecifierAfterArrow: ParserError {
  public let effectsSpecifiersAfterArrow: [TokenSyntax]

  public var message: String {
    "\(nodesDescription(effectsSpecifiersAfterArrow, format: false)) must precede '->'"
  }
}

public struct ExtraneousCodeAtTopLevel: ParserError {
  public let extraneousCode: UnexpectedNodesSyntax

  public var message: String {
    return "extraneous \(extraneousCode.shortSingleLineContentDescription) at top level"
  }
}

public struct ExtraneousWhitespace: ParserError {
  public let tokenWithWhitespace: TokenSyntax

  public var message: String {
    return "extraneous whitespace after '\(tokenWithWhitespace.text)' is not permitted"
  }
}

public struct IdentifierNotAllowedInOperatorName: ParserError {
  public let identifier: TokenSyntax

  public var message: String {
    return
      "\(nodesDescription([identifier], format: false)) is considered an identifier and must not appear within an operator name"
  }
}

public struct InvalidFloatLiteralMissingLeadingZero: ParserError {
  public let decimalDigits: TokenSyntax

  public var message: String {
    return
      "'.\(decimalDigits.text)' is not a valid floating point literal; it must be written '0.\(decimalDigits.text)'"
  }
}

public struct InvalidIdentifierError: ParserError {
  public let invalidIdentifier: TokenSyntax
  public let missingIdentifier: TokenSyntax

  public var message: String {
    switch invalidIdentifier.tokenKind {
    case .floatLiteral(let text), .integerLiteral(let text):
      fallthrough
    case .unknown(let text) where text.first?.isNumber == true:
      let name = missingIdentifier.childNameInParent ?? "identifier"
      return "\(name) can only start with a letter or underscore, not a number"
    case .wildcard:
      return "'\(invalidIdentifier.text)' cannot be used as an identifier here"
    case let tokenKind where tokenKind.isLexerClassifiedKeyword:
      return "keyword '\(invalidIdentifier.text)' cannot be used as an identifier here"
    default:
      return "'\(invalidIdentifier.text)' is not a valid identifier"
    }
  }
}

public struct InvalidIndentationInMultiLineStringLiteralError: ParserError {
  public enum Kind: Sendable {
    case insufficientIndentation
    case unexpectedSpace
    case unexpectedTab

    var message: String {
      switch self {
      case .insufficientIndentation: return "insufficient indentation"
      case .unexpectedSpace: return "unexpected space in indentation"
      case .unexpectedTab: return "unexpected tab in indentation"
      }
    }
  }

  public let kind: Kind
  public let lines: Int

  public var message: String {
    if lines == 1 {
      return "\(kind.message) of line in multi-line string literal"
    } else {
      return "\(kind.message) of the next \(lines) lines in multi-line string literal"
    }
  }
}

public struct MissingAttributeArgument: ParserError {
  /// The name of the attribute that's missing the argument, without `@`.
  public let attributeName: TypeSyntax

  public var message: String {
    return "expected argument for '@\(attributeName)' attribute"
  }
}

public struct MissingBothStringQuotesOfStringSegments: ParserError {
  public let stringSegments: StringLiteralSegmentListSyntax

  public var message: String {
    return #"expected \#(stringSegments.shortSingleLineContentDescription) to be surrounded by '"'"#
  }
}

public struct MissingConditionInStatement: ParserError {
  let node: SyntaxProtocol

  public var message: String {
    if let name = node.nodeTypeNameForDiagnostics(allowBlockNames: false) {
      return "missing condition in \(name)"
    } else {
      return "missing condition in statement"
    }
  }
}

public struct MissingExpressionInStatement: ParserError {
  let node: SyntaxProtocol

  public var message: String {
    if let name = node.nodeTypeNameForDiagnostics(allowBlockNames: false) {
      return "expected expression in \(name)"
    } else {
      return "expected expression in statement"
    }
  }
}

public struct NegatedAvailabilityCondition: ParserError {
  public let availabilityCondition: AvailabilityConditionSyntax
  public let negatedAvailabilityKeyword: TokenSyntax

  public var message: String {
    return
      "\(nodesDescription([availabilityCondition], format: false)) cannot be used in an expression; did you mean \(nodesDescription([negatedAvailabilityKeyword], format: false))?"
  }
}

public struct SpaceSeparatedIdentifiersError: ParserError {
  public let firstToken: TokenSyntax
  public let additionalTokens: [TokenSyntax]

  public var message: String {
    if let name = firstToken.parent?.ancestorOrSelf(mapping: {
      $0.nodeTypeNameForDiagnostics(allowBlockNames: false)
    }) {
      return "found an unexpected second identifier in \(name); is there an accidental break?"
    } else {
      return "found an unexpected second identifier; is there an accidental break?"
    }
  }
}

public struct SpecifierOnParameterName: ParserError {
  public let misplacedSpecifiers: [TokenSyntax]

  public var message: String {
    return "\(nodesDescription(misplacedSpecifiers, format: false)) before a parameter name is not allowed"
  }
}

public struct TokensNotAllowedInOperatorName: ParserError {
  public let tokens: [TokenSyntax]

  public var message: String {
    return "\(nodesDescription(tokens, format: false)) is not allowed in operator names"
  }
}

public struct TrailingVersionAreIgnored: ParserError {
  public let major: TokenSyntax
  public let components: VersionComponentListSyntax

  public var message: String {
    return "trailing components of version \(major)\(components) are ignored"
  }

  public var severity: DiagnosticSeverity = .warning
}

public struct TryCannotBeUsed: ParserError {
  public let nextToken: TokenSyntax

  public var message: String {
    return "'try' cannot be used with '\(nextToken.text)'"
  }
}

public struct UnexpectedNodesError: ParserError {
  public let unexpectedNodes: UnexpectedNodesSyntax

  public var message: String {
    var message = "unexpected \(unexpectedNodes.shortSingleLineContentDescription)"
    if let parent = unexpectedNodes.parent {
      if let parentTypeName = parent.nodeTypeNameForDiagnostics(allowBlockNames: false),
        parent.children(viewMode: .sourceAccurate).first(where: { $0.totalLength.utf8Length > 0 })?.id
          == unexpectedNodes.id
      {
        message += " before \(parentTypeName)"
      } else if let parentTypeName = parent.ancestorOrSelf(mapping: {
        $0.nodeTypeNameForDiagnostics(allowBlockNames: false)
      }) {
        message += " in \(parentTypeName)"
      }
    }
    return message
  }
}

public struct UnknownDirectiveError: ParserError {
  public let unexpected: UnexpectedNodesSyntax

  public var message: String {
    return "use of unknown directive \(nodesDescription([unexpected], format: false))"
  }
}

public struct UnknownParameterError: ParserError {
  public let parameter: TokenSyntax
  public let validParameters: [TokenSyntax]

  public var message: String {
    var message = "unknown parameter '\(parameter.text)'"

    if let parentTypeName = parameter.parent?.ancestorOrSelf(mapping: {
      $0.nodeTypeNameForDiagnostics(allowBlockNames: false)
    }) {
      message += " in \(parentTypeName)"
    }

    message += "; valid parameters are \(nodesDescription(validParameters, format: true))"

    return message
  }
}

// MARK: - Notes (please sort alphabetically)

public struct EffectSpecifierDeclaredHere: ParserNote {
  let specifier: TokenSyntax

  public var message: String {
    return "\(nodesDescription([specifier], format: false)) declared here"
  }
}

/// A parser fix-it with a static message.
public struct StaticParserNote: NoteMessage {
  public let message: String
  private let messageID: String

  /// This should only be called within a static var on FixItMessage, such
  /// as the examples below. This allows us to pick up the messageID from the
  /// var name.
  fileprivate init(_ message: String, messageID: String = #function) {
    self.message = message
    self.messageID = messageID
  }

  public var noteID: MessageID {
    MessageID(domain: diagnosticDomain, id: "\(type(of: self)).\(messageID)")
  }
}

extension NoteMessage where Self == StaticParserNote {
  /// Please order alphabetically by property name.
  public static var shouldMatchIndentationOfClosingQuote: Self {
    .init("should match indentation here")
  }
}

// MARK: - Fix-Its (please sort alphabetically)

/// A parser fix-it with a static message.
public struct StaticParserFixIt: FixItMessage {
  public let message: String
  private let messageID: String

  /// This should only be called within a static var on FixItMessage, such
  /// as the examples below. This allows us to pick up the messageID from the
  /// var name.
  fileprivate init(_ message: String, messageID: String = #function) {
    self.message = message
    self.messageID = messageID
  }

  public var fixItID: MessageID {
    MessageID(domain: diagnosticDomain, id: "\(type(of: self)).\(messageID)")
  }
}

extension FixItMessage where Self == StaticParserFixIt {
  /// Please order alphabetically by property name.
  public static var changeIndentationToMatchClosingDelimiter: Self {
    .init("change indentation of this line to match closing delimiter")
  }
  public static var insertSemicolon: Self {
    .init("insert ';'")
  }
  public static var insertAttributeArguments: Self {
    .init("insert attribute argument")
  }
  public static var insertNewline: Self {
    .init("insert newline")
  }
  public static var insertWhitespace: Self {
    .init("insert whitespace")
  }
  public static var joinIdentifiers: Self {
    .init("join the identifiers together")
  }
  public static var joinIdentifiersWithCamelCase: Self {
    .init("join the identifiers together with camel-case")
  }
  public static var removeBackslash: Self {
    .init("remove '\'")
  }
  public static var removeExtraneousDelimiters: Self {
    .init("remove extraneous delimiters")
  }
  public static var insertExtraClosingPounds: Self {
    .init("insert additional closing '#' delimiters")
  }
  public static var removeExtraneousWhitespace: Self {
    .init("remove whitespace")
  }
  public static var removeOperatorBody: Self {
    .init("remove operator body")
  }
  public static var replaceCurlyQuoteByNormalQuote: Self {
    .init(#"replace curly quotes with '"'"#)
  }
  public static var replaceNonBreakingSpaceBySpace: Self {
    .init("replace non-breaking space with ' '")
  }
  public static var wrapInBackticks: Self {
    .init("if this name is unavoidable, use backticks to escape it")
  }
}

public struct InsertFixIt: ParserFixIt {
  public let tokenToBeInserted: TokenSyntax

  public var message: String {
    "insert '\(tokenToBeInserted.text)'"
  }
}

public struct MoveTokensAfterFixIt: ParserFixIt {
  /// The token that should be moved
  public let movedTokens: [TokenSyntax]

  /// The token after which `movedTokens` should be moved
  public let after: TokenKind

  public var message: String {
    "move \(nodesDescription(movedTokens, format: false)) after '\(after.nameForDiagnostics)'"
  }
}

public struct MoveTokensInFrontOfFixIt: ParserFixIt {
  /// The token that should be moved
  public let movedTokens: [TokenSyntax]

  /// The token before which 'movedTokens' should be moved
  public let inFrontOf: TokenKind

  public var message: String {
    "move \(nodesDescription(movedTokens, format: false)) in front of '\(inFrontOf.nameForDiagnostics)'"
  }
}

public struct MoveTokensInFrontOfTypeFixIt: ParserFixIt {
  /// The token that should be moved
  public let movedTokens: [TokenSyntax]

  public var message: String {
    "move \(nodesDescription(movedTokens, format: false)) in front of type"
  }
}

public struct RemoveRedundantFixIt: ParserFixIt {
  public let removeTokens: [TokenSyntax]

  public var message: String {
    "remove redundant \(nodesDescription(removeTokens, format: false))"
  }
}

public struct RemoveNodesFixIt: ParserFixIt {
  public let nodesToRemove: [Syntax]

  init(_ nodesToRemove: [some SyntaxProtocol]) {
    self.nodesToRemove = nodesToRemove.map(Syntax.init)
  }

  init(_ nodeToRemove: some SyntaxProtocol) {
    self.nodesToRemove = [Syntax(nodeToRemove)]
  }

  public var message: String {
    "remove \(nodesDescription(nodesToRemove, format: false))"
  }
}

public struct ReplaceTokensFixIt: ParserFixIt {
  public let replaceTokens: [TokenSyntax]

  public let replacements: [TokenSyntax]

  public var message: String {
    "replace \(nodesDescription(replaceTokens, format: false)) with \(nodesDescription(replacements, format: false))"
  }
}