@@ -16,11 +16,11 @@ import SwiftDiagnostics
1616fileprivate let diagnosticDomain : String = " SwiftLexer "
1717
1818/// A error diagnostic whose ID is determined by the diagnostic's type.
19- public protocol LexerError : DiagnosticMessage {
19+ public protocol TokenError : DiagnosticMessage {
2020 var diagnosticID : MessageID { get }
2121}
2222
23- public extension LexerError {
23+ public extension TokenError {
2424 static var diagnosticID : MessageID {
2525 return MessageID ( domain: diagnosticDomain, id: " \( self ) " )
2626 }
@@ -37,7 +37,7 @@ public extension LexerError {
3737// MARK: - Errors (please sort alphabetically)
3838
3939/// Please order the cases in this enum alphabetically by case name.
40- public enum StaticLexerError : String , DiagnosticMessage {
40+ public enum StaticTokenError : String , DiagnosticMessage {
4141 case expectedBinaryExponentInHexFloatLiteral = " hexadecimal floating point literal must end with an exponent "
4242 case expectedClosingBraceInUnicodeEscape = #"expected '}' in \u{...} escape sequence"#
4343 case expectedDigitInFloatLiteral = " expected a digit in floating point exponent "
@@ -48,7 +48,7 @@ public enum StaticLexerError: String, DiagnosticMessage {
4848 case invalidIdentifierStartCharacter = " an identifier cannot begin with this character "
4949 case invalidNumberOfHexDigitsInUnicodeEscape = #"\u{...} escape sequence expects between 1 and 8 hex digits"#
5050 case invalidUtf8 = " invalid UTF-8 found in source file "
51- case lexerErrorOffsetOverflow = " the lexer dicovered an error in this token but was not able to represent its offset due to overflow; please split the token "
51+ case tokenDiagnosticOffsetOverflow = " the lexer dicovered an error in this token but was not able to represent its offset due to overflow; please split the token "
5252 case sourceConflictMarker = " source control conflict marker in source file "
5353 case unexpectedBlockCommentEnd = " unexpected end of block comment "
5454 case unicodeCurlyQuote = #"unicode curly quote found; use '"' instead"#
@@ -64,7 +64,7 @@ public enum StaticLexerError: String, DiagnosticMessage {
6464}
6565
6666/// Please order the cases in this enum alphabetically by case name.
67- public enum StaticLexerWarning : String , DiagnosticMessage {
67+ public enum StaticTokenWarning : String , DiagnosticMessage {
6868 case nonBreakingSpace = " non-breaking space (U+00A0) used instead of regular space "
6969 case nulCharacter = " nul character embedded in middle of file "
7070
@@ -77,7 +77,7 @@ public enum StaticLexerWarning: String, DiagnosticMessage {
7777 public var severity : DiagnosticSeverity { . warning }
7878}
7979
80- public struct InvalidFloatingPointExponentDigit : LexerError {
80+ public struct InvalidFloatingPointExponentDigit : TokenError {
8181 public enum Kind {
8282 case digit( Unicode . Scalar )
8383 case character( Unicode . Scalar )
@@ -94,7 +94,7 @@ public struct InvalidFloatingPointExponentDigit: LexerError {
9494 }
9595}
9696
97- public struct InvalidDigitInIntegerLiteral : LexerError {
97+ public struct InvalidDigitInIntegerLiteral : TokenError {
9898 public enum Kind {
9999 case binary( Unicode . Scalar )
100100 case octal( Unicode . Scalar )
@@ -118,10 +118,10 @@ public struct InvalidDigitInIntegerLiteral: LexerError {
118118 }
119119}
120120
121- // MARK: - Convert LexerError from SwiftSyntax to error messages
121+ // MARK: - Convert TokenDiagnostic from SwiftSyntax to error messages
122122
123- public extension SwiftSyntax . LexerError {
124- /// `tokenText` is the entire text of the token in which the `LexerError `
123+ public extension SwiftSyntax . TokenDiagnostic {
124+ /// `tokenText` is the entire text of the token in which the `TokenDiagnostic `
125125 /// occurred, including trivia.
126126 @_spi ( RawSyntax)
127127 func diagnosticMessage( wholeTextBytes: [ UInt8 ] ) -> DiagnosticMessage {
@@ -132,34 +132,34 @@ public extension SwiftSyntax.LexerError {
132132 }
133133
134134 switch self . kind {
135- case . expectedBinaryExponentInHexFloatLiteral: return StaticLexerError . expectedBinaryExponentInHexFloatLiteral
136- case . expectedClosingBraceInUnicodeEscape: return StaticLexerError . expectedClosingBraceInUnicodeEscape
137- case . expectedDigitInFloatLiteral: return StaticLexerError . expectedDigitInFloatLiteral
138- case . expectedHexCodeInUnicodeEscape: return StaticLexerError . expectedHexCodeInUnicodeEscape
139- case . expectedHexDigitInHexLiteral: return StaticLexerError . expectedHexDigitInHexLiteral
135+ case . expectedBinaryExponentInHexFloatLiteral: return StaticTokenError . expectedBinaryExponentInHexFloatLiteral
136+ case . expectedClosingBraceInUnicodeEscape: return StaticTokenError . expectedClosingBraceInUnicodeEscape
137+ case . expectedDigitInFloatLiteral: return StaticTokenError . expectedDigitInFloatLiteral
138+ case . expectedHexCodeInUnicodeEscape: return StaticTokenError . expectedHexCodeInUnicodeEscape
139+ case . expectedHexDigitInHexLiteral: return StaticTokenError . expectedHexDigitInHexLiteral
140140 case . insufficientIndentationInMultilineStringLiteral:
141141 // This should be diagnosed when visiting the `StringLiteralExprSyntax`
142142 // inside `ParseDiagnosticsGenerator` but fall back to an error message
143143 // here in case the error is not diagnosed.
144144 return InvalidIndentationInMultiLineStringLiteralError ( kind: . insufficientIndentation, lines: 1 )
145145 case . invalidBinaryDigitInIntegerLiteral: return InvalidDigitInIntegerLiteral ( kind: . binary( scalarAtErrorOffset) )
146- case . invalidCharacter: return StaticLexerError . invalidCharacter
146+ case . invalidCharacter: return StaticTokenError . invalidCharacter
147147 case . invalidDecimalDigitInIntegerLiteral: return InvalidDigitInIntegerLiteral ( kind: . decimal( scalarAtErrorOffset) )
148- case . invalidEscapeSequenceInStringLiteral: return StaticLexerError . invalidEscapeSequenceInStringLiteral
148+ case . invalidEscapeSequenceInStringLiteral: return StaticTokenError . invalidEscapeSequenceInStringLiteral
149149 case . invalidFloatingPointExponentCharacter: return InvalidFloatingPointExponentDigit ( kind: . character( scalarAtErrorOffset) )
150150 case . invalidFloatingPointExponentDigit: return InvalidFloatingPointExponentDigit ( kind: . digit( scalarAtErrorOffset) )
151151 case . invalidHexDigitInIntegerLiteral: return InvalidDigitInIntegerLiteral ( kind: . hex( scalarAtErrorOffset) )
152- case . invalidIdentifierStartCharacter: return StaticLexerError . invalidIdentifierStartCharacter
153- case . invalidNumberOfHexDigitsInUnicodeEscape: return StaticLexerError . invalidNumberOfHexDigitsInUnicodeEscape
152+ case . invalidIdentifierStartCharacter: return StaticTokenError . invalidIdentifierStartCharacter
153+ case . invalidNumberOfHexDigitsInUnicodeEscape: return StaticTokenError . invalidNumberOfHexDigitsInUnicodeEscape
154154 case . invalidOctalDigitInIntegerLiteral: return InvalidDigitInIntegerLiteral ( kind: . octal( scalarAtErrorOffset) )
155- case . invalidUtf8: return StaticLexerError . invalidUtf8
156- case . lexerErrorOffsetOverflow : return StaticLexerError . lexerErrorOffsetOverflow
157- case . nonBreakingSpace: return StaticLexerWarning . nonBreakingSpace
158- case . nulCharacter: return StaticLexerWarning . nulCharacter
159- case . sourceConflictMarker: return StaticLexerError . sourceConflictMarker
160- case . unexpectedBlockCommentEnd: return StaticLexerError . unexpectedBlockCommentEnd
161- case . unicodeCurlyQuote: return StaticLexerError . unicodeCurlyQuote
162- case . unprintableAsciiCharacter: return StaticLexerError . unprintableAsciiCharacter
155+ case . invalidUtf8: return StaticTokenError . invalidUtf8
156+ case . tokenDiagnosticOffsetOverflow : return StaticTokenError . tokenDiagnosticOffsetOverflow
157+ case . nonBreakingSpace: return StaticTokenWarning . nonBreakingSpace
158+ case . nulCharacter: return StaticTokenWarning . nulCharacter
159+ case . sourceConflictMarker: return StaticTokenError . sourceConflictMarker
160+ case . unexpectedBlockCommentEnd: return StaticTokenError . unexpectedBlockCommentEnd
161+ case . unicodeCurlyQuote: return StaticTokenError . unicodeCurlyQuote
162+ case . unprintableAsciiCharacter: return StaticTokenError . unprintableAsciiCharacter
163163 }
164164 }
165165
0 commit comments