Skip to content

Commit b93da38

Browse files
committed
Drop 'Token' and 'Keyword' suffixes from static methods on 'TokenSyntax'
This allows us to unify Tokens.swift in SwiftSyntax and SwiftSyntaxBuilder.
1 parent 0682c85 commit b93da38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+584
-1226
lines changed

Sources/SwiftSyntax/Tokens.swift.gyb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
%{
22
from gyb_syntax_support import *
3+
from gyb_syntax_support.kinds import lowercase_first_word
34
# -*- mode: Swift -*-
45
# Ignore the following admonition it applies to the resulting .swift file only
56
}%
@@ -31,7 +32,7 @@ extension TokenSyntax {
3132
% leading_trivia = '.space' if token.requires_leading_space else '[]'
3233
% trailing_trivia = '.space' if token.requires_trailing_space else '[]'
3334
% if token.is_keyword:
34-
public static func ${token.swift_kind()}(
35+
public static func `${lowercase_first_word(token.name)}`(
3536
leadingTrivia: Trivia? = nil,
3637
trailingTrivia: Trivia? = nil,
3738
presence: SourcePresence = .present
@@ -44,7 +45,7 @@ extension TokenSyntax {
4445
)
4546
}
4647
% elif token.text:
47-
public static func ${token.swift_kind()}Token(
48+
public static func ${token.swift_kind()}(
4849
leadingTrivia: Trivia? = nil,
4950
trailingTrivia: Trivia? = nil,
5051
presence: SourcePresence = .present
@@ -83,4 +84,18 @@ extension TokenSyntax {
8384
presence: presence
8485
)
8586
}
87+
88+
/// The `open` contextual token
89+
public static func open(
90+
leadingTrivia: Trivia? = nil,
91+
trailingTrivia: Trivia? = nil,
92+
presence: SourcePresence = .present
93+
) -> TokenSyntax {
94+
return TokenSyntax(
95+
.contextualKeyword("open"),
96+
leadingTrivia: leadingTrivia ?? defaultTrivia(presence: presence, trivia: ${leading_trivia}),
97+
trailingTrivia: trailingTrivia ?? defaultTrivia(presence: presence, trivia: ${trailing_trivia}),
98+
presence: presence
99+
)
100+
}
86101
}

0 commit comments

Comments
 (0)