Re:CLI tools hidden in the Python standard library
by burntsushi on Thursday June 29, 2023 @09:40AM
(#36520244)
You'll be able to do this soon with the Rust regex crate as well. Well, by using one of its dependencies. Once regex 1.9 is out, you'll be able to do this with regex-automata:
And its output:
A bit more verbose than the Python, but the library is exposing much lower level components. You have to do a little more stitching to get the `Scanner` behavior. But it does everything the Python does: a single scan (using finite automata and not backtracking like Python), skip certain token types and guarantees that the entirety of the haystack is consumed.
[ Parent
| on HN ]
Re:CLI tools hidden in the Python standard library
by fastasucan on Thursday June 29, 2023 @04:34PM
(#36526321)
'A bit more verbose' = 2,5 times as many characters. Not saying its good or bad just saying its a bit more verbose ;)
Re:CLI tools hidden in the Python standard library
by burntsushi on Thursday June 29, 2023 @08:06PM
(#36528652)
Yes, as I said, the APIs exposed in regex-automata give a lot more power. It's an "expert" level crate. You could pretty easily build a scanner-like abstraction and get pretty close to the Python code.
I posted this because a lot of regex engines don't support this type of use case. Or don't support it well without having to give something up.
Re:CLI tools hidden in the Python standard library
by n8henrie on Saturday July 01, 2023 @11:03AM
(#36550871)
Interesting! Not often using either crate, this example looks like something for which I might usually look to nom. Is there a reason I should consider using regex for this use case instead (if neither is a pre-existing dependency)?
Re:CLI tools hidden in the Python standard library
by burntsushi on Sunday July 02, 2023 @03:39PM
(#36564885)
I don't use nom. I've tried using parser combinator libraries in the past but generally don't like them.
That said, I don't usually use regexes for this either. Instead, I just do things by hand.
So I'm probably not the right person to answer your question unfortunately. I just know that more than one person has asked for this style of use case to be supported in the regex crate. :-)