|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | /// Represents the specification for a Token in the TokenSyntax file.
|
14 |
| -public class TokenSpec { |
| 14 | +public struct TokenSpec { |
15 | 15 | public let name: String
|
16 | 16 | public let nameForDiagnostics: String
|
17 | 17 | public let text: String?
|
| 18 | + public let isPunctuation: Bool |
18 | 19 | public let associatedValueClass: String?
|
19 | 20 |
|
20 | 21 | public var swiftKind: String {
|
21 | 22 | return lowercaseFirstWord(name: self.name)
|
22 | 23 | }
|
23 | 24 |
|
24 |
| - init( |
| 25 | + private init( |
25 | 26 | name: String,
|
26 | 27 | nameForDiagnostics: String,
|
27 | 28 | text: String? = nil,
|
| 29 | + isPunctuation: Bool, |
28 | 30 | associatedValueClass: String? = nil
|
29 | 31 | ) {
|
30 | 32 | self.name = name
|
31 | 33 | self.nameForDiagnostics = nameForDiagnostics
|
32 | 34 | self.text = text
|
| 35 | + self.isPunctuation = isPunctuation |
33 | 36 | self.associatedValueClass = associatedValueClass
|
34 | 37 | }
|
35 |
| -} |
36 |
| - |
37 |
| -public class PoundSpec: TokenSpec { |
38 |
| - init( |
39 |
| - name: String, |
40 |
| - nameForDiagnostics: String? = nil, |
41 |
| - text: String |
42 |
| - ) { |
43 |
| - super.init( |
44 |
| - name: name, |
45 |
| - nameForDiagnostics: nameForDiagnostics ?? text, |
46 |
| - text: text |
47 |
| - ) |
48 |
| - } |
49 |
| -} |
50 | 38 |
|
51 |
| -public class PoundObjectLiteralSpec: PoundSpec { |
52 |
| - let `protocol`: String |
53 |
| - |
54 |
| - init( |
55 |
| - name: String, |
56 |
| - text: String, |
57 |
| - nameForDiagnostics: String, |
58 |
| - `protocol`: String |
59 |
| - ) { |
60 |
| - self.`protocol` = `protocol` |
61 |
| - super.init( |
| 39 | + static func punctuator(name: String, text: String) -> TokenSpec { |
| 40 | + return TokenSpec( |
62 | 41 | name: name,
|
63 |
| - nameForDiagnostics: nameForDiagnostics, |
64 |
| - text: text |
| 42 | + nameForDiagnostics: text, |
| 43 | + text: text, |
| 44 | + isPunctuation: true, |
| 45 | + associatedValueClass: nil |
65 | 46 | )
|
66 | 47 | }
|
67 |
| -} |
68 |
| - |
69 |
| -public class PoundConfigSpec: PoundSpec {} |
70 | 48 |
|
71 |
| -public class PoundDirectiveSpec: PoundSpec { |
72 |
| - init( |
73 |
| - name: String, |
74 |
| - text: String |
75 |
| - ) { |
76 |
| - super.init( |
| 49 | + static func poundKeyword(name: String, text: String) -> TokenSpec { |
| 50 | + return TokenSpec( |
77 | 51 | name: name,
|
78 |
| - text: text |
| 52 | + nameForDiagnostics: text, |
| 53 | + text: text, |
| 54 | + isPunctuation: false, |
| 55 | + associatedValueClass: nil |
79 | 56 | )
|
80 | 57 | }
|
81 |
| -} |
82 | 58 |
|
83 |
| -public class PoundConditionalDirectiveSpec: PoundDirectiveSpec { |
84 |
| - override init( |
85 |
| - name: String, |
86 |
| - text: String |
87 |
| - ) { |
88 |
| - super.init( |
| 59 | + static func other(name: String, nameForDiagnostics: String, text: String? = nil, associatedValueClass: String? = nil) -> TokenSpec { |
| 60 | + TokenSpec( |
89 | 61 | name: name,
|
90 |
| - text: text |
| 62 | + nameForDiagnostics: nameForDiagnostics, |
| 63 | + text: text, |
| 64 | + isPunctuation: false, |
| 65 | + associatedValueClass: associatedValueClass |
91 | 66 | )
|
92 |
| - } |
93 |
| -} |
94 | 67 |
|
95 |
| -public class PunctuatorSpec: TokenSpec { |
96 |
| - init( |
97 |
| - name: String, |
98 |
| - text: String |
99 |
| - ) { |
100 |
| - super.init( |
101 |
| - name: name, |
102 |
| - nameForDiagnostics: text, |
103 |
| - text: text |
104 |
| - ) |
105 | 68 | }
|
106 | 69 | }
|
107 | 70 |
|
108 |
| -public class LiteralSpec: TokenSpec {} |
109 |
| - |
110 |
| -public class MiscSpec: TokenSpec {} |
111 |
| - |
112 | 71 | public let SYNTAX_TOKENS: [TokenSpec] = [
|
113 |
| - PunctuatorSpec(name: "Arrow", text: "->"), |
114 |
| - PunctuatorSpec(name: "AtSign", text: "@"), |
115 |
| - PunctuatorSpec(name: "Backslash", text: "\\"), |
116 |
| - PunctuatorSpec(name: "Backtick", text: "`"), |
117 |
| - MiscSpec(name: "BinaryOperator", nameForDiagnostics: "binary operator"), |
118 |
| - PunctuatorSpec(name: "Colon", text: ":"), |
119 |
| - PunctuatorSpec(name: "Comma", text: ","), |
120 |
| - MiscSpec(name: "DollarIdentifier", nameForDiagnostics: "dollar identifier"), |
121 |
| - PunctuatorSpec(name: "Ellipsis", text: "..."), |
122 |
| - MiscSpec(name: "EndOfFile", nameForDiagnostics: "end of file", text: ""), |
123 |
| - PunctuatorSpec(name: "Equal", text: "="), |
124 |
| - PunctuatorSpec(name: "ExclamationMark", text: "!"), |
125 |
| - MiscSpec(name: "ExtendedRegexDelimiter", nameForDiagnostics: "extended delimiter"), |
126 |
| - LiteralSpec(name: "FloatingLiteral", nameForDiagnostics: "floating literal"), |
127 |
| - MiscSpec(name: "Identifier", nameForDiagnostics: "identifier"), |
128 |
| - PunctuatorSpec(name: "InfixQuestionMark", text: "?"), |
129 |
| - LiteralSpec(name: "IntegerLiteral", nameForDiagnostics: "integer literal"), |
130 |
| - MiscSpec(name: "Keyword", nameForDiagnostics: "keyword", associatedValueClass: "Keyword"), |
131 |
| - PunctuatorSpec(name: "LeftAngle", text: "<"), |
132 |
| - PunctuatorSpec(name: "LeftBrace", text: "{"), |
133 |
| - PunctuatorSpec(name: "LeftParen", text: "("), |
134 |
| - PunctuatorSpec(name: "LeftSquare", text: "["), |
135 |
| - PunctuatorSpec(name: "MultilineStringQuote", text: "\"\"\""), |
136 |
| - PunctuatorSpec(name: "Period", text: "."), |
137 |
| - MiscSpec(name: "PostfixOperator", nameForDiagnostics: "postfix operator"), |
138 |
| - PunctuatorSpec(name: "PostfixQuestionMark", text: "?"), |
139 |
| - PunctuatorSpec(name: "Pound", text: "#"), |
140 |
| - PoundConfigSpec(name: "PoundAvailable", text: "#available"), |
141 |
| - PoundConditionalDirectiveSpec(name: "PoundElse", text: "#else"), |
142 |
| - PoundConditionalDirectiveSpec(name: "PoundElseif", text: "#elseif"), |
143 |
| - PoundConditionalDirectiveSpec(name: "PoundEndif", text: "#endif"), |
144 |
| - PoundConditionalDirectiveSpec(name: "PoundIf", text: "#if"), |
145 |
| - PoundDirectiveSpec(name: "PoundSourceLocation", text: "#sourceLocation"), |
146 |
| - PoundConfigSpec(name: "PoundUnavailable", text: "#unavailable"), |
147 |
| - PunctuatorSpec(name: "PrefixAmpersand", text: "&"), |
148 |
| - MiscSpec(name: "PrefixOperator", nameForDiagnostics: "prefix operator"), |
149 |
| - MiscSpec(name: "RawStringDelimiter", nameForDiagnostics: "raw string delimiter"), |
150 |
| - MiscSpec(name: "RegexLiteralPattern", nameForDiagnostics: "regex pattern"), |
151 |
| - PunctuatorSpec(name: "RegexSlash", text: "/"), |
152 |
| - PunctuatorSpec(name: "RightAngle", text: ">"), |
153 |
| - PunctuatorSpec(name: "RightBrace", text: "}"), |
154 |
| - PunctuatorSpec(name: "RightParen", text: ")"), |
155 |
| - PunctuatorSpec(name: "RightSquare", text: "]"), |
156 |
| - PunctuatorSpec(name: "Semicolon", text: ";"), |
157 |
| - PunctuatorSpec(name: "SingleQuote", text: "\'"), |
158 |
| - PunctuatorSpec(name: "StringQuote", text: "\""), |
159 |
| - MiscSpec(name: "StringSegment", nameForDiagnostics: "string segment"), |
160 |
| - MiscSpec(name: "Unknown", nameForDiagnostics: "token"), |
161 |
| - MiscSpec(name: "Wildcard", nameForDiagnostics: "wildcard", text: "_"), |
| 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 | + .other(name: "Keyword", nameForDiagnostics: "keyword", associatedValueClass: "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: "_"), |
162 | 121 | ]
|
163 | 122 |
|
164 | 123 | public let SYNTAX_TOKEN_MAP = Dictionary(
|
|
0 commit comments