-
Notifications
You must be signed in to change notification settings - Fork 17
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
Regex matching in a rope #23
Comments
I'm open to adding those functionalities; however, I don't think it should be done via the Instead, a better approach could be to add a |
Not gonna lie, when I first saw What you are suggesting with the cursor sounds exactly like the missing piece needed to implement the Cursor trait from the |
Do you want to have a go at it? I might get around to it but can't guarantee when. |
I was going to have a go at it, yeah. However, my Rust is pretty rubbish, so I will need some hand holding. It may also take me a while to work out how Crop internals work. Will open a PR for comments at some point if you haven't done that before then. Thanks again! |
Hi, this isn't an issue but more of an ask for some pointers on how to make finding regex matches in a
crop::Rope
work.I checked out the regex crate but its api seems to be mainly designed around working with
&str
s . They recommended to use the lower levelregex-automata
when:This is what Helix editor is doing for regex search/replace. They have created a regex-cursor lib and in it they also provide an implementation of their
Cursor
trait for use withropey
. From what I can tell, this is used to create a regex Input with theirRopeyCursor
(which impls saidCursor
trait) from aRopeSlice
. I had a look at the implementation and it seems quite straightforward.It takes a chunks iterator (also available in crop) and then just stores internally a reference to the current chunk's bytes and offset, changing them as
advance
andbacktrack
methods are called on the cursor. To advance the cursor, it delegates to the chunk iterator'snext
method, but in order to backtrack the cursor, it calls aprev()
method on ropey's chunk iterator.And this is where I got stuck. I tried to create a similar
CropCursor
in my program which implements theCursor
trait from the regex-cursor crate, but I don't know how to "move backwards" crop's Chunks iterator in a similar way to ropey's one.Internally it delegates to Tree -> Leaves, and from there, I can't tell what is going on without studying crop's code in more detail.
Ropey also has a public method which can return a chunk at a byte offset, which seems to be used in Helix to match a regex on a partial document.
So I was hoping you could shed some light on what would be a sensible approach to implement Regex matching on a Rope. Should I simply
.to_string()
the rope, pass that to aRegex
and call it a day? Or should I pursue this effort of implementing the Cursor trait fromregex-cursor
, in which case how do I go about moving crop's Chunk iterator backwards, and getting a chunk at a byte offset? Or maybe there is another way to do this, which I haven't considered?Either way, thank you for your time and for your work on this library.
The text was updated successfully, but these errors were encountered: