4 ms·
That seems rather trivial, and I'm not sure how you could possibly have any issues with the borrow checker. Just do the first regex search, then escape into a
by devit 5y ago
That seems rather trivial, and I'm not sure how you could possibly have any issues with the borrow checker.
Just do the first regex search, then escape into a String with regex::escape, then build a regex from the String and search with it.
Of course what you are doing is probably wrong since you should use a string matching crate rather than escaping characters and using a regex matching crate.
- ahelwer 5y agoSince it's so trivial, I would be quite happy for you to implement the feature for me! https://github.com/tree-sitter/tree-sitter/issues/982 https://github.com/tree-sitter/tree-sitter/issues/982 Just lol at the idea that you won't run into borrow checker issues when dealing with strings though.
- burntsushi 5y agoSolving that issue isn't trivial. I just read it and I wouldn't know where to begin, probably because I don't understand the requirements. I think what's being called "trivial" is doing a bit of regex searching. It's probably accurate to call that trivial for an experienced Rust programmer, but if you're just beginning, I don't think it's helpful to call anything trivial. I still remember my first exposure to Rust. It was different. It took a bit to grok. But once it clicked, things were much better. As the maintainer of the regex crate, I invite you or anyone to ask for help using regexes. The regex repo has Discussions opened up, so it's appropriate to ask for help, even if they are beginner questions: https://github.com/rust-lang/regex/discussions https://github.com/rust-lang/regex/discussions As usual though, try to provide as many details as you can. Giving the source code you have but can't get to work is a great start, for example.
- estebank 5y agoLooking at their current iteration of the code, the problem is not in the regex crate's API, but rather on them not having the ownership system internalized yet. https://doc.rust-lang.org/rust-by-example/ https://doc.rust-lang.org/rust-by-example/ and https://github.com/rust-lang/rustlings https://github.com/rust-lang/rustlings might be good places to visit to gain that experience, as well as improving the specific diagnostics to be more actionable.
- burntsushi 5y ago> the problem is not in the regex crate's API, but rather on them not having the ownership system internalized yet Yes, I figured that to be the case, but still wanted to say, "Discussions are open for questions, even if they are beginner related, as long as it's related to regex'ing somehow." :-)
- organian 5y agoI'm not the person you replied to, but here's some Playground code I just wrote that might be helpful for you, based on the issue you linked: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c8109722d6d834b358e8577f9fcb9e9e https://play.rust-lang.org/?version=stable&mode=debug&editio...
- iudqnolq 5y agoI wrote code recently to parse a file with regexes and generate rust code from it. It's get-the-job-done code, not super clean, but you might find it useful. https://github.com/danielzfranklin/drm-fourcc-rs/blob/main/build.rs https://github.com/danielzfranklin/drm-fourcc-rs/blob/main/b...
- zRedShift 5y agoMaybe this can help you, I looked at your fork of tree-sitter to figure out what you were trying to do. https://play.rust-lang.org/?version=stable&edition=2018&gist=8b1b41b39f8df6c5b35d500cb19454f7 https://play.rust-lang.org/?version=stable&edition=2018&gist... But what you really want is to get your head around ownership and borrowing, especially when it comes to the scoped RAII that rust has (e.g. freeing a String while a reference to it still exists and is being used would give you the "temporary value dropped while borrowed" error).