-
Notifications
You must be signed in to change notification settings - Fork 441
Remove CanImportExprSyntax and provide API to interpret an ExprSyntax as a VersionTupleSyntax #2025
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
Remove CanImportExprSyntax and provide API to interpret an ExprSyntax as a VersionTupleSyntax #2025
Conversation
Tests/SwiftParserTest/ExpressionInterpretedAsVersionTupleTests.swift
Outdated
Show resolved
Hide resolved
extension ExprSyntax { | ||
public func asVersionTuple(with maxComponentCount: Int) -> VersionTupleSyntax? { | ||
var parser = Parser(self.description) | ||
let raw = parser.parseVersionTuple(maxComponentCount: maxComponentCount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should make sure that all tokens in the ExprSyntax
are represented idk the VersionTupleSyntax
, similar to what we do when creating syntax nodes from string literals
And now that I think about it, I think the best thing to do, would be add a parser entry function for VersionTupleSyntax
so that all that code gets auto-generated, including the following, which is necessary for memory safety
Could you add a test case for 2.0 + 1
. + 1
should be unexpected nodes in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think making this a parser entry function is a good idea! And we have to pass the maxComponentCount
parameter to that function so I add a helper function below.
ea1c73b
to
53101dd
Compare
53101dd
to
2244549
Compare
Tests/SwiftParserTest/ExpressionInterpretedAsVersionTupleTests.swift
Outdated
Show resolved
Hide resolved
3172161
to
ce2f2f2
Compare
731504b
to
b0e01fd
Compare
@swift-ci Please test |
b0e01fd
to
490fe3d
Compare
…ression node To make it easier to interpret the version passed to `canImport(MyModule, _version: <#version#>)`, add `ExprSyntax.interpretedAsVersionTuple` that takes eg. `1.2.3`, which got parsed as a member access `3` to the `1.2` float literal and re-parses it as a `VersionTupleSyntax`. This relaxation also allows string literals as version parameters to `#if canImport`. Fixes swiftlang#1972 rdar://121070235 Co-Authored-By: Ziyang Huang <[email protected]>
490fe3d
to
1382ffb
Compare
Picking this PR up. |
@swift-ci Please test |
Resolves #1972