-
Notifications
You must be signed in to change notification settings - Fork 167
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 support for f-strings #2566
base: main
Are you sure you want to change the base?
Conversation
@certik Can you provide me with some feedback on this PR? Are there any things that could be improved? Thanks beforehand. |
To support f-strings I have used re2c conditions. This was the best solution I could come up with to support lexing and parsing of expression enclosed within the string. |
I think I have finally found an efficient/clean solution to handle lexing fstrings and parsing expressions within it. I noticed re2c conditions explode the code size of tokenizer.cpp from ~3000 to ~13000 lines of code. Using multiple blocks is way more efficient and all the tests are also passing. |
Now the following works: a : i32 = 10
b : f64 = 15.5
c : str = "foobar"
print(f"Trying some calculations : {a*2+3}, {b*3.14}, some strings {c*2}") This give the following output:
|
@Shaikh-Ubaid @czgdp1807 Can you please review this PR? |
Thank you very much, @mrdaybird, for this. |
@mrdaybird my apologies that nobody reviewed it yet. @Thirumalai-Shaktivel, @Shaikh-Ubaid would one of you have time to review it please? |
The changes seem considerate. I will give this a thorough look today/tomorrow. |
Support f-strings in lpython, because f-strings are awesome.
Previously, expression enclosed inside the f-strings was not parsed correctly. (Fixes #641 )
TODO:
Maybe for another PR: (this PR is already pretty large to review i think)