Skip to content

Commit 46815da

Browse files
committed
Omit false parameter values
1 parent 9efbb3f commit 46815da

File tree

2 files changed

+130
-121
lines changed

2 files changed

+130
-121
lines changed

Sources/SwiftSyntaxBuilderGeneration/Tokens.swift.gyb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,29 @@ public class Misc: Token { }
117117
let SYNTAX_TOKENS: [Token] = [
118118
% for token in SYNTAX_TOKENS:
119119
% class_name = type(token).__name__
120-
% text = 'text: "' + token.text + '", ' if token.text else ""
120+
% parameters = ["name: \"%s\"" % token.name]
121121
% 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]
123123
% 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]
125125
% 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
127130
% 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
129135
% 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]
131137
% else:
132138
% print("Unknown token `%s`", (token.name), file=sys.stderr)
133139
% sys.exit(1)
134140
% 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)}),
135144
% end
136145
]

0 commit comments

Comments
 (0)