1212
1313import SwiftSyntax
1414
15+ fileprivate extension OperatorKind {
16+ var keyword : Keyword {
17+ switch self {
18+ case . infix: return . infix
19+ case . prefix: return . prefix
20+ case . postfix: return . postfix
21+ }
22+ }
23+ }
24+
1525extension Operator {
1626 /// Synthesize a syntactic representation of this operator based on its
1727 /// semantic definition.
1828 public func synthesizedSyntax( ) -> OperatorDeclSyntax {
1929 let modifiers = ModifierListSyntax (
20- [ DeclModifierSyntax ( name: . identifier ( " \( kind) " ) ) ]
30+ [ DeclModifierSyntax ( name: . keyword ( kind. keyword ) ) ]
2131 )
2232 let operatorKeyword = TokenSyntax . keyword ( . operator, leadingTrivia: . space)
2333 let identifierSyntax =
24- TokenSyntax . identifier ( name, leadingTrivia: . space)
34+ TokenSyntax . binaryOperator ( name, leadingTrivia: . space)
2535 let precedenceGroupSyntax = precedenceGroup. map { groupName in
2636 OperatorPrecedenceAndTypesSyntax (
2737 colon: . colonToken( ) ,
@@ -64,6 +74,16 @@ extension PrecedenceRelation {
6474 }
6575}
6676
77+ fileprivate extension Associativity {
78+ var keyword : Keyword {
79+ switch self {
80+ case . none: return . none
81+ case . left: return . left
82+ case . right: return . right
83+ }
84+ }
85+ }
86+
6787extension PrecedenceGroup {
6888 /// Synthesize a syntactic representation of this precedence group based on
6989 /// its semantic definition.
@@ -83,12 +103,12 @@ extension PrecedenceGroup {
83103 . init(
84104 PrecedenceGroupAssociativitySyntax (
85105 associativityKeyword:
86- . identifier (
87- " associativity " ,
106+ . keyword (
107+ . associativity,
88108 leadingTrivia: [ . newlines( 1 ) , . spaces( indentation) ]
89109 ) ,
90110 colon: . colonToken( ) ,
91- value: . identifier ( " \( associativity) " , leadingTrivia: . space)
111+ value: . keyword ( associativity. keyword , leadingTrivia: . space)
92112 )
93113 )
94114 )
@@ -103,8 +123,8 @@ extension PrecedenceGroup {
103123 . init(
104124 PrecedenceGroupAssignmentSyntax (
105125 assignmentKeyword:
106- . identifier (
107- " assignment " ,
126+ . keyword (
127+ . assignment,
108128 leadingTrivia: [ . newlines( 1 ) , . spaces( indentation) ]
109129 ) ,
110130 colon: . colonToken( ) ,
0 commit comments