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
Add pattern matching library #192
Conversation
…ct index on find, and correct string on match-str
|
please note that if you're porting mostly from the Lua version, while this one is extremely lighter than what is a fully working regex implementation, this is a pattern matching system, not regex. if you'd instead like something more powerful, I'd suggest porting over LPeg - a commonly used library in Lua that has more advanced features and is, IMO, much more powerful and better than regex (while also having a re mode that lets you use regex-like syntax). |
|
@RyanSquared thanks for your input! Ideally I would like to have a PCRE-compatible library in the long run, but I believe that this is quite good for now. It is small and maintainable, and this is more important than completeness at the moment, since we’re a very small team who maintain and develop Carp nights and weekends. So, while I appreciate that Lua’s pattern system is more simplistic than what you would like to have in the long run, this is by design. |
And I'm perfectly fine with that, but what you're saying is that this is a regex library, and the Lua team has made very strong efforts in the past to point out that this is not regex. It's pattern matching. It's faster. It's more useful. But most importantly, even if it looks like regex, it's not. |
|
You’re right, I should probably rename them to patterns at the moment. Thanks again for your input! |
|
Very exciting! Here's some feedback:
|
69a5eb1
to
dac3bad
Compare
|
Thanks for the review! I think all thos points should now be fixed :) |
|
Epic! |
This PR introduces an initial API for regexes in Carp. It is an adaptation of the Lua regex system (I should probably think about proper attribution before we merge this; thoughts?).
Tests are included.
The following functions were added:
find : (Fn [&String &String] Int): finds the index of a regex inside another stringmatch : (Fn [&String &String] (Array String)): returns the match groups in a matchglobal-match : (Fn [&String &String] (Array (Array String))): returns the match groups of all matchessubstitute : (Fn [&String &String &String Int] String): substitutes a patternntimes. Passing-1will result in substitution of every occurrence of the pattern.matches? : (Fn [&String &String] Bool): will check whether there are any valid matches of the regex in the stringmatch-str : (Fn [&String &String] String): will return the matched stringAll in a few hours worth of work!🎉 (this probably means that it’s buggy)
Cheers