Skip to content

Add API to enable or disable bare slash regex parsing #448

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 1 commit into from
May 30, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 23, 2022

Depends on swiftlang/swift#59018


Add a parameter to the SyntaxParser.parse functions to enable or disable bare slash regex parsing.

rdar://93750821

@ahoppen ahoppen requested a review from rintaro May 23, 2022 11:10
@ahoppen
Copy link
Member Author

ahoppen commented May 23, 2022

swiftlang/swift#59018

@swift-ci Please test

Comment on lines +120 to +121
languageVersion: String? = nil,
enableBareSlashRegexLiteral: Bool? = nil,
Copy link
Member

@rintaro rintaro May 24, 2022

Choose a reason for hiding this comment

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

I feel like these should be a Options object. But I'm not sure how the API should look like, for example

// An array of enums
SyntaxParse.parse(
    url,
    options: [.languageVersion("5.6"), .bareSlashRegexLiteral(true)],
    diagnosticHandler: diagnosticHandler)

// Just a "options" object
SyntaxParse.parse(
    url,
    options: SyntaxParseOptions(languageVersion: "5.1", enableBareSlashRegexLiteral: true),
    diagnosticHandler: diagnosticHandler)

The advantage of options object is that you can easily pass around and store the object in the clients, when they want to create options at not exact the call site.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Though it's still only in the pitch phase, it seems like a long-term API for this should build on the ideas from @DougGregor 's future feature strings.

The value passed into SyntaxParser.parse could just be an array of strings denoting the feature names. While that's not as discoverable as strongly-typed arguments, if Swift Package Manager is already planning to use that approach (for the reasons described in that pitch), then the string array would at least be familiar and consistent for users. And it eliminates some potential instability from API users, since SwiftSyntax doesn't need to be updated every time new features are added.

This would also have the advantage of letting SwiftSyntax clients, like swift-format, provide the same -enable-future-feature flag and pass those strings verbatim to SwiftSyntax, instead of each client having to either provide their own flags for each of these features or do their own mapping.

With all that being said, I don't know what the best design for this API should look like now if you want to land it before the future-feature work while still keeping that as the eventual end state.

Copy link
Member

Choose a reason for hiding this comment

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

Alex and I chatted about this and we decided to accept this as is for now until the "language features" proposal is settled.

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Just resolve the conflict :)

Add a parameter to the `SyntaxParser.parse` functions to enable or disable bare slash regex parsing.

rdar://93750821
@ahoppen ahoppen force-pushed the pr/enable-disable-bare-slash branch from e45cdc5 to d538760 Compare May 27, 2022 18:40
@ahoppen
Copy link
Member Author

ahoppen commented May 27, 2022

swiftlang/swift#59018

@swift-ci Please test

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