Skip to content

Conversation

@ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 8, 2023

Allow the creation of e.g. an ExtensionDeclSyntax as

let extension = try ExtensionDeclSyntax("extension Foo: Proto {}")

The initializer throws if the string describes a declaration other than an 'extension'. If the string can get parsed as an extension but contains syntax errors, we return a node that contains syntax errors. This matches the behavior of the HasTrailingCodeBlock intializers that take a header + result builder.

Allow the creation of e.g. an `ExtensionDeclSyntax` as

```swift
let extension = try ExtensionDeclSyntax("extension Foo: Proto {}")
```

The initializer throws if the string describes a declaration other than an 'extension'. If the string can get parsed as an extension but contains syntax errors, we return a node that contains syntax errors. This matches the behavior of the `HasTrailingCodeBlock` intializers that take a header + result builder.
@ahoppen ahoppen requested review from bnbarham and rintaro August 8, 2023 20:33
@ahoppen
Copy link
Member Author

ahoppen commented Aug 8, 2023

@swift-ci Please test

Comment on lines +20 to +21
public protocol DeclSyntaxParseable: DeclSyntaxProtocol {}
public extension DeclSyntaxParseable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason init(_ stringInterpolation: SyntaxNodeString) can't be just in extension DeclSyntaxProtocol?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because, for example, AccessorDeclSyntax does not go through parseDecl, it has its own parser entry function. And thus, trying to call parser.parseDecl and casting it to AccessorDeclSyntax wouldn’t work.

@ahoppen ahoppen merged commit 1e8b158 into swiftlang:main Aug 9, 2023
@ahoppen ahoppen deleted the ahoppen/extensiondecl-from-string branch August 9, 2023 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants