10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ import SwiftSyntax
14
+
13
15
/// Represents the specification for a Token in the TokenSyntax file.
14
16
public struct TokenSpec {
15
17
public enum Kind {
@@ -19,22 +21,18 @@ public struct TokenSpec {
19
21
case other
20
22
}
21
23
22
- public let name : String
24
+ public let varOrCaseName : TokenSyntax
23
25
public let nameForDiagnostics : String
24
26
public let text : String ?
25
27
public let kind : Kind
26
28
27
- public var swiftKind : String {
28
- return lowercaseFirstWord ( name: self . name)
29
- }
30
-
31
29
fileprivate init (
32
30
name: String ,
33
31
nameForDiagnostics: String ,
34
32
text: String ? = nil ,
35
33
kind: Kind
36
34
) {
37
- self . name = name
35
+ self . varOrCaseName = . identifier ( name)
38
36
self . nameForDiagnostics = nameForDiagnostics
39
37
self . text = text
40
38
self . kind = kind
@@ -69,57 +67,57 @@ public struct TokenSpec {
69
67
}
70
68
71
69
public let SYNTAX_TOKENS : [ TokenSpec ] = [
72
- . punctuator( name: " Arrow " , text: " -> " ) ,
73
- . punctuator( name: " AtSign " , text: " @ " ) ,
74
- . punctuator( name: " Backslash " , text: " \\ " ) ,
75
- . punctuator( name: " Backtick " , text: " ` " ) ,
76
- . other( name: " BinaryOperator " , nameForDiagnostics: " binary operator " ) ,
77
- . punctuator( name: " Colon " , text: " : " ) ,
78
- . punctuator( name: " Comma " , text: " , " ) ,
79
- . other( name: " DollarIdentifier " , nameForDiagnostics: " dollar identifier " ) ,
80
- . punctuator( name: " Ellipsis " , text: " ... " ) ,
81
- . other( name: " EndOfFile " , nameForDiagnostics: " end of file " , text: " " ) ,
82
- . punctuator( name: " Equal " , text: " = " ) ,
83
- . punctuator( name: " ExclamationMark " , text: " ! " ) ,
84
- . other( name: " ExtendedRegexDelimiter " , nameForDiagnostics: " extended delimiter " ) ,
85
- . other( name: " FloatingLiteral " , nameForDiagnostics: " floating literal " ) ,
86
- . other( name: " Identifier " , nameForDiagnostics: " identifier " ) ,
87
- . punctuator( name: " InfixQuestionMark " , text: " ? " ) ,
88
- . other( name: " IntegerLiteral " , nameForDiagnostics: " integer literal " ) ,
89
- TokenSpec ( name: " Keyword " , nameForDiagnostics: " keyword " , text: nil , kind: . keyword) ,
90
- . punctuator( name: " LeftAngle " , text: " < " ) ,
91
- . punctuator( name: " LeftBrace " , text: " { " ) ,
92
- . punctuator( name: " LeftParen " , text: " ( " ) ,
93
- . punctuator( name: " LeftSquare " , text: " [ " ) ,
94
- . punctuator( name: " MultilineStringQuote " , text: " \" \" \" " ) ,
95
- . punctuator( name: " Period " , text: " . " ) ,
96
- . other( name: " PostfixOperator " , nameForDiagnostics: " postfix operator " ) ,
97
- . punctuator( name: " PostfixQuestionMark " , text: " ? " ) ,
98
- . punctuator( name: " Pound " , text: " # " ) ,
99
- . poundKeyword( name: " PoundAvailable " , text: " #available " ) ,
100
- . poundKeyword( name: " PoundElse " , text: " #else " ) ,
101
- . poundKeyword( name: " PoundElseif " , text: " #elseif " ) ,
102
- . poundKeyword( name: " PoundEndif " , text: " #endif " ) ,
103
- . poundKeyword( name: " PoundIf " , text: " #if " ) ,
104
- . poundKeyword( name: " PoundSourceLocation " , text: " #sourceLocation " ) ,
105
- . poundKeyword( name: " PoundUnavailable " , text: " #unavailable " ) ,
106
- . punctuator( name: " PrefixAmpersand " , text: " & " ) ,
107
- . other( name: " PrefixOperator " , nameForDiagnostics: " prefix operator " ) ,
108
- . other( name: " RawStringDelimiter " , nameForDiagnostics: " raw string delimiter " ) ,
109
- . other( name: " RegexLiteralPattern " , nameForDiagnostics: " regex pattern " ) ,
110
- . punctuator( name: " RegexSlash " , text: " / " ) ,
111
- . punctuator( name: " RightAngle " , text: " > " ) ,
112
- . punctuator( name: " RightBrace " , text: " } " ) ,
113
- . punctuator( name: " RightParen " , text: " ) " ) ,
114
- . punctuator( name: " RightSquare " , text: " ] " ) ,
115
- . punctuator( name: " Semicolon " , text: " ; " ) ,
116
- . punctuator( name: " SingleQuote " , text: " \' " ) ,
117
- . punctuator( name: " StringQuote " , text: " \" " ) ,
118
- . other( name: " StringSegment " , nameForDiagnostics: " string segment " ) ,
119
- . other( name: " Unknown " , nameForDiagnostics: " token " ) ,
120
- . other( name: " Wildcard " , nameForDiagnostics: " wildcard " , text: " _ " ) ,
70
+ . punctuator( name: " arrow " , text: " -> " ) ,
71
+ . punctuator( name: " atSign " , text: " @ " ) ,
72
+ . punctuator( name: " backslash " , text: " \\ " ) ,
73
+ . punctuator( name: " backtick " , text: " ` " ) ,
74
+ . other( name: " binaryOperator " , nameForDiagnostics: " binary operator " ) ,
75
+ . punctuator( name: " colon " , text: " : " ) ,
76
+ . punctuator( name: " comma " , text: " , " ) ,
77
+ . other( name: " dollarIdentifier " , nameForDiagnostics: " dollar identifier " ) ,
78
+ . punctuator( name: " ellipsis " , text: " ... " ) ,
79
+ . other( name: " endOfFile " , nameForDiagnostics: " end of file " , text: " " ) ,
80
+ . punctuator( name: " equal " , text: " = " ) ,
81
+ . punctuator( name: " exclamationMark " , text: " ! " ) ,
82
+ . other( name: " extendedRegexDelimiter " , nameForDiagnostics: " extended delimiter " ) ,
83
+ . other( name: " floatingLiteral " , nameForDiagnostics: " floating literal " ) ,
84
+ . other( name: " identifier " , nameForDiagnostics: " identifier " ) ,
85
+ . punctuator( name: " infixQuestionMark " , text: " ? " ) ,
86
+ . other( name: " integerLiteral " , nameForDiagnostics: " integer literal " ) ,
87
+ TokenSpec ( name: " keyword " , nameForDiagnostics: " keyword " , text: nil , kind: . keyword) ,
88
+ . punctuator( name: " leftAngle " , text: " < " ) ,
89
+ . punctuator( name: " leftBrace " , text: " { " ) ,
90
+ . punctuator( name: " leftParen " , text: " ( " ) ,
91
+ . punctuator( name: " leftSquare " , text: " [ " ) ,
92
+ . punctuator( name: " multilineStringQuote " , text: " \" \" \" " ) ,
93
+ . punctuator( name: " period " , text: " . " ) ,
94
+ . other( name: " postfixOperator " , nameForDiagnostics: " postfix operator " ) ,
95
+ . punctuator( name: " postfixQuestionMark " , text: " ? " ) ,
96
+ . punctuator( name: " pound " , text: " # " ) ,
97
+ . poundKeyword( name: " poundAvailable " , text: " #available " ) ,
98
+ . poundKeyword( name: " poundElse " , text: " #else " ) ,
99
+ . poundKeyword( name: " poundElseif " , text: " #elseif " ) ,
100
+ . poundKeyword( name: " poundEndif " , text: " #endif " ) ,
101
+ . poundKeyword( name: " poundIf " , text: " #if " ) ,
102
+ . poundKeyword( name: " poundSourceLocation " , text: " #sourceLocation " ) ,
103
+ . poundKeyword( name: " poundUnavailable " , text: " #unavailable " ) ,
104
+ . punctuator( name: " prefixAmpersand " , text: " & " ) ,
105
+ . other( name: " prefixOperator " , nameForDiagnostics: " prefix operator " ) ,
106
+ . other( name: " rawStringDelimiter " , nameForDiagnostics: " raw string delimiter " ) ,
107
+ . other( name: " regexLiteralPattern " , nameForDiagnostics: " regex pattern " ) ,
108
+ . punctuator( name: " regexSlash " , text: " / " ) ,
109
+ . punctuator( name: " rightAngle " , text: " > " ) ,
110
+ . punctuator( name: " rightBrace " , text: " } " ) ,
111
+ . punctuator( name: " rightParen " , text: " ) " ) ,
112
+ . punctuator( name: " rightSquare " , text: " ] " ) ,
113
+ . punctuator( name: " semicolon " , text: " ; " ) ,
114
+ . punctuator( name: " singleQuote " , text: " \' " ) ,
115
+ . punctuator( name: " stringQuote " , text: " \" " ) ,
116
+ . other( name: " stringSegment " , nameForDiagnostics: " string segment " ) ,
117
+ . other( name: " unknown " , nameForDiagnostics: " token " ) ,
118
+ . other( name: " wildcard " , nameForDiagnostics: " wildcard " , text: " _ " ) ,
121
119
]
122
120
123
121
public let SYNTAX_TOKEN_MAP = Dictionary (
124
- uniqueKeysWithValues: SYNTAX_TOKENS . map { ( " \( $0. name ) Token " , $0) }
122
+ uniqueKeysWithValues: SYNTAX_TOKENS . map { ( " \( $0. varOrCaseName . description . withFirstCharacterUppercased ) Token " , $0) }
125
123
)
0 commit comments