lpython
lpython copied to clipboard
Implement ``str.replace()`` and ``str.index()``
Relates to #2356
I also noticed that these methods don't work with constant strings
semantic error: 'str' object has no attribute 'split'
--> test.py:2:7
|
2 | print("1 2 3".split())
| ^^^^^^^^^^^^^^^
and I'm guessing it's because they are not being handled in handle_constant_string_attributes.
- Why can't both constant strings and variable strings be handled by the
_lpython_str_...functions? Because it looks like the methods for constant strings are directly being implemented in C++. - Shall I also add separate implementations for these in
handle_constant_string_attributes?
Yes, I think we handle compile-time string in python_ast_to_asr.cpp and run time string using _lpython_....
What needs to be done to complete this and merge?
Please mark this PR ready for review once it is ready.
I have implemented str.replace() completely (with support for all three parameters) here: https://github.com/lcompilers/lpython/pull/2587