Skip to content

Commit 08d9a18

Browse files
committed
Omit false parameter values
1 parent 9efbb3f commit 08d9a18

File tree

2 files changed

+126
-124
lines changed

2 files changed

+126
-124
lines changed

Sources/SwiftSyntaxBuilderGeneration/Tokens.swift.gyb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,22 @@ 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}"),
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
129128
% 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]
131130
% else:
132131
% print("Unknown token `%s`", (token.name), file=sys.stderr)
133132
% sys.exit(1)
134133
% 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)}),
135137
% end
136138
]

0 commit comments

Comments
 (0)