Skip to content
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

Support PEP 701: Syntactic formalization of f-strings #6502

Closed
5 tasks done
dhruvmanila opened this issue Aug 11, 2023 · 1 comment · Fixed by #7376
Closed
5 tasks done

Support PEP 701: Syntactic formalization of f-strings #6502

dhruvmanila opened this issue Aug 11, 2023 · 1 comment · Fixed by #7376
Assignees
Labels
core Related to core functionality parser Related to the parser python312 Related to Python 3.12

Comments

@dhruvmanila
Copy link
Member

dhruvmanila commented Aug 11, 2023

PEP 701 formalizes the grammar for f-strings. This will require updates to both the lexer and parser while keeping the AST representation the same.

  • Update the lexer to emit the new tokens (FSTRING_START, FSTRING_MIDDLE, FSTRING_END). This means that f"foo {bar}" wouldn't be emitted as a single String token but rather something like:

     FSTRING_START('f"')
     FSTRING_MIDDLE("foo ")
     LBRACE
     NAME("bar")
     RBRACE
     FSTRING_END('f"')
    
  • Update the parser to account for any grammar changes required to recognize these tokens and parse it into an equivalent AST nodes. There are few things to note here:

    • We can remove the f-string parsing done in the string parser (string.rs)
    • Debug expressions (f"foo {bar = }") preserves whitespaces using the debug_text field. Newlines needs to be preserved as well.
    • Implicit string concatenation
    • SimpleTokenizer changes

The goal is to complete this in the current iteration (August) before the official release of Python 3.12.

Tasks

Reference implementation:

@dhruvmanila dhruvmanila added core Related to core functionality parser Related to the parser labels Aug 11, 2023
@dhruvmanila dhruvmanila self-assigned this Aug 11, 2023
@zanieb zanieb added the python312 Related to Python 3.12 label Aug 24, 2023
@dhruvmanila dhruvmanila changed the title Add support for PEP 701: Syntactic formalization of f-strings Support PEP 701: Syntactic formalization of f-strings Sep 1, 2023
@dhruvmanila
Copy link
Member Author

The way the PRs will be merged is as follows:

  1. All changes will be made in separate pull request for separation in logic and code reviews
  2. All the pull requests will be merged in a new branch dhruv/pep-701
  3. A final pull request will be opened from dhruv/pep-701 to main once changes are done.
  4. Merge 🥳

@dhruvmanila dhruvmanila linked a pull request Sep 15, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to core functionality parser Related to the parser python312 Related to Python 3.12
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants