-
Notifications
You must be signed in to change notification settings - Fork 50
Provide literal pattern for convertible regexes #670
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
Conversation
} | ||
} | ||
|
||
fileprivate struct LiteralPrinter { |
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.
Should this replace printAsCanonical
, or merge them?
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.
This doesn't necessarily need to replace printAsCanonical
, since they work on different things. If we have the AST -> DSL conversion, though, then this should be able to print anything, and we wouldn't need the existing AST printer any more. Not sure if we need the headache of keeping both in sync
Tests/RegexTests/MatchTests.swift
Outdated
@@ -30,7 +44,8 @@ func _firstMatch( | |||
) throws -> (String, [String?])? { | |||
var regex = try Regex(regexStr, syntax: syntax).matchingSemantics(semanticLevel) | |||
let result = try regex.firstMatch(in: input) | |||
|
|||
try _roundTripLiteral(regexStr, syntax: syntax) |
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.
Long term, we'll want to sink this deeper into the library.
For this, I think we'd also want to test parity for parse only tests.
What needs to be done to get this further along? |
dd2235f
to
84a58c2
Compare
00a7c42
to
2d1ba4d
Compare
@swift-ci Please test |
This adds an (SPI) API for converting a `Regex` instance to a regex literal when possible, whether the regex starts as a literal, a run-time-constructed regex, or using the RegexBuilder syntax. The `_literalPattern` is round-trippable, so a regex created from a `_literalPattern` will have that same `_literalPattern`, but it could be different from the original pattern used to create a regex.
This adds another confirmation test, as part of the parse testing. When a parsing test is expected to succeed, and contains supported syntax, this checks that a round-tripped literal pattern maintains its identity.
Add an example of a pattern that is different from, but equivalent to, the original regex.
49e211e
to
e628267
Compare
@swift-ci Please test |
@swift-ci Please test Windows platform |
@swift-ci Please test |
This adds an (SPI) API for converting a `Regex` instance to a regex literal when possible, whether the regex starts as a literal, a run-time-constructed regex, or using the RegexBuilder syntax. The `_literalPattern` is round-trippable, so a regex created from a `_literalPattern` will have that same `_literalPattern`, but it could be different from the original pattern used to create a regex. This adds another confirmation test, as part of the parse testing. When a parsing test is expected to succeed, and contains supported syntax, this checks that a round-tripped literal pattern maintains its identity.
This adds an (SPI) API for converting a `Regex` instance to a regex literal when possible, whether the regex starts as a literal, a run-time-constructed regex, or using the RegexBuilder syntax. The `_literalPattern` is round-trippable, so a regex created from a `_literalPattern` will have that same `_literalPattern`, but it could be different from the original pattern used to create a regex. This adds another confirmation test, as part of the parse testing. When a parsing test is expected to succeed, and contains supported syntax, this checks that a round-tripped literal pattern maintains its identity.
This adds an (SPI) API for converting a
Regex
instance to a regex literal when possible, whether the regex starts as a literal, a run-time-constructed regex, or using the RegexBuilder syntax. The_literalPattern
is round-trippable, so a regex created from a_literalPattern
will have that same_literalPattern
, but it could be different from the original pattern used to create a regex.This is an alternative to #667, in that a library using
Regex
as a dependency could create a composed printable regex type with the required semantics.