@@ -117,20 +117,22 @@ 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} " ),
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} " ),
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()}),
127
- % elif class_name == 'Literal':
128
- ${class_name}(name: " ${ token. name} " , kind: " ${ token. kind} " , serializationCode: ${token.serialization_code}),
122
+ % parameters += [ " serializationCode: %s " % token. serialization_code, " text: \" %s \" " % token. text]
123
+ % elif class _name in [ 'PoundKeyword', 'PoundConfig', 'PoundDirectiveKeyword', 'PoundConditionalDirectiveKeyword', 'Punctuator', 'Misc', 'Literal'] :
124
+ % parameters += [ " kind: \" %s \" " % token. kind, " serializationCode: %s " % token. serialization_code]
125
+ % if token. text:
126
+ % parameters += [ " text: \" %s \" " % token. text]
127
+ % end
129
128
% elif class _name == 'PoundObjectLiteral':
130
- ${class_name}(name: " $ { token . name } " , kind: " $ { token. kind} " , serializationCode: ${ token.serialization_code}, ${ text}description: " $ { token. description} " , protocol: " $ { token. protocol} " ),
129
+ % parameters += [ " kind: \" %s \" " % token. kind, " serializationCode: %s " % token. serialization_code, " text: \" %s \" " % token. text , " description: \" %s \" " % token . description , " protocol: \" %s \" " % token. protocol]
131
130
% else:
132
131
% print( " Unknown token `%s` " , ( token. name) , file= sys. stderr)
133
132
% sys . exit( 1 )
134
133
% end
134
+ % parameters += [ " requiresLeadingSpace: true " ] if token. requires_leading_space else [ ]
135
+ % parameters += [ " requiresTrailingSpace: true " ] if token. requires_trailing_space else [ ]
136
+ ${ class_name} ( ${ " , " . join ( parameters) } ) ,
135
137
% end
136
138
]
0 commit comments