12
12
13
13
/// The kind of token a node can contain. Either a token of a specific kind or a
14
14
/// keyword with the given text.
15
- public enum TokenChoice : CustomStringConvertible {
15
+ public enum TokenChoice {
16
16
case keyword( text: String )
17
17
case token( tokenKind: String )
18
18
@@ -23,19 +23,24 @@ public enum TokenChoice: CustomStringConvertible {
23
23
}
24
24
}
25
25
26
- public var description : String {
26
+ public var descriptionAsTokenSpec : String {
27
27
switch self {
28
- case . keyword( text: let string ) :
29
- guard let keyword = KEYWORDS . first ( where: { $0. name == string } ) else {
30
- assertionFailure ( " no such keyword named \( string ) " )
28
+ case . keyword( text: let text ) :
29
+ guard let keyword = KEYWORDS . first ( where: { $0. name == text } ) else {
30
+ assertionFailure ( " no such keyword named \( text ) " )
31
31
return " "
32
32
}
33
33
return " .keyword(. \( keyword. escapedName) ) "
34
- case . token( tokenKind: let string ) :
35
- guard let token = SYNTAX_TOKENS . first ( where: { $0. name == string . components ( separatedBy: " Token " ) . first } ) else {
36
- assertionFailure ( " no such token named \( string ) " )
34
+ case . token( tokenKind: let tokenKind ) :
35
+ guard let token = SYNTAX_TOKENS . first ( where: { $0. name == tokenKind . components ( separatedBy: " Token " ) . first } ) else {
36
+ assertionFailure ( " no such token named \( tokenKind ) " )
37
37
return " "
38
38
}
39
+
40
+ if tokenKind == " KeywordToken " {
41
+ return " TokenSpec(.keyword) "
42
+ }
43
+
39
44
return " . \( token. swiftKind) "
40
45
}
41
46
}
0 commit comments