-
Notifications
You must be signed in to change notification settings - Fork 19
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
Implementing RegEx function in Database Exprs. #14
Comments
What does it do if the compile fails due to an invalid regex? |
It should throw an exception which tells the client what was wrong with the regex. |
Experimenting with the Posix regex library, the library returns an error message on an invalid regex so this should be feasible. |
Thank Dick (: I didn't know that Posix have a Regex library. That would be great! Should I assign the issue to you? Are you going to work on this? |
I will word on this, but I'll be pretty busy until mid-December. Where does an expression get compiled? Would the generated Jx9 code compare one string to the regex and return true or false? |
We should add Regex as a function to Jx9. It should be function that take a string and a Regex pattern, and return true or false. Then we can use it in our queries. |
Aiden, please assign this task to me. |
Yours now (: |
Aidin, it looks like class RegularExpr should be a subclass of Expr and should be allowed in a ConnectiveExpr. Do you agree? Am I correct that the scope of this task is to define a regular expression type in libtocc and not to define an interface for it in cli? |
Yes. The second question is true. But first one is not. Note that, before anything, we need a C function, that we can call from inside of a Jx9 script. Take a look at |
Aidin, it appears that the constructor of RegexExpr will need, as a parameter, a pointer to the Unqlite VM. Is there any problem with this? |
Aidin, I see two possible ways of doing this.
|
Let me see... There's a third way! CompiledRegex* compile_regex(const char* regex);
bool match_regex(CompiledRegex* regex, const char* str_to_match) Then, Jx9 first calls the first function and get a pointer to a compiled regex. Then, for each 20 records, passes the compiled regex to the second function. What do you think? |
If Jx9 calls the first function, where will the Regex that compile_regex compile reside? If is in the stack of of compiled_regex, the pointer might be invalidated by the time match_regex is called. It could be in a static field in compile_regex, but only if no more than one regex will ever be active. I think what we need to do is have compile_regex create the regex on the heap with malloc. We will need a Jx9 function free_regex(CompiledRegex* regex) which will call regfree and then free the memory that was malloced. This will work. I've also thought of another possible way. Have Jx9 function: bool match_regex(const char* compiled_regex_address, const char* str_to_match) where compiled_regex_address is a string representing the address of the regex. When we compile the regex in RegexExpr::RegexExpr, we will convert its to address to a string and then put it in this->protected_data->arg. FunctionExpr::Compile put this string into the first argument of the Jx9 call to match_regex. (This is what happens for will convert the address to a string and put this in the J9X string to call the match_regex. (This will work like FunctionExpr::Compile does for WildCardExpr. The C++ code called by match_regex will receive the string, convert it to the address static regex_t *string_to_regex_pointer(const char *string) static void regex_pointer_to_string(regex_t *regex_pointer, char *string, size_t string_length) What are your thoughts about all this? |
Creative Idea! |
On 01/02/2015 09:30 AM, Aidin Gharibnavaz wrote:
|
How do a add a new file to libtocc/tests, regex_tests.hpp? |
Create a |
I'm having a problem running libtocc/tests/configure. I get the following error: configure: error: Could not find libtocc library. Please make sure you have this library in your libs path. Refer to documentations for more info. I built libtocc and ran "sudo make install" on it successfully so the library should not be missing. |
We can use one of two libraries: regex or pcre. Pcre (Perl Compatible Regular Expressions) uses a format of regular expression compatible with Perl, Python, PHP, Java, and other packages. It seems to be the most commonly used regular expression library. It requires an external library to be linked in, the same way we link in Unqlite. It is available in MS Windows if we ever port TOCC to Windows. Regex is the posix regular expression library. Its format is compatible with egrep and not compatible with PCRE. In Unix-like OS's, no additional library needs to be linked in. Regex is not available for Windows. Which should we use? |
|
Implement a RegEx class which is derived from FunctionExpr in database/expr/
When it compiles, it returns a Jx9 code that calls a C function. The C function will match a string with a RegEx pattern.
The text was updated successfully, but these errors were encountered: