Skip to content

Commit 45ee09e

Browse files
committed
Add gyb for Punctuators and Misc tokens
1 parent 48b12a2 commit 45ee09e

File tree

2 files changed

+284
-101
lines changed

2 files changed

+284
-101
lines changed

Sources/SwiftSyntaxBuilder/Tokens.swift.gyb

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,43 @@ enum Tokens {
2727
% for token in SYNTAX_TOKENS:
2828
% if token.is_keyword:
2929
/// The `${token.text}` keyword
30-
static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Keyword().withTrailingTrivia(.spaces(1))
30+
static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Keyword()
31+
% if token.requires_trailing_space:
32+
.withLeadingTrivia(.spaces(1))
33+
% end
34+
% if token.requires_leading_space:
35+
.withTrailingTrivia(.spaces(1))
36+
% end
3137
% end
3238
% end
3339

3440
// MARK: Punctuations and Signs
3541

36-
/// `":"`
37-
static let colon = SyntaxFactory.makeColonToken().withTrailingTrivia(.spaces(1))
38-
39-
/// `" = "`
40-
static let equal = SyntaxFactory.makeEqualToken().withLeadingTrivia(.spaces(1))
41-
.withTrailingTrivia(.spaces(1))
42+
% for token in SYNTAX_TOKENS:
43+
% if token.macro_name() == "PUNCTUATOR":
44+
/// The `${token.text}` keyword
45+
static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Keyword()
46+
% if token.requires_trailing_space:
47+
.withLeadingTrivia(.spaces(1))
48+
% end
49+
% if token.requires_leading_space:
50+
.withTrailingTrivia(.spaces(1))
51+
% end
52+
% end
53+
% end
4254

43-
/// `"{"`
44-
static let leftBrace = SyntaxFactory.makeLeftBraceToken()
55+
// MARK: Punctuations and Signs
4556

46-
/// `"}"`
47-
static let rightBrace = SyntaxFactory.makeRightBraceToken()
57+
% for token in SYNTAX_TOKENS:
58+
% if token.macro_name() == "MISC":
59+
/// The `${token.text}` keyword
60+
static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Keyword()
61+
% if token.requires_trailing_space:
62+
.withLeadingTrivia(.spaces(1))
63+
% end
64+
% if token.requires_leading_space:
65+
.withTrailingTrivia(.spaces(1))
66+
% end
67+
% end
68+
% end
4869
}

0 commit comments

Comments
 (0)