Skip to content

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

@dhruvmanila

Description

@dhruvmanila

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:

Metadata

Metadata

Assignees

Labels

coreRelated to core functionalityparserRelated to the parserpython312Related to Python 3.12

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions