@@ -16,11 +16,11 @@ import SwiftDiagnostics
16
16
fileprivate let diagnosticDomain : String = " SwiftLexer "
17
17
18
18
/// A error diagnostic whose ID is determined by the diagnostic's type.
19
- public protocol LexerError : DiagnosticMessage {
19
+ public protocol TokenError : DiagnosticMessage {
20
20
var diagnosticID : MessageID { get }
21
21
}
22
22
23
- public extension LexerError {
23
+ public extension TokenError {
24
24
static var diagnosticID : MessageID {
25
25
return MessageID ( domain: diagnosticDomain, id: " \( self ) " )
26
26
}
@@ -37,7 +37,7 @@ public extension LexerError {
37
37
// MARK: - Errors (please sort alphabetically)
38
38
39
39
/// Please order the cases in this enum alphabetically by case name.
40
- public enum StaticLexerError : String , DiagnosticMessage {
40
+ public enum StaticTokenError : String , DiagnosticMessage {
41
41
case expectedBinaryExponentInHexFloatLiteral = " hexadecimal floating point literal must end with an exponent "
42
42
case expectedClosingBraceInUnicodeEscape = #"expected '}' in \u{...} escape sequence"#
43
43
case expectedDigitInFloatLiteral = " expected a digit in floating point exponent "
@@ -48,7 +48,7 @@ public enum StaticLexerError: String, DiagnosticMessage {
48
48
case invalidIdentifierStartCharacter = " an identifier cannot begin with this character "
49
49
case invalidNumberOfHexDigitsInUnicodeEscape = #"\u{...} escape sequence expects between 1 and 8 hex digits"#
50
50
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 "
52
52
case sourceConflictMarker = " source control conflict marker in source file "
53
53
case unexpectedBlockCommentEnd = " unexpected end of block comment "
54
54
case unicodeCurlyQuote = #"unicode curly quote found; use '"' instead"#
@@ -64,7 +64,7 @@ public enum StaticLexerError: String, DiagnosticMessage {
64
64
}
65
65
66
66
/// Please order the cases in this enum alphabetically by case name.
67
- public enum StaticLexerWarning : String , DiagnosticMessage {
67
+ public enum StaticTokenWarning : String , DiagnosticMessage {
68
68
case nonBreakingSpace = " non-breaking space (U+00A0) used instead of regular space "
69
69
case nulCharacter = " nul character embedded in middle of file "
70
70
@@ -77,7 +77,7 @@ public enum StaticLexerWarning: String, DiagnosticMessage {
77
77
public var severity : DiagnosticSeverity { . warning }
78
78
}
79
79
80
- public struct InvalidFloatingPointExponentDigit : LexerError {
80
+ public struct InvalidFloatingPointExponentDigit : TokenError {
81
81
public enum Kind {
82
82
case digit( Unicode . Scalar )
83
83
case character( Unicode . Scalar )
@@ -94,7 +94,7 @@ public struct InvalidFloatingPointExponentDigit: LexerError {
94
94
}
95
95
}
96
96
97
- public struct InvalidDigitInIntegerLiteral : LexerError {
97
+ public struct InvalidDigitInIntegerLiteral : TokenError {
98
98
public enum Kind {
99
99
case binary( Unicode . Scalar )
100
100
case octal( Unicode . Scalar )
@@ -118,10 +118,10 @@ public struct InvalidDigitInIntegerLiteral: LexerError {
118
118
}
119
119
}
120
120
121
- // MARK: - Convert LexerError from SwiftSyntax to error messages
121
+ // MARK: - Convert TokenDiagnostic from SwiftSyntax to error messages
122
122
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 `
125
125
/// occurred, including trivia.
126
126
@_spi ( RawSyntax)
127
127
func diagnosticMessage( wholeTextBytes: [ UInt8 ] ) -> DiagnosticMessage {
@@ -132,34 +132,34 @@ public extension SwiftSyntax.LexerError {
132
132
}
133
133
134
134
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
140
140
case . insufficientIndentationInMultilineStringLiteral:
141
141
// This should be diagnosed when visiting the `StringLiteralExprSyntax`
142
142
// inside `ParseDiagnosticsGenerator` but fall back to an error message
143
143
// here in case the error is not diagnosed.
144
144
return InvalidIndentationInMultiLineStringLiteralError ( kind: . insufficientIndentation, lines: 1 )
145
145
case . invalidBinaryDigitInIntegerLiteral: return InvalidDigitInIntegerLiteral ( kind: . binary( scalarAtErrorOffset) )
146
- case . invalidCharacter: return StaticLexerError . invalidCharacter
146
+ case . invalidCharacter: return StaticTokenError . invalidCharacter
147
147
case . invalidDecimalDigitInIntegerLiteral: return InvalidDigitInIntegerLiteral ( kind: . decimal( scalarAtErrorOffset) )
148
- case . invalidEscapeSequenceInStringLiteral: return StaticLexerError . invalidEscapeSequenceInStringLiteral
148
+ case . invalidEscapeSequenceInStringLiteral: return StaticTokenError . invalidEscapeSequenceInStringLiteral
149
149
case . invalidFloatingPointExponentCharacter: return InvalidFloatingPointExponentDigit ( kind: . character( scalarAtErrorOffset) )
150
150
case . invalidFloatingPointExponentDigit: return InvalidFloatingPointExponentDigit ( kind: . digit( scalarAtErrorOffset) )
151
151
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
154
154
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
163
163
}
164
164
}
165
165
0 commit comments