@@ -117,20 +117,29 @@ public class Misc: Token { }
117
117
let SYNTAX_TOKENS: [ Token ] = [
118
118
% for token in SYNTAX_TOKENS:
119
119
% class _name = type ( token) . __name__
120
- % text = 'text : " ' + token.text + ' " , ' if token. text else " "
120
+ % parameters = [ " name: \" %s \" " % token. name ]
121
121
% if class_name in [ 'Keyword', 'SwiftKeyword', 'DeclKeyword', 'StmtKeyword', 'ExprKeyword', 'PatternKeyword', 'SilKeyword'] :
122
- ${class_name}(name: " $ { token . name } " , serializationCode: ${ token.serialization_code}, text: " $ { token. text} " ),
122
+ % parameters += [ " serializationCode: %s " % token. serialization_code, " text: \" %s \" " % token. text]
123
123
% elif class _name in [ 'PoundKeyword', 'PoundConfig', 'PoundDirectiveKeyword', 'PoundConditionalDirectiveKeyword'] :
124
- ${class_name}(name: " $ { token . name } " , kind: " $ { token. kind} " , serializationCode: ${ token.serialization_code}, text: " $ { token. text} " ),
124
+ % parameters += [ " kind: \" %s \" " % token. kind, " serializationCode: %s " % token. serialization_code, " text: \" %s \" " % token. text]
125
125
% elif class _name in [ 'Punctuator', 'Misc'] :
126
- ${class_name}(name: " ${ token. name} " , kind: " ${ token. kind} " , serializationCode: ${token.serialization_code}, ${text}requiresLeadingSpace: ${str(token.requires_leading_space).lower()}, requiresTrailingSpace: ${str(token.requires_trailing_space).lower()}),
126
+ % parameters += [ " kind: \" %s \" " % token. kind, " serializationCode: %s " % token. serialization_code]
127
+ % if token. text:
128
+ % parameters += [ " text: \" %s \" " % token. text]
129
+ % end
127
130
% elif class _name == 'Literal':
128
- ${class_name}(name: " ${ token. name} " , kind: " ${ token. kind} " , serializationCode: ${token.serialization_code}),
131
+ % parameters += [ " kind: \" %s \" " % token. kind, " serializationCode: %s " % token. serialization_code]
132
+ % if token. text:
133
+ % parameters += [ " text: \" %s \" " % token. text]
134
+ % end
129
135
% elif class _name == 'PoundObjectLiteral':
130
- ${class_name}(name: " $ { token . name } " , kind: " $ { token. kind} " , serializationCode: ${ token.serialization_code}, ${ text}description: " $ { token. description} " , protocol: " $ { token. protocol} " ),
136
+ % parameters += [ " kind: \" %s \" " % token. kind, " serializationCode: %s " % token. serialization_code, " text: \" %s \" " % token. text , " description: \" %s \" " % token . description , " protocol: \" %s \" " % token. protocol]
131
137
% else:
132
138
% print( " Unknown token `%s` " , ( token. name) , file= sys. stderr)
133
139
% sys . exit( 1 )
134
140
% end
141
+ % parameters += [ " requiresLeadingSpace: true " ] if token. requires_leading_space else [ ]
142
+ % parameters += [ " requiresTrailingSpace: true " ] if token. requires_trailing_space else [ ]
143
+ ${ class_name} ( ${ " , " . join ( parameters) } ) ,
135
144
% end
136
145
]
0 commit comments