Skip to content

Commit 766d039

Browse files
committed
Remove text_choices and model the text choices in token_choices
1 parent b3500cb commit 766d039

File tree

17 files changed

+448
-182
lines changed

17 files changed

+448
-182
lines changed

CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ public let KEYWORDS: [KeywordSpec] = [
9898
KeywordSpec("available"),
9999
KeywordSpec("await"),
100100
KeywordSpec("before"),
101+
KeywordSpec("block"),
101102
KeywordSpec("break", isLexerClassified: true, requiresTrailingSpace: true),
102103
KeywordSpec("case", isLexerClassified: true, requiresTrailingSpace: true),
103104
KeywordSpec("catch", isLexerClassified: true, requiresLeadingSpace: true),
104105
KeywordSpec("class", isLexerClassified: true, requiresTrailingSpace: true),
105106
KeywordSpec("continue", isLexerClassified: true, requiresTrailingSpace: true),
106107
KeywordSpec("convenience"),
107108
KeywordSpec("convention"),
109+
KeywordSpec("cType"),
108110
KeywordSpec("default", isLexerClassified: true),
109111
KeywordSpec("defer", isLexerClassified: true, requiresTrailingSpace: true),
110112
KeywordSpec("deinit", isLexerClassified: true, requiresTrailingSpace: true),
@@ -124,6 +126,7 @@ public let KEYWORDS: [KeywordSpec] = [
124126
KeywordSpec("extension", isLexerClassified: true, requiresTrailingSpace: true),
125127
KeywordSpec("fallthrough", isLexerClassified: true, requiresTrailingSpace: true),
126128
KeywordSpec("false", isLexerClassified: true),
129+
KeywordSpec("file"),
127130
KeywordSpec("fileprivate", isLexerClassified: true, requiresTrailingSpace: true),
128131
KeywordSpec("final"),
129132
KeywordSpec("for", isLexerClassified: true, requiresTrailingSpace: true),
@@ -145,7 +148,9 @@ public let KEYWORDS: [KeywordSpec] = [
145148
KeywordSpec("isolated"),
146149
KeywordSpec("kind"),
147150
KeywordSpec("lazy"),
151+
KeywordSpec("left"),
148152
KeywordSpec("let", isLexerClassified: true, requiresTrailingSpace: true),
153+
KeywordSpec("line"),
149154
KeywordSpec("lowerThan"),
150155
KeywordSpec("macro"),
151156
KeywordSpec("message"),

CodeGeneration/Sources/SyntaxSupport/gyb_generated/TypeNodes.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ public let TYPE_NODES: [Node] = [
104104
kind: "Type",
105105
children: [
106106
Child(name: "SomeOrAnySpecifier",
107-
kind: .token(choices: [.keyword(text: "some"), .keyword(text: "any")]),
108-
classification: "Keyword"),
107+
kind: .token(choices: [.keyword(text: "some"), .keyword(text: "any")])),
109108
Child(name: "BaseType",
110109
kind: .node(kind: "Type"))
111110
]),
@@ -127,7 +126,7 @@ public let TYPE_NODES: [Node] = [
127126
Child(name: "Type",
128127
kind: .node(kind: "Type")),
129128
Child(name: "Ampersand",
130-
kind: .token(choices: [.keyword(text: "&")]),
129+
kind: .node(kind: "Token"),
131130
isOptional: true)
132131
]),
133132

CodeGeneration/Sources/SyntaxSupport/gyb_helpers/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ def make_swift_child(child, spaces):
5555
parameter_spaces = 8
5656
parameters = ['name: "%s"' % child.name]
5757

58-
if child.text_choices:
59-
mapped_choices = [f'.keyword(text: "{text}")' for text in child.text_choices]
60-
joined_choices = ', '.join(mapped_choices)
61-
kind = f'.token(choices: [{joined_choices}])'
62-
elif child.token_choices:
58+
if child.token_choices:
6359
mapped_choices = [f'.token(tokenKind: "{choice.name}Token")' for (choice, text) in child.token_choices if text is None]
6460
mapped_choices += [f'.keyword(text: "{text}")' for (choice, text) in child.token_choices if text is not None]
6561
joined_choices = ', '.join(mapped_choices)

Sources/IDEUtils/generated/SyntaxClassification.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ extension SyntaxClassification {
9191
switch (parentKind, indexInParent) {
9292
case (.availabilityVersionRestriction, 1):
9393
return (.keyword, false)
94-
case (.constrainedSugarType, 1):
95-
return (.keyword, false)
9694
case (.declModifier, 1):
9795
return (.attribute, false)
9896
case (.expressionSegment, 5):

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public enum Keyword: UInt8, Hashable {
147147

148148
case before
149149

150+
<<<<<<< HEAD
150151
case `break`
151152

152153
case `case`
@@ -390,6 +391,261 @@ public enum Keyword: UInt8, Hashable {
390391
case wrt
391392

392393
case yield
394+
=======
395+
case block = 61
396+
397+
case `break` = 62
398+
399+
case `case` = 63
400+
401+
case `catch` = 64
402+
403+
case `class` = 65
404+
405+
case `continue` = 66
406+
407+
case convenience = 67
408+
409+
case convention = 68
410+
411+
case cType = 69
412+
413+
case `default` = 70
414+
415+
case `defer` = 71
416+
417+
case `deinit` = 72
418+
419+
case deprecated = 73
420+
421+
case derivative = 74
422+
423+
case didSet = 75
424+
425+
case differentiable = 76
426+
427+
case distributed = 77
428+
429+
case `do` = 78
430+
431+
case dynamic = 79
432+
433+
case each = 80
434+
435+
case `else` = 81
436+
437+
case `enum` = 82
438+
439+
case escaping = 83
440+
441+
case exclusivity = 84
442+
443+
case exported = 85
444+
445+
case `extension` = 86
446+
447+
case `fallthrough` = 87
448+
449+
case `false` = 88
450+
451+
case file = 89
452+
453+
case `fileprivate` = 90
454+
455+
case final = 91
456+
457+
case `for` = 92
458+
459+
case `func` = 93
460+
461+
case get = 94
462+
463+
case `guard` = 95
464+
465+
case higherThan = 96
466+
467+
case `if` = 97
468+
469+
case `import` = 98
470+
471+
case `in` = 99
472+
473+
case indirect = 100
474+
475+
case infix = 101
476+
477+
case `init` = 102
478+
479+
case inline = 103
480+
481+
case `inout` = 104
482+
483+
case `internal` = 105
484+
485+
case introduced = 106
486+
487+
case `is` = 107
488+
489+
case isolated = 108
490+
491+
case kind = 109
492+
493+
case lazy = 110
494+
495+
case left = 111
496+
497+
case `let` = 112
498+
499+
case line = 113
500+
501+
case lowerThan = 114
502+
503+
case macro = 115
504+
505+
case message = 116
506+
507+
case metadata = 117
508+
509+
case module = 118
510+
511+
case mutableAddressWithNativeOwner = 119
512+
513+
case mutableAddressWithOwner = 120
514+
515+
case mutating = 121
516+
517+
case `nil` = 122
518+
519+
case noasync = 123
520+
521+
case noDerivative = 124
522+
523+
case noescape = 125
524+
525+
case nonisolated = 126
526+
527+
case nonmutating = 127
528+
529+
case objc = 128
530+
531+
case obsoleted = 129
532+
533+
case of = 130
534+
535+
case open = 131
536+
537+
case `operator` = 132
538+
539+
case optional = 133
540+
541+
case override = 134
542+
543+
case package = 135
544+
545+
case postfix = 136
546+
547+
case `precedencegroup` = 137
548+
549+
case prefix = 138
550+
551+
case `private` = 139
552+
553+
case `Protocol` = 140
554+
555+
case `protocol` = 141
556+
557+
case `public` = 142
558+
559+
case reasync = 143
560+
561+
case renamed = 144
562+
563+
case `repeat` = 145
564+
565+
case required = 146
566+
567+
case `rethrows` = 147
568+
569+
case `return` = 148
570+
571+
case reverse = 149
572+
573+
case safe = 150
574+
575+
case `self` = 151
576+
577+
case `Self` = 152
578+
579+
case Sendable = 153
580+
581+
case set = 154
582+
583+
case some = 155
584+
585+
case sourceFile = 156
586+
587+
case spi = 157
588+
589+
case spiModule = 158
590+
591+
case `static` = 159
592+
593+
case `struct` = 160
594+
595+
case `subscript` = 161
596+
597+
case `super` = 162
598+
599+
case swift = 163
600+
601+
case `switch` = 164
602+
603+
case target = 165
604+
605+
case `throw` = 166
606+
607+
case `throws` = 167
608+
609+
case transpose = 168
610+
611+
case `true` = 169
612+
613+
case `try` = 170
614+
615+
case `Type` = 171
616+
617+
case `typealias` = 172
618+
619+
case unavailable = 173
620+
621+
case unchecked = 174
622+
623+
case unowned = 175
624+
625+
case unsafe = 176
626+
627+
case unsafeAddress = 177
628+
629+
case unsafeMutableAddress = 178
630+
631+
case `var` = 179
632+
633+
case visibility = 180
634+
635+
case weak = 181
636+
637+
case `where` = 182
638+
639+
case `while` = 183
640+
641+
case willSet = 184
642+
643+
case witness_method = 185
644+
645+
case wrt = 186
646+
647+
case yield = 187
648+
>>>>>>> a7a0ff37 (Remove text_choices and model the text choides in token_choices)
393649

394650
@_spi(RawSyntax) public init?(_ text: SyntaxText) {
395651
switch text.count {
@@ -449,6 +705,8 @@ public enum Keyword: UInt8, Hashable {
449705
self = .`else`
450706
case "enum":
451707
self = .`enum`
708+
case "file":
709+
self = .file
452710
case "func":
453711
self = .`func`
454712
case "init":
@@ -457,6 +715,10 @@ public enum Keyword: UInt8, Hashable {
457715
self = .kind
458716
case "lazy":
459717
self = .lazy
718+
case "left":
719+
self = .left
720+
case "line":
721+
self = .line
460722
case "objc":
461723
self = .objc
462724
case "open":
@@ -490,12 +752,16 @@ public enum Keyword: UInt8, Hashable {
490752
self = .async
491753
case "await":
492754
self = .await
755+
case "block":
756+
self = .block
493757
case "break":
494758
self = .`break`
495759
case "catch":
496760
self = .`catch`
497761
case "class":
498762
self = .`class`
763+
case "cType":
764+
self = .cType
499765
case "defer":
500766
self = .`defer`
501767
case "false":
@@ -999,6 +1265,7 @@ public enum Keyword: UInt8, Hashable {
9991265
/// table is significantly faster. Ideally, we could also get the compiler to
10001266
/// constant-evaluate `Keyword.spi.defaultText` to a `SyntaxText` but I don't
10011267
/// see how that's possible right now.
1268+
<<<<<<< HEAD
10021269
private static let keywordTextLookupTable: [SyntaxText] = [
10031270
"__consuming",
10041271
"__owned",
@@ -1184,6 +1451,9 @@ public enum Keyword: UInt8, Hashable {
11841451
"wrt",
11851452
"yield",
11861453
]
1454+
=======
1455+
private static let keywordTextLookupTable: [SyntaxText] = ["__consuming", "__owned", "__setter_access", "__shared", "_alignment", "_backDeploy", "_borrow", "_cdecl", "_Class", "_compilerInitialized", "_const", "_documentation", "_dynamicReplacement", "_effects", "_expose", "_forward", "_implements", "_linear", "_local", "_modify", "_move", "_NativeClass", "_NativeRefCountedObject", "_noMetadata", "_nonSendable", "_objcImplementation", "_objcRuntimeName", "_opaqueReturnTypeOf", "_optimize", "_originallyDefinedIn", "_PackageDescription", "_private", "_projectedValueProperty", "_read", "_RefCountedObject", "_semantics", "_silgen_name", "_specialize", "_spi", "_spi_available", "_swift_native_objc_runtime_base", "_Trivial", "_TrivialAtMost", "_typeEraser", "_unavailableFromAsync", "_UnknownLayout", "actor", "addressWithNativeOwner", "addressWithOwner", "any", "Any", "as", "assignment", "associatedtype", "associativity", "async", "autoclosure", "availability", "available", "await", "before", "block", "break", "case", "catch", "class", "continue", "convenience", "convention", "cType", "default", "defer", "deinit", "deprecated", "derivative", "didSet", "differentiable", "distributed", "do", "dynamic", "each", "else", "enum", "escaping", "exclusivity", "exported", "extension", "fallthrough", "false", "file", "fileprivate", "final", "for", "func", "get", "guard", "higherThan", "if", "import", "in", "indirect", "infix", "init", "inline", "inout", "internal", "introduced", "is", "isolated", "kind", "lazy", "left", "let", "line", "lowerThan", "macro", "message", "metadata", "module", "mutableAddressWithNativeOwner", "mutableAddressWithOwner", "mutating", "nil", "noasync", "noDerivative", "noescape", "nonisolated", "nonmutating", "objc", "obsoleted", "of", "open", "operator", "optional", "override", "package", "postfix", "precedencegroup", "prefix", "private", "Protocol", "protocol", "public", "reasync", "renamed", "repeat", "required", "rethrows", "return", "reverse", "safe", "self", "Self", "Sendable", "set", "some", "sourceFile", "spi", "spiModule", "static", "struct", "subscript", "super", "swift", "switch", "target", "throw", "throws", "transpose", "true", "try", "Type", "typealias", "unavailable", "unchecked", "unowned", "unsafe", "unsafeAddress", "unsafeMutableAddress", "var", "visibility", "weak", "where", "while", "willSet", "witness_method", "wrt", "yield"]
1456+
>>>>>>> a7a0ff37 (Remove text_choices and model the text choides in token_choices)
11871457

11881458
@_spi(RawSyntax)
11891459
public var defaultText: SyntaxText {

0 commit comments

Comments
 (0)