how do I regex_syntax crate for translating two posix descendant regexes syntaxes? #838
-
Say I wanted to reuse the regex_syntax crate for implementing a translator from one regex syntax to another. Since some strategically important types are private and many, how can I make use of those without using a wrapper if no traits are available that make those type's functionalities available? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
Sorry but I don't think there are enough details in your question for me to understand it enough to give an answer. Can you maybe be a bit more concrete? Showing some code tgat you would like to write would be helpful too. |
Beta Was this translation helpful? Give feedback.
-
Also, I noticed that you deleted a comment you made here? Again, why? It contained useful information! This is what I see in my inbox:
So the first thing to note here is that There is even a It's possible you might want the AST visitor though. It will be more complicated, but it will give you a bit more control on how things are translated to another syntax. With the HIR, I suspect it should work just fine, but you might wind up with regexes that do not look like a human wrote them. Now, with all that said, you don't need to use a As for what you said on reddit:
I get that too myself. But there are no stupid questions. The answers might be staring you right in the face in the docs, and indeed, I might give a terse response pointing to the docs. But that doesn't mean you're dumb or I think your dumb. The number of times I've missed something plainly stated in the docs over the years is uncountable. Sometimes you just miss stuff. And other times, the docs aren't as good as they could be. |
Beta Was this translation helpful? Give feedback.
-
It occurred to me to try implementing just an alternative Printer using generics and the available traits, I actually even started on that, therefore I figured deleting it before wasting anyone's time - which I know now it wouldn't be so. Thanks a lot for answering, despite my shortsightedness, because now I know there's actually a confirmed, feasible and easier way, exemplified in I'll try not forgetting that
for the future. In retrospect, it was a little bit of a burnout on my part. Anyways, answers, like you said, right in front of me but missed, somehow, and heck ...sometimes you just miss stuff..., right? Thank you so much @BurntSushi , this discussion's been helpful in more ways than I hoped for. |
Beta Was this translation helpful? Give feedback.
-
@BurntSushi , man! I actually solved it through math, here me out:
Proof: R being a regular expression, it can be so either by being [atomic] or [composite].
Then, after hacking the source code of Neovim and Vim, I've studied the algorithm for their new NFA engine which then occurred to me must be mathematically compatible through Nondeterministic Finite Automata as they're both formal languages. Therefore, after researching Kleene's algorithm and Glushkov's construction algorithm, both are compatible at high-level intermediate representations, aka NFA. Concluding, transforming a Rust's (BurntSushi) regex syntax into HIR and printing it back out as a regular expression bridges the gap between the two syntaxes and that output should be accepted by both machines. I then ran some tests and it is indeed so, even more, Vim would automatically switch engines to accommodate the expression derived from the HIR, explicitly. I'm packaging the solution into an app, furthermore, this all implies, if Neovim devs are interested, they can actually replace(or add an opt out of) the old vimregex engine with Rust's, provided we escape the special symbols or turn the "very magic" option. It's even feasible to replace Vim's "new" NFA engine using the regex_syntax crate and keep the later one as a bridge to keep old plugin from breaking changes. PS: Please forgive any misspelling, my ADHD makes me switch some words and I can't always spot those mistakes. |
Beta Was this translation helpful? Give feedback.
Also, I noticed that you deleted a comment you made here? Again, why? It contained useful information! This is what I see in my inbox:
So the first thing to note here…