Skip to content

Adding more f-string features #4827

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

samstrohkorbatt
Copy link
Contributor

Fixed issue #4601 and add more f-string features with tests:

  1. Walrus operator
  2. Nested f-strings
  3. Lambda functions
  4. {{ }}
  5. Nested strings

@samstrohkorbatt
Copy link
Contributor Author

@rzhao271,
Can you review and approve this PR? This fixes the #4601 bug.

@ffiarpg
Copy link

ffiarpg commented Apr 25, 2025

@hediet Would love to see this issue resolved.

@ffiarpg
Copy link

ffiarpg commented May 6, 2025

@rzhao271

Raymond can you please reach out internally to find someone to approve this?

Copy link
Contributor

@aiday-mar aiday-mar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR. I am not the owner of the area, so I have a few questions I wanted to ask you to gain a better understanding of the PR. Thank you.

[/"/, 'string.escape', '@dblStringBody']
],
fStringBody: [
fStringBody3: [
[/[^\\'\{\}]+/, 'string'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have several questions about the PR which I would like to ask to better understand this PR.

How come here on line 262 it's written

[/[^\\'\{\}]+/, 'string']

But on line 273 we have:

		[/[^\\'\{\}]+$/, 'string', '@popall'],
		[/[^\\'\{\}]+/, 'string'],

For the other case? It seems like this code is not the exact duplicate of the other code, as it does not contain the third value '@popall'.

Also would you know what popall here refers to? I am trying to understand.

[/\{f"{1}/, 'string', '@fDblStringBody1'], // for nested f-strings
[/\{[^\}'":!=]+/, 'identifier', '@fStringDetail'],
[/\\./, 'string'],
[/'''/, 'string.escape', '@popall'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added? The equivalent of this does not seem to be present in the fStringBody1 array. What use case does it fix?

[/\{[^\}'":!=]+/, 'identifier', '@fStringDetail'],
[/\\./, 'string'],
[/"""/, 'string.escape', '@popall'],
[/"/, 'string.escape'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we escape on the " and on the """. What use case does it fix? And why does line 298 not have @popall as third value in the array?

[/[!][ars]/, 'string'], // only !a, !r, !s are supported by f-strings: https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals
[/=/, 'string'],
[/=/, 'identifier'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed from string to identifier?

[/=/, 'string'],
[/=/, 'identifier'],
[/'[^\']+'/, 'string'],
[/"[^\""]+"/, 'string'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be instead

/"[^\"]+"/

?

@@ -287,9 +317,13 @@ export const language = <languages.IMonarchLanguage>{
[/\\$/, 'string']
],
fStringDetail: [
[/[:][^}]+/, 'string'],
[/:=[^}]+/, 'identifier'], // walrus operator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me examples of where these would activate? Why are they followed by 'identifier' and not string?

@aiday-mar aiday-mar self-requested a review May 7, 2025 12:23
@khameeteman
Copy link

Looking forward to this fix!

@rdejongeviktor
Copy link

Would love to see this PR merged!

@aiday-mar
Copy link
Contributor

Hi everyone thanks for the comments. I left some questions regarding the PR which I'd like to enquire on before merging the PR. If there is no response, I may close the PR in the future to clean the PR stack.

@aiday-mar aiday-mar added the ~info-needed Issue requires more information from poster (with bot comment) label Jun 5, 2025
@aiday-mar aiday-mar assigned aiday-mar and unassigned hediet Jun 5, 2025
@aiday-mar aiday-mar changed the title Fixing issue #4601 and added more features Adding more f-string features Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes-requested ~info-needed Issue requires more information from poster (with bot comment)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants