Skip to content

[DRAFT] Printable regex #667

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

Closed
wants to merge 1 commit into from
Closed

Conversation

milseman
Copy link
Member

@milseman milseman commented May 3, 2023

No description provided.

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

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

Looking good!

}

@available(macOS 9999, *) // TODO: 5.9?
public enum RegexSyntax {
Copy link
Member

Choose a reason for hiding this comment

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

This should be one of those enum-wrapping structs, since it definitely isn't a closed set.

let values = try decoder.container(keyedBy: CodingKeys.self)
let str = try values.decode(String.self, forKey: .string)
guard let pre = try PrintableRegex(Regex(str)) else {
throw DecodingError.error
Copy link
Member

Choose a reason for hiding this comment

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

Based on my recent proposal experience, this should probably just be the standard DecodingError.typeMismatch. That gets used when a value doesn't decode into the expected type (e.g. an invalid URL).


@available(macOS 9999, *) // TODO: 5.9?
extension Regex {
public var printable: PrintableRegex<Output>? { .init(self) }
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to kill two birds with one stone and also provide something like this at the same time?

public var stringRepresentation: String? { PrintableRegex(self).text }

@natecook1000
Copy link
Member

Closing in lieu of #670.

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.

2 participants