-
Notifications
You must be signed in to change notification settings - Fork 170
Access re
library via CPython interop
#1919
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
Comments
BTW, feel free to use LASR as a test case for CPython interop. It uses |
Once |
Yup! Currently, we are trying to implement @pythoncall(module="b")
def get_email(text: str) -> str:
pass
def test():
text: str = "Hello, my email id is [email protected]. xyz"
print(get_email(text))
test() b.py def get_email(text):
import re
# Regular expression patterns
email_pattern = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b"
# Matching email addresses
email_matches = re.findall(email_pattern, text)
# Return of List type not supported yet, so return a string
return email_matches[0] Output: $ lpython expr2.py --backend c --enable-cpython
[email protected] |
I'll use it as soon as I can in LLVM! |
Actually, I'd like to try it on the C backend. Would you be so kind as to reply here with the exact commands I need to issue at the terminal on a mac to use the C back end? I.e., compile python to C, compile the C, and run the a.out in the published |
One can use it the following way (in the (lp) ubaid@ubaids-MacBook-Pro my_folder % ls
my_main.py my_module.py
(lp) ubaid@ubaids-MacBook-Pro my_folder % cat my_main.py
from lpython import pythoncall
@pythoncall(module = "my_module")
def get_cpython_version() -> str:
pass
def main0():
print("CPython version: ", get_cpython_version())
main0()
(lp) ubaid@ubaids-MacBook-Pro my_folder % cat my_module.py
def get_cpython_version():
import platform
return platform.python_version()
(lp) ubaid@ubaids-MacBook-Pro my_folder % python my_main.py
CPython version: 3.10.2
(lp) ubaid@ubaids-MacBook-Pro my_folder % lpython my_main.py --backend c --enable-cpython
CPython version: 3.10.2 |
Please note that the file |
Sure! LPython does everything for you, you just have to specify the backend. def main0():
x: i32
x = (2+3)*5
print(x)
main0() and run: $ lpython a.py --backend c
25 Generated C file: #include <inttypes.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <lfortran_intrinsics.h>
struct dimension_descriptor
{
int32_t lower_bound, length;
};
// Implementations
void main0()
{
int32_t x;
x = (2 + 3)*5;
printf("%d\n", x);
}
void _lpython_main_program()
{
main0();
}
int main(int argc, char* argv[])
{
_lpython_set_argv(argc, argv);
_lpython_main_program();
return 0;
} This is simple code, @Shaikh-Ubaid has shared a detailed explanation of the usage above. |
Cool, I'm working on |
Yea, I forgot about this. @Shaikh-Ubaid, Let's add this to our TODO, that we have to specify the path to look for the module using the |
Continued from #1919 (comment), if we are using numpy arrays, then we need to pass the option
|
I'm writing a type-checker, LASR, for ASR in python , and porting it to LPython.
I'd like to import
re
. I know it's not practical to compilere
, but I would like to import it to my LPython program (see link above ... calling LPython on it produces many irrelevant errors.)The text was updated successfully, but these errors were encountered: