Skip to content

Move Token helpers to TokenSyntax extension #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SwiftSyntax

extension BooleanLiteralExpr {
public init(_ value: Bool) {
self.init(booleanLiteral: value ? Tokens.true : Tokens.false)
self.init(booleanLiteral: value ? .true : .false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ extension ${node.syntax_kind} {
% end
% elif token and not token.text:
% if child.is_optional:
% init_parameters.append("%s: %s.map(Tokens.%s)" % (child.swift_name, child.swift_name, lowercase_first_word(token.name)))
% init_parameters.append("%s: %s.map(TokenSyntax.%s)" % (child.swift_name, child.swift_name, lowercase_first_word(token.name)))
% else:
% init_parameters.append("%s: Tokens.%s(%s)" % (child.swift_name, lowercase_first_word(token.name), child.swift_name))
% init_parameters.append("%s: TokenSyntax.%s(%s)" % (child.swift_name, lowercase_first_word(token.name), child.swift_name))
% end
% else:
% init_parameters.append("%s: %s" % (child.swift_name, child.swift_name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ extension StringLiteralExpr {
let segment = StringSegment(content: content)
let segments = StringLiteralSegments([segment])

self.init(openQuote: Tokens.stringQuote,
self.init(openQuote: .stringQuote,
segments: segments,
closeQuote: Tokens.stringQuote)
closeQuote: .stringQuote)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftSyntaxBuilder/Tokens.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import SwiftSyntax

/// Namespace for commonly used tokens with default trivia.
public enum Tokens {
public extension TokenSyntax {
% for token in SYNTAX_TOKENS:
% if token.is_keyword:
/// The `${token.text.encode('utf-8').decode('unicode_escape')}` keyword
public static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Keyword()
static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Keyword()
% if token.requires_leading_space:
.withLeadingTrivia(.spaces(1))
% end
Expand All @@ -34,15 +34,15 @@ public enum Tokens {
% end
% elif token.text:
/// The `${token.text.encode('utf-8').decode('unicode_escape')}` token
public static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Token()
static let `${lowercase_first_word(token.name)}` = SyntaxFactory.make${token.name}Token()
% if token.requires_leading_space:
.withLeadingTrivia(.spaces(1))
% end
% if token.requires_trailing_space:
.withTrailingTrivia(.spaces(1))
% end
% else:
public static func `${lowercase_first_word(token.name)}`(_ text: String) -> TokenSyntax {
static func `${lowercase_first_word(token.name)}`(_ text: String) -> TokenSyntax {
SyntaxFactory.make${token.name}(text)
% if token.requires_leading_space:
.withLeadingTrivia(.spaces(1))
Expand Down
Loading