Skip to content

Commit 7971c34

Browse files
committed
Replace string-based token references with Token enum in CodeGeneration
The CodeGeneration module was previously referring to tokens using string-based references like IdentifierToken, which is not idiomatic Swift. To make the code more concise and in line with Swift's best practices, this commit introduces a Token enum in the TokenSpec.swift file. Now, instead of string-based references, the new Token enum contains all the possible token kinds. It also includes a computed property that returns the corresponding TokenSpec for a given token, allowing for more concise and idiomatic references. The code has been refactored to replace all string-based token references with members of the newly introduced Token enum. Associated tests have also been updated to reflect these changes.
1 parent 5a914f9 commit 7971c34

22 files changed

+569
-470
lines changed

CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public let ATTRIBUTE_NODES: [Node] = [
3939
Child(
4040
name: "AtSign",
4141
deprecatedName: "AtSignToken",
42-
kind: .token(choices: [.token(tokenKind: "AtSignToken")]),
42+
kind: .token(choices: [.token(tokenKind: .atSign)]),
4343
documentation: "The `@` sign."
4444
),
4545
Child(
@@ -50,7 +50,7 @@ public let ATTRIBUTE_NODES: [Node] = [
5050
),
5151
Child(
5252
name: "LeftParen",
53-
kind: .token(choices: [.token(tokenKind: "LeftParenToken")]),
53+
kind: .token(choices: [.token(tokenKind: .leftParen)]),
5454
documentation: "If the attribute takes arguments, the opening parenthesis.",
5555
isOptional: true
5656
),
@@ -144,7 +144,7 @@ public let ATTRIBUTE_NODES: [Node] = [
144144
),
145145
Child(
146146
name: "RightParen",
147-
kind: .token(choices: [.token(tokenKind: "RightParenToken")]),
147+
kind: .token(choices: [.token(tokenKind: .rightParen)]),
148148
documentation: "If the attribute takes arguments, the closing parenthesis.",
149149
isOptional: true
150150
),
@@ -166,7 +166,7 @@ public let ATTRIBUTE_NODES: [Node] = [
166166
),
167167
Child(
168168
name: "Colon",
169-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
169+
kind: .token(choices: [.token(tokenKind: .colon)]),
170170
documentation: "The colon separating the label and the value"
171171
),
172172
Child(
@@ -176,7 +176,7 @@ public let ATTRIBUTE_NODES: [Node] = [
176176
),
177177
Child(
178178
name: "Semicolon",
179-
kind: .token(choices: [.token(tokenKind: "SemicolonToken")])
179+
kind: .token(choices: [.token(tokenKind: .semicolon)])
180180
),
181181
]
182182
),
@@ -195,7 +195,7 @@ public let ATTRIBUTE_NODES: [Node] = [
195195
),
196196
Child(
197197
name: "TrailingComma",
198-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
198+
kind: .token(choices: [.token(tokenKind: .comma)]),
199199
documentation: "A trailing comma if the argument is followed by another argument",
200200
isOptional: true
201201
),
@@ -226,7 +226,7 @@ public let ATTRIBUTE_NODES: [Node] = [
226226
),
227227
Child(
228228
name: "Colon",
229-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
229+
kind: .token(choices: [.token(tokenKind: .colon)]),
230230
documentation: "The colon separating \"before\" and the parameter list."
231231
),
232232
Child(
@@ -247,12 +247,12 @@ public let ATTRIBUTE_NODES: [Node] = [
247247
children: [
248248
Child(
249249
name: "ConventionLabel",
250-
kind: .token(choices: [.token(tokenKind: "IdentifierToken")]),
250+
kind: .token(choices: [.token(tokenKind: .identifier)]),
251251
documentation: "The convention label."
252252
),
253253
Child(
254254
name: "Comma",
255-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
255+
kind: .token(choices: [.token(tokenKind: .comma)]),
256256
isOptional: true
257257
),
258258
Child(
@@ -262,7 +262,7 @@ public let ATTRIBUTE_NODES: [Node] = [
262262
),
263263
Child(
264264
name: "Colon",
265-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
265+
kind: .token(choices: [.token(tokenKind: .colon)]),
266266
isOptional: true
267267
),
268268
Child(
@@ -286,11 +286,11 @@ public let ATTRIBUTE_NODES: [Node] = [
286286
),
287287
Child(
288288
name: "Colon",
289-
kind: .token(choices: [.token(tokenKind: "ColonToken")])
289+
kind: .token(choices: [.token(tokenKind: .colon)])
290290
),
291291
Child(
292292
name: "ProtocolName",
293-
kind: .token(choices: [.token(tokenKind: "IdentifierToken")])
293+
kind: .token(choices: [.token(tokenKind: .identifier)])
294294
),
295295
]
296296
),
@@ -315,7 +315,7 @@ public let ATTRIBUTE_NODES: [Node] = [
315315
),
316316
Child(
317317
name: "Colon",
318-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
318+
kind: .token(choices: [.token(tokenKind: .colon)]),
319319
documentation: "The colon separating the \"of\" label and the original declaration name."
320320
),
321321
Child(
@@ -325,7 +325,7 @@ public let ATTRIBUTE_NODES: [Node] = [
325325
),
326326
Child(
327327
name: "Period",
328-
kind: .token(choices: [.token(tokenKind: "PeriodToken")]),
328+
kind: .token(choices: [.token(tokenKind: .period)]),
329329
documentation: "The period separating the original declaration name and the accessor name.",
330330
isOptional: true
331331
),
@@ -338,7 +338,7 @@ public let ATTRIBUTE_NODES: [Node] = [
338338
),
339339
Child(
340340
name: "Comma",
341-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
341+
kind: .token(choices: [.token(tokenKind: .comma)]),
342342
isOptional: true
343343
),
344344
Child(
@@ -372,11 +372,11 @@ public let ATTRIBUTE_NODES: [Node] = [
372372
Child(
373373
name: "Argument",
374374
deprecatedName: "Parameter",
375-
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "IntegerLiteralToken"), .keyword(text: "self")])
375+
kind: .token(choices: [.token(tokenKind: .identifier), .token(tokenKind: .integerLiteral), .keyword(text: "self")])
376376
),
377377
Child(
378378
name: "TrailingComma",
379-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
379+
kind: .token(choices: [.token(tokenKind: .comma)]),
380380
isOptional: true
381381
),
382382
]
@@ -397,7 +397,7 @@ public let ATTRIBUTE_NODES: [Node] = [
397397
),
398398
Child(
399399
name: "Colon",
400-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
400+
kind: .token(choices: [.token(tokenKind: .colon)]),
401401
documentation: "The colon separating \"wrt\" and the parameter list."
402402
),
403403
Child(
@@ -429,7 +429,7 @@ public let ATTRIBUTE_NODES: [Node] = [
429429
children: [
430430
Child(
431431
name: "LeftParen",
432-
kind: .token(choices: [.token(tokenKind: "LeftParenToken")])
432+
kind: .token(choices: [.token(tokenKind: .leftParen)])
433433
),
434434
Child(
435435
name: "Arguments",
@@ -439,7 +439,7 @@ public let ATTRIBUTE_NODES: [Node] = [
439439
),
440440
Child(
441441
name: "RightParen",
442-
kind: .token(choices: [.token(tokenKind: "RightParenToken")])
442+
kind: .token(choices: [.token(tokenKind: .rightParen)])
443443
),
444444
]
445445
),
@@ -464,7 +464,7 @@ public let ATTRIBUTE_NODES: [Node] = [
464464
Child(
465465
name: "KindSpecifierComma",
466466
deprecatedName: "DiffKindComma",
467-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
467+
kind: .token(choices: [.token(tokenKind: .comma)]),
468468
documentation: "The comma following the differentiability kind, if it exists.",
469469
isOptional: true
470470
),
@@ -477,7 +477,7 @@ public let ATTRIBUTE_NODES: [Node] = [
477477
Child(
478478
name: "ArgumentsComma",
479479
deprecatedName: "DiffParamsComma",
480-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
480+
kind: .token(choices: [.token(tokenKind: .comma)]),
481481
documentation: "The comma following the differentiability arguments clause, if it exists.",
482482
isOptional: true
483483
),
@@ -506,15 +506,15 @@ public let ATTRIBUTE_NODES: [Node] = [
506506
),
507507
Child(
508508
name: "Colon",
509-
kind: .token(choices: [.token(tokenKind: "ColonToken")])
509+
kind: .token(choices: [.token(tokenKind: .colon)])
510510
),
511511
Child(
512512
name: "Value",
513513
kind: .nodeChoices(choices: [
514514
Child(
515515
name: "Token",
516516
kind: .token(choices: [
517-
.token(tokenKind: "IdentifierToken"),
517+
.token(tokenKind: .identifier),
518518
.keyword(text: "private"),
519519
.keyword(text: "fileprivate"),
520520
.keyword(text: "internal"),
@@ -530,7 +530,7 @@ public let ATTRIBUTE_NODES: [Node] = [
530530
),
531531
Child(
532532
name: "TrailingComma",
533-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
533+
kind: .token(choices: [.token(tokenKind: .comma)]),
534534
documentation: "A trailing comma if this argument is followed by another one",
535535
isOptional: true
536536
),
@@ -557,7 +557,7 @@ public let ATTRIBUTE_NODES: [Node] = [
557557
),
558558
Child(
559559
name: "Colon",
560-
kind: .token(choices: [.token(tokenKind: "ColonToken")])
560+
kind: .token(choices: [.token(tokenKind: .colon)])
561561
),
562562
Child(
563563
name: "DeclName",
@@ -587,7 +587,7 @@ public let ATTRIBUTE_NODES: [Node] = [
587587
),
588588
Child(
589589
name: "Comma",
590-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
590+
kind: .token(choices: [.token(tokenKind: .comma)]),
591591
isOptional: true
592592
),
593593
Child(
@@ -615,7 +615,7 @@ public let ATTRIBUTE_NODES: [Node] = [
615615
),
616616
Child(
617617
name: "Comma",
618-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
618+
kind: .token(choices: [.token(tokenKind: .comma)]),
619619
documentation: "The comma separating the type and method name"
620620
),
621621
Child(
@@ -647,7 +647,7 @@ public let ATTRIBUTE_NODES: [Node] = [
647647
),
648648
Child(
649649
name: "Colon",
650-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
650+
kind: .token(choices: [.token(tokenKind: .colon)]),
651651
documentation: "The colon separating the label and the value"
652652
),
653653
Child(
@@ -658,7 +658,7 @@ public let ATTRIBUTE_NODES: [Node] = [
658658
),
659659
Child(
660660
name: "TrailingComma",
661-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
661+
kind: .token(choices: [.token(tokenKind: .comma)]),
662662
documentation: "A trailing comma if this argument is followed by another one",
663663
isOptional: true
664664
),
@@ -681,7 +681,7 @@ public let ATTRIBUTE_NODES: [Node] = [
681681
),
682682
Child(
683683
name: "Colon",
684-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
684+
kind: .token(choices: [.token(tokenKind: .colon)]),
685685
isOptional: true
686686
),
687687
]
@@ -709,11 +709,11 @@ public let ATTRIBUTE_NODES: [Node] = [
709709
),
710710
Child(
711711
name: "Comma",
712-
kind: .token(choices: [.token(tokenKind: "CommaToken")])
712+
kind: .token(choices: [.token(tokenKind: .comma)])
713713
),
714714
Child(
715715
name: "Ordinal",
716-
kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]),
716+
kind: .token(choices: [.token(tokenKind: .integerLiteral)]),
717717
documentation: "The ordinal corresponding to the 'some' keyword that introduced this opaque type."
718718
),
719719
]
@@ -731,15 +731,15 @@ public let ATTRIBUTE_NODES: [Node] = [
731731
),
732732
Child(
733733
name: "Colon",
734-
kind: .token(choices: [.token(tokenKind: "ColonToken")])
734+
kind: .token(choices: [.token(tokenKind: .colon)])
735735
),
736736
Child(
737737
name: "ModuleName",
738738
kind: .node(kind: .stringLiteralExpr)
739739
),
740740
Child(
741741
name: "Comma",
742-
kind: .token(choices: [.token(tokenKind: "CommaToken")])
742+
kind: .token(choices: [.token(tokenKind: .comma)])
743743
),
744744
Child(
745745
name: "Platforms",
@@ -773,7 +773,7 @@ public let ATTRIBUTE_NODES: [Node] = [
773773
Child(
774774
name: "Period",
775775
deprecatedName: "Dot",
776-
kind: .token(choices: [.token(tokenKind: "PeriodToken")]),
776+
kind: .token(choices: [.token(tokenKind: .period)]),
777777
isOptional: true
778778
),
779779
Child(
@@ -818,7 +818,7 @@ public let ATTRIBUTE_NODES: [Node] = [
818818
),
819819
Child(
820820
name: "Colon",
821-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
821+
kind: .token(choices: [.token(tokenKind: .colon)]),
822822
documentation: "The colon separating the label and the value"
823823
),
824824
Child(
@@ -830,7 +830,7 @@ public let ATTRIBUTE_NODES: [Node] = [
830830
),
831831
Child(
832832
name: "TrailingComma",
833-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
833+
kind: .token(choices: [.token(tokenKind: .comma)]),
834834
documentation: "A trailing comma if this argument is followed by another one",
835835
isOptional: true
836836
),
@@ -849,7 +849,7 @@ public let ATTRIBUTE_NODES: [Node] = [
849849
),
850850
Child(
851851
name: "Colon",
852-
kind: .token(choices: [.token(tokenKind: "ColonToken")])
852+
kind: .token(choices: [.token(tokenKind: .colon)])
853853
),
854854
Child(
855855
name: "Message",
@@ -870,7 +870,7 @@ public let ATTRIBUTE_NODES: [Node] = [
870870
),
871871
Child(
872872
name: "Colon",
873-
kind: .token(choices: [.token(tokenKind: "ColonToken")])
873+
kind: .token(choices: [.token(tokenKind: .colon)])
874874
),
875875
Child(
876876
name: "Filename",

0 commit comments

Comments
 (0)