-
Notifications
You must be signed in to change notification settings - Fork 441
Move gyb file to SwiftSyntaxBuilder cod gen #1109
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
kimdv
merged 1 commit into
swiftlang:main
from
kimdv:kimdv/move-SyntaxExpressibleByStringInterpolationConformances.swift-to-code-gen
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
.../generate-swiftsyntaxbuilder/SyntaxExpressibleByStringInterpolationConformancesFile.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import SwiftSyntax | ||
import SyntaxSupport | ||
import SwiftSyntaxBuilder | ||
import Utils | ||
|
||
let syntaxExpressibleByStringInterpolationConformancesFile = SourceFile { | ||
ImportDecl( | ||
""" | ||
\(raw: generateCopyrightHeader(for: "generate-swiftsyntaxbuilder")) | ||
import SwiftSyntax | ||
""") | ||
ImportDecl("import SwiftParser") | ||
ImportDecl("import SwiftParserDiagnostics") | ||
|
||
ExtensionDecl("extension SyntaxParseable") { | ||
InitializerDecl( | ||
""" | ||
public init(stringInterpolationOrThrow stringInterpolation: SyntaxStringInterpolation) throws { | ||
self = try performParse(source: stringInterpolation.sourceText, parse: { parser in | ||
return Self.parse(from: &parser) | ||
}) | ||
} | ||
""") | ||
} | ||
|
||
for node in SYNTAX_NODES { | ||
if node.parserFunction != nil && node.isBase { | ||
ExtensionDecl("extension \(node.name)Protocol") { | ||
InitializerDecl( | ||
""" | ||
public init(stringInterpolationOrThrow stringInterpolation: SyntaxStringInterpolation) throws { | ||
self = try performParse(source: stringInterpolation.sourceText, parse: { parser in | ||
let node = \(raw: node.name).parse(from: &parser) | ||
guard let result = node.as(Self.self) else { | ||
throw SyntaxStringInterpolationError.producedInvalidNodeType(expectedType: Self.self, actualType: node.kind.syntaxNodeType) | ||
} | ||
return result | ||
}) | ||
} | ||
""") | ||
|
||
} | ||
|
||
ExtensionDecl("extension \(node.name): SyntaxExpressibleByStringInterpolation") { | ||
InitializerDecl( | ||
""" | ||
public init(stringInterpolationOrThrow stringInterpolation: SyntaxStringInterpolation) throws { | ||
self = try performParse(source: stringInterpolation.sourceText, parse: { parser in | ||
return Self.parse(from: &parser) | ||
}) | ||
} | ||
""") | ||
} | ||
} else if node.parserFunction != nil || (node.baseType.baseName != "Syntax" && node.baseType.baseName != "SyntaxCollection") { | ||
ExtensionDecl("extension \(raw: node.name): SyntaxExpressibleByStringInterpolation { }") | ||
} | ||
} | ||
|
||
FunctionDecl( | ||
""" | ||
// TODO: This should be fileprivate, but is currently used in | ||
// `ConvenienceInitializers.swift`. See the corresponding TODO there. | ||
func performParse<SyntaxType: SyntaxProtocol>(source: [UInt8], parse: (inout Parser) throws -> SyntaxType) throws -> SyntaxType { | ||
return try source.withUnsafeBufferPointer { buffer in | ||
var parser = Parser(buffer) | ||
// FIXME: When the parser supports incremental parsing, put the | ||
// interpolatedSyntaxNodes in so we don't have to parse them again. | ||
let result = try parse(&parser) | ||
if result.hasError { | ||
let diagnostics = ParseDiagnosticsGenerator.diagnostics(for: result) | ||
assert(!diagnostics.isEmpty) | ||
throw SyntaxStringInterpolationError.diagnostics(diagnostics, tree: Syntax(result)) | ||
} | ||
return result | ||
} | ||
} | ||
""") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
Sources/SwiftSyntaxBuilder/SyntaxExpressibleByStringInterpolationConformances.swift.gyb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.