Skip to content

Remove TokenSyntax shorthand static members for SwiftSyntaxBuilder #1231

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
12 changes: 7 additions & 5 deletions CodeGeneration/Sources/Utils/SyntaxBuildableType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ public struct SyntaxBuildableType: Hashable {
public var defaultInitialization: ExprSyntax? {
if isOptional {
return ExprSyntax(NilLiteralExprSyntax())
} else if isToken {
if let token = token, token.text != nil {
return ExprSyntax(MemberAccessExprSyntax(base: "TokenSyntax", name: lowercaseFirstWord(name: token.name).backticked))
} else if tokenKind == "EOFToken" {
return ExprSyntax(MemberAccessExprSyntax(base: "TokenSyntax", name: "eof"))
} else if let token = token {
if token.isKeyword {
return ExprSyntax(".\(raw: token.swiftKind)()")
} else if token.text != nil {
return ExprSyntax(".\(raw: lowercaseFirstWord(name: token.name))Token()")
}
} else if tokenKind == "EOFToken" {
return ExprSyntax(".eof()")
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ struct GenerateSwiftSyntax: ParsableCommand {
TemplateSpec(sourceFile: buildableNodesFile, module: swiftSyntaxBuilderDir, filename: "BuildableNodes.swift"),
TemplateSpec(sourceFile: resultBuildersFile, module: swiftSyntaxBuilderDir, filename: "ResultBuilders.swift"),
TemplateSpec(sourceFile: syntaxExpressibleByStringInterpolationConformancesFile, module: swiftSyntaxBuilderDir, filename: "SyntaxExpressibleByStringInterpolationConformances.swift"),
TemplateSpec(sourceFile: tokenFile, module: swiftSyntaxBuilderDir, filename: "Token.swift"),
]

var errors: [Error] = []
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion Sources/SwiftSyntaxBuilder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ add_swift_host_library(SwiftSyntaxBuilder
generated/BuildableCollectionNodes.swift
generated/BuildableNodes.swift
generated/ResultBuilders.swift
generated/Token.swift
generated/SyntaxExpressibleByStringInterpolationConformances.swift
)

Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ extension AttributeSyntax {
let argumentList = argumentList()
self.init(
attributeName: attributeName,
leftParen: argumentList != nil ? .leftParen : nil,
leftParen: argumentList != nil ? .leftParenToken() : nil,
argument: argumentList.map(AttributeSyntax.Argument.argumentList),
rightParen: argumentList != nil ? .rightParen : nil
rightParen: argumentList != nil ? .rightParenToken() : nil
)
}
}
Expand All @@ -77,8 +77,8 @@ extension DictionaryExprSyntax {
/// A convenience initializer that allows passing in members using a result builder
/// instead of having to wrap them in a `DictionaryElementList`.
public init(
leftSquare: TokenSyntax = .`leftSquareBracket`,
rightSquare: TokenSyntax = .`rightSquareBracket`,
leftSquare: TokenSyntax = .leftSquareBracketToken(),
rightSquare: TokenSyntax = .rightSquareBracketToken(),
@DictionaryElementListBuilder contentBuilder: () -> DictionaryElementListSyntax = { DictionaryElementListSyntax([]) }
) {
let elementList = contentBuilder()
Expand Down Expand Up @@ -154,9 +154,9 @@ extension FunctionCallExprSyntax {
let shouldOmitParens = argumentList.isEmpty && trailingClosure != nil
self.init(
calledExpression: callee,
leftParen: shouldOmitParens ? nil : .leftParen,
leftParen: shouldOmitParens ? nil : .leftParenToken(),
argumentList: argumentList,
rightParen: shouldOmitParens ? nil : .rightParen,
rightParen: shouldOmitParens ? nil : .rightParenToken(),
trailingClosure: trailingClosure,
additionalTrailingClosures: additionalTrailingClosures
)
Expand Down Expand Up @@ -227,7 +227,7 @@ extension MemberAccessExprSyntax {
/// Creates a `MemberAccessExpr` using the provided parameters.
public init(
base: ExprSyntax? = nil,
dot: TokenSyntax = .period,
dot: TokenSyntax = .periodToken(),
name: String,
declNameArguments: DeclNameArgumentsSyntax? = nil
) {
Expand Down Expand Up @@ -312,9 +312,9 @@ extension StringLiteralExprSyntax {
/// the number of `#`s needed to express the string as-is without any escapes.
public init(
openDelimiter: TokenSyntax? = nil,
openQuote: TokenSyntax = .stringQuote,
openQuote: TokenSyntax = .stringQuoteToken(),
content: String,
closeQuote: TokenSyntax = .stringQuote,
closeQuote: TokenSyntax = .stringQuoteToken(),
closeDelimiter: TokenSyntax? = nil
) {
var openDelimiter = openDelimiter
Expand Down
16 changes: 8 additions & 8 deletions Sources/SwiftSyntaxBuilder/Syntax+StringInterpolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ extension Bool: ExpressibleByLiteralSyntax {
extension ArraySlice: ExpressibleByLiteralSyntax where Element: ExpressibleByLiteralSyntax {
public func makeLiteralSyntax() -> ArrayExprSyntax {
ArrayExprSyntax(
leftSquare: .leftSquareBracket,
leftSquare: .leftSquareBracketToken(),
elements: ArrayElementListSyntax {
for elem in self {
ArrayElementSyntax(expression: elem.makeLiteralSyntax())
}
},
rightSquare: .rightSquareBracket
rightSquare: .rightSquareBracketToken()
)
}
}
Expand All @@ -352,24 +352,24 @@ extension Set: ExpressibleByLiteralSyntax where Element: ExpressibleByLiteralSyn
}

return ArrayExprSyntax(
leftSquare: .leftSquareBracket,
leftSquare: .leftSquareBracketToken(),
elements: ArrayElementListSyntax {
for elemSyntax in elemSyntaxes {
ArrayElementSyntax(expression: elemSyntax)
}
},
rightSquare: .rightSquareBracket
rightSquare: .rightSquareBracketToken()
)
}
}

extension KeyValuePairs: ExpressibleByLiteralSyntax where Key: ExpressibleByLiteralSyntax, Value: ExpressibleByLiteralSyntax {
public func makeLiteralSyntax() -> DictionaryExprSyntax {
DictionaryExprSyntax(leftSquare: .leftSquareBracket, rightSquare: .rightSquareBracket) {
DictionaryExprSyntax(leftSquare: .leftSquareBracketToken(), rightSquare: .rightSquareBracketToken()) {
for elem in self {
DictionaryElementSyntax(
keyExpression: elem.key.makeLiteralSyntax(),
colon: .colon,
colon: .colonToken(),
valueExpression: elem.value.makeLiteralSyntax()
)
}
Expand All @@ -386,11 +386,11 @@ extension Dictionary: ExpressibleByLiteralSyntax where Key: ExpressibleByLiteral
$0.key.syntaxTextBytes.lexicographicallyPrecedes($1.key.syntaxTextBytes)
}

return DictionaryExprSyntax(leftSquare: .leftSquareBracket, rightSquare: .rightSquareBracket) {
return DictionaryExprSyntax(leftSquare: .leftSquareBracketToken(), rightSquare: .rightSquareBracketToken()) {
for elemSyntax in elemSyntaxes {
DictionaryElementSyntax(
keyExpression: elemSyntax.key,
colon: .colon,
colon: .colonToken(),
valueExpression: elemSyntax.value
)
}
Expand Down
Loading