From 56f760e5ec2f315d48104ed12fde3ce10fa48b9e Mon Sep 17 00:00:00 2001 From: kitasuke Date: Sun, 12 May 2019 23:11:24 +0900 Subject: [PATCH 1/2] Consolidate StringInterpolationExprSyntax to StringLiteralExprSyntax --- Sources/SwiftSyntax/SyntaxFactory.swift.gyb | 13 +++++++++---- lit_tests/output/print_verify_tree.swift.withkind | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Sources/SwiftSyntax/SyntaxFactory.swift.gyb b/Sources/SwiftSyntax/SyntaxFactory.swift.gyb index b4d32814d06..aa8c7ef7d59 100644 --- a/Sources/SwiftSyntax/SyntaxFactory.swift.gyb +++ b/Sources/SwiftSyntax/SyntaxFactory.swift.gyb @@ -199,10 +199,15 @@ public enum SyntaxFactory { public static func makeStringLiteralExpr(_ text: String, leadingTrivia: Trivia = [], trailingTrivia: Trivia = []) -> StringLiteralExprSyntax { - let literal = makeStringLiteral("\"\(text)\"", - leadingTrivia: leadingTrivia, - trailingTrivia: trailingTrivia) - return makeStringLiteralExpr(stringLiteral: literal) + let string = makeStringSegment(text, + leadingTrivia: leadingTrivia, + trailingTrivia: trailingTrivia) + let segment = makeStringSegment(content: string) + let segments = makeStringLiteralSegments([segment]) + let quote = makeStringQuoteToken() + return makeStringLiteralExpr(openQuote: quote, + segments: segments, + closeQuote: quote) } public static func makeVariableExpr(_ text: String, diff --git a/lit_tests/output/print_verify_tree.swift.withkind b/lit_tests/output/print_verify_tree.swift.withkind index 02d52fb4311..fab3f9c69f1 100644 --- a/lit_tests/output/print_verify_tree.swift.withkind +++ b/lit_tests/output/print_verify_tree.swift.withkind @@ -4,8 +4,8 @@ func foo() { #if swift(>=3.2) - components.append("-b \"\(string[..<string.index(before: string.endIndex)])\"") + components.append("-b \"\(string[..<string.index(before: string.endIndex)])\"") #else - components.append("-b \"\(string.substring(to: string.characters.index(before: string.endIndex)))\"") + components.append("-b \"\(string.substring(to: string.characters.index(before: string.endIndex)))\"") #endif } \ No newline at end of file From 66837202e5bb90fb56850162b1f9da753056d1fa Mon Sep 17 00:00:00 2001 From: kitasuke Date: Mon, 13 May 2019 01:05:35 +0900 Subject: [PATCH 2/2] Pass leading/trailing trivia to open/close quote --- Sources/SwiftSyntax/SyntaxFactory.swift.gyb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftSyntax/SyntaxFactory.swift.gyb b/Sources/SwiftSyntax/SyntaxFactory.swift.gyb index aa8c7ef7d59..23587cf08ad 100644 --- a/Sources/SwiftSyntax/SyntaxFactory.swift.gyb +++ b/Sources/SwiftSyntax/SyntaxFactory.swift.gyb @@ -204,10 +204,11 @@ public enum SyntaxFactory { trailingTrivia: trailingTrivia) let segment = makeStringSegment(content: string) let segments = makeStringLiteralSegments([segment]) - let quote = makeStringQuoteToken() - return makeStringLiteralExpr(openQuote: quote, + let openQuote = makeStringQuoteToken(leadingTrivia: leadingTrivia) + let closeQuote = makeStringQuoteToken(trailingTrivia: trailingTrivia) + return makeStringLiteralExpr(openQuote: openQuote, segments: segments, - closeQuote: quote) + closeQuote: closeQuote) } public static func makeVariableExpr(_ text: String,