-
Notifications
You must be signed in to change notification settings - Fork 50
Support text segment boundary anchors #178
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
Support text segment boundary anchors #178
Conversation
This enables the `\y` and `\Y` anchors in regex literals and `Anchor.textSegmentBoundary` in the DSL. Note: This also includes `UnicodeScalar` conformance to `RegexProtocol`, which acts like Unicode scalar literals in regex literals.
@swift-ci Please test Linux platform |
@swift-ci Please test Linux platform |
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.
Quick pass over.
@@ -96,12 +96,16 @@ extension Compiler.ByteCodeGen { | |||
} | |||
|
|||
case .textSegment: | |||
// This we should be able to do! | |||
throw Unsupported(#"\y (text segment)"#) | |||
builder.buildAssert { (input, pos, _) in |
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.
Are these anchors' semantics dependent on options?
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.
Yes, the y{g}
and y{w}
matching options flip the behavior between matching extended grapheme cluster boundaries and word boundaries respectively (with the former being the default). Though it sounds like that's what the TODO
is referencing.
public typealias Match = Substring | ||
|
||
public var regex: Regex<Match> { | ||
.init(ast: atom(.scalar(self))) |
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.
We need to stop constructing ASTs in the DSL. Can you use DSLTree, and if not, let me know what's missing?
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.
Switched this and the other primitives to use DSLTree 👍🏻
@swift-ci Please test Linux platform |
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.
LGTM
@swift-ci please test |
Co-authored-by: Michael Ilseman <michael.ilseman@gmail.com>
Co-authored-by: Michael Ilseman <michael.ilseman@gmail.com>
@swift-ci Please test Linux platform |
@swift-ci Please test Linux platform |
This enables the
\y
and\Y
anchors in regex literals andAnchor.textSegmentBoundary
in the DSL.Note: This also includes
UnicodeScalar
conformance toRegexProtocol
, which acts like Unicode scalar literals in regex literals.