@@ -17,48 +17,100 @@ import SwiftSyntaxBuilder
17
17
let tokensFile = SourceFile {
18
18
ImportDecl ( importTok: TokenSyntax . import. withLeadingTrivia ( . docLineComment( copyrightHeader) ) , path: " SwiftSyntax " )
19
19
20
- ExtensionDecl ( extendedType: " TokenSyntax " , modifiersBuilder: { TokenSyntax . public. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// Namespace for commonly used tokens with default trivia. " ) +
21
- . newlines( 1 ) ) } , membersBuilder: {
20
+ ExtensionDecl (
21
+ extendedType: " TokenSyntax " ,
22
+ modifiersBuilder: {
23
+ TokenSyntax . public. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// Namespace for commonly used tokens with default trivia. " ) + . newlines( 1 ) )
24
+ } ,
25
+ membersBuilder: {
22
26
for token in SYNTAX_TOKENS {
23
27
if token. isKeyword {
24
- VariableDecl ( letOrVarKeyword: . var,
25
- modifiersBuilder: {
26
- if let text = token. text {
27
- TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The ` \( text) ` keyword " ) + . newlines( 1 ) )
28
- } else {
29
- TokenSyntax . static
30
- }
31
- } ,
32
- bindingsBuilder: {
33
- // We need to use `CodeBlock` here to ensure there is braces around.
28
+ VariableDecl (
29
+ letOrVarKeyword: . var,
30
+ modifiersBuilder: {
31
+ if let text = token. text {
32
+ TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The ` \( text) ` keyword " ) + . newlines( 1 ) )
33
+ } else {
34
+ TokenSyntax . static
35
+ }
36
+ } ,
37
+ bindingsBuilder: {
38
+ // We need to use `CodeBlock` here to ensure there is braces around.
34
39
35
- let accessor = CodeBlock {
36
- FunctionCallExpr ( MemberAccessExpr ( base: " SyntaxFactory " , name: " make \( token. name) Keyword " ) )
40
+ let accessor = CodeBlock {
41
+ FunctionCallExpr ( MemberAccessExpr ( base: " SyntaxFactory " , name: " make \( token. name) Keyword " ) )
37
42
38
- if token. requiresLeadingSpace {
39
- createWithLeadingTriviaCall ( )
40
- }
43
+ if token. requiresLeadingSpace {
44
+ createWithLeadingTriviaCall ( )
45
+ }
41
46
42
- if token. requiresTrailingSpace {
43
- createWithTrailingTriviaCall ( )
47
+ if token. requiresTrailingSpace {
48
+ createWithTrailingTriviaCall ( )
49
+ }
44
50
}
45
- }
46
51
47
- createTokenSyntaxPatternBinding ( " ` \( token. name. withFirstCharacterLowercased) ` " , accessor: accessor)
48
- } )
52
+ createTokenSyntaxPatternBinding ( " ` \( token. name. withFirstCharacterLowercased) ` " , accessor: accessor)
53
+ }
54
+ )
49
55
} else if token. text != nil {
50
- VariableDecl ( letOrVarKeyword: . var,
51
- modifiersBuilder: {
52
- if let text = token. text {
53
- TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The ` \( text) ` token " ) + . newlines( 1 ) )
54
- } else {
55
- TokenSyntax . static
56
+ VariableDecl (
57
+ letOrVarKeyword: . var,
58
+ modifiersBuilder: {
59
+ if let text = token. text {
60
+ TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The ` \( text) ` token " ) + . newlines( 1 ) )
61
+ } else {
62
+ TokenSyntax . static
63
+ }
64
+ } ,
65
+ bindingsBuilder: {
66
+ // We need to use `CodeBlock` here to ensure there is braces around.
67
+ let accessor = CodeBlock {
68
+ FunctionCallExpr ( MemberAccessExpr ( base: " SyntaxFactory " , name: " make \( token. name) Token " ) )
69
+
70
+ if token. requiresLeadingSpace {
71
+ createWithLeadingTriviaCall ( )
72
+ }
73
+
74
+ if token. requiresTrailingSpace {
75
+ createWithTrailingTriviaCall ( )
76
+ }
77
+ }
78
+
79
+ createTokenSyntaxPatternBinding ( " ` \( token. name. withFirstCharacterLowercased) ` " , accessor: accessor)
56
80
}
57
- } ,
58
- bindingsBuilder: {
59
- // We need to use `CodeBlock` here to ensure there is braces around.
60
- let accessor = CodeBlock {
61
- FunctionCallExpr ( MemberAccessExpr ( base: " SyntaxFactory " , name: " make \( token. name) Token " ) )
81
+ )
82
+ } else {
83
+ let signature = FunctionSignature (
84
+ input: ParameterClause (
85
+ parameterList: FunctionParameter (
86
+ attributes: nil ,
87
+ firstName: . wildcard,
88
+ secondName: . identifier( " text " ) ,
89
+ colon: . colon,
90
+ type: " String "
91
+ ) ,
92
+ rightParen: . rightParen. withTrailingTrivia ( . spaces( 1 ) )
93
+ ) ,
94
+ output: " TokenSyntax "
95
+ )
96
+
97
+ FunctionDecl (
98
+ identifier: . identifier( " ` \( token. name. withFirstCharacterLowercased) ` " ) ,
99
+ signature: signature,
100
+ modifiersBuilder: {
101
+ if let text = token. text {
102
+ TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The ` \( text) ` token " ) )
103
+ } else {
104
+ TokenSyntax . static
105
+ }
106
+ } ,
107
+ bodyBuilder: {
108
+ FunctionCallExpr (
109
+ MemberAccessExpr ( base: " SyntaxFactory " , name: " make \( token. name) " ) ,
110
+ argumentListBuilder: {
111
+ TupleExprElement ( expression: IdentifierExpr ( " text " ) )
112
+ }
113
+ )
62
114
63
115
if token. requiresLeadingSpace {
64
116
createWithLeadingTriviaCall ( )
@@ -68,64 +120,46 @@ let tokensFile = SourceFile {
68
120
createWithTrailingTriviaCall ( )
69
121
}
70
122
}
71
-
72
- createTokenSyntaxPatternBinding ( " ` \( token. name. withFirstCharacterLowercased) ` " , accessor: accessor)
73
- } )
74
- } else {
75
- let signature = FunctionSignature ( input: ParameterClause ( parameterList: FunctionParameter ( attributes: nil , firstName: . wildcard, secondName: . identifier( " text " ) , colon: . colon, type: " String " ) , rightParen: . rightParen. withTrailingTrivia ( . spaces( 1 ) ) ) , output: " TokenSyntax " )
76
-
77
- FunctionDecl ( identifier: . identifier( " ` \( token. name. withFirstCharacterLowercased) ` " ) ,
78
- signature: signature,
79
- modifiersBuilder: {
80
- if let text = token. text {
81
- TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The ` \( text) ` token " ) )
82
- } else {
83
- TokenSyntax . static
84
- }
85
- } ,
86
- bodyBuilder: {
87
- FunctionCallExpr ( MemberAccessExpr ( base: " SyntaxFactory " , name: " make \( token. name) " ) , argumentListBuilder: {
88
- TupleExprElement ( expression: IdentifierExpr ( " text " ) )
89
- } )
90
-
91
- if token. requiresLeadingSpace {
92
- createWithLeadingTriviaCall ( )
93
- }
94
-
95
- if token. requiresTrailingSpace {
96
- createWithTrailingTriviaCall ( )
97
- }
98
- } )
123
+ )
99
124
}
100
125
}
101
- VariableDecl ( letOrVarKeyword: . var,
102
- modifiersBuilder: { TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The `eof` token " ) + . newlines( 1 ) ) } ,
103
- bindingsBuilder: {
104
- // We need to use `CodeBlock` here to ensure there is braces around.
105
- let body = CodeBlock {
106
- FunctionCallExpr ( MemberAccessExpr ( base: " SyntaxFactory " , name: " makeToken " ) ,
107
- argumentListBuilder: {
108
- TupleExprElement ( expression: MemberAccessExpr ( name: " eof " ) , trailingComma: . comma)
109
- TupleExprElement ( label: TokenSyntax . identifier ( " presence " ) , colon: . colon, expression: MemberAccessExpr ( name: " present " ) )
110
- } )
111
- }
126
+ VariableDecl (
127
+ letOrVarKeyword: . var,
128
+ modifiersBuilder: { TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The `eof` token " ) + . newlines( 1 ) ) } ,
129
+ bindingsBuilder: {
130
+ // We need to use `CodeBlock` here to ensure there is braces around.
131
+ let body = CodeBlock {
132
+ FunctionCallExpr (
133
+ MemberAccessExpr ( base: " SyntaxFactory " , name: " makeToken " ) ,
134
+ argumentListBuilder: {
135
+ TupleExprElement ( expression: MemberAccessExpr ( name: " eof " ) , trailingComma: . comma)
136
+ TupleExprElement ( label: TokenSyntax . identifier ( " presence " ) , colon: . colon, expression: MemberAccessExpr ( name: " present " ) )
137
+ }
138
+ )
139
+ }
112
140
113
- createTokenSyntaxPatternBinding ( " eof " , accessor: body)
114
- } )
115
- VariableDecl ( letOrVarKeyword: . var,
116
- modifiersBuilder: { TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The `open` contextual token " ) + . newlines( 1 ) ) } ,
117
- bindingsBuilder: {
118
- // We need to use `CodeBlock` here to ensure there is braces around.
119
- let body = CodeBlock {
120
- FunctionCallExpr ( MemberAccessExpr ( base: " SyntaxFactory " , name: " makeContextualKeyword " ) ,
121
- argumentListBuilder: {
122
- TupleExprElement ( expression: StringLiteralExpr ( " open " ) )
123
- } )
124
-
125
- createWithTrailingTriviaCall ( )
141
+ createTokenSyntaxPatternBinding ( " eof " , accessor: body)
126
142
}
143
+ )
144
+ VariableDecl (
145
+ letOrVarKeyword: . var,
146
+ modifiersBuilder: { TokenSyntax . static. withLeadingTrivia ( . newlines( 1 ) + . docLineComment( " /// The `open` contextual token " ) + . newlines( 1 ) ) } ,
147
+ bindingsBuilder: {
148
+ // We need to use `CodeBlock` here to ensure there is braces around.
149
+ let body = CodeBlock {
150
+ FunctionCallExpr (
151
+ MemberAccessExpr ( base: " SyntaxFactory " , name: " makeContextualKeyword " ) ,
152
+ argumentListBuilder: {
153
+ TupleExprElement ( expression: StringLiteralExpr ( " open " ) )
154
+ }
155
+ )
156
+
157
+ createWithTrailingTriviaCall ( )
158
+ }
127
159
128
- createTokenSyntaxPatternBinding ( " open " , accessor: body)
129
- } )
130
- } )
160
+ createTokenSyntaxPatternBinding ( " open " , accessor: body)
161
+ }
162
+ )
163
+ }
164
+ )
131
165
}
0 commit comments