lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Implement ``str.replace()`` and ``str.index()``

Open AkshayWarrier opened this issue 2 years ago • 2 comments

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.

  1. 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++.
  2. Shall I also add separate implementations for these in handle_constant_string_attributes?

AkshayWarrier avatar Dec 14 '23 21:12 AkshayWarrier

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.

Thirumalai-Shaktivel avatar Mar 05 '24 12:03 Thirumalai-Shaktivel

I have implemented str.replace() completely (with support for all three parameters) here: https://github.com/lcompilers/lpython/pull/2587

Kishan-Ved avatar Mar 08 '24 11:03 Kishan-Ved