mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-98831: Modernize FORMAT_VALUE (#101628)
Generator update: support balanced parentheses and brackets in conditions and size expressions.
This commit is contained in:
parent
aacbdb0c65
commit
b2b85b5db9
5 changed files with 24 additions and 35 deletions
|
@ -263,7 +263,14 @@ class Parser(PLexer):
|
|||
@contextual
|
||||
def expression(self) -> Expression | None:
|
||||
tokens: list[lx.Token] = []
|
||||
while (tkn := self.peek()) and tkn.kind not in (lx.RBRACKET, lx.RPAREN):
|
||||
level = 1
|
||||
while tkn := self.peek():
|
||||
if tkn.kind in (lx.LBRACKET, lx.LPAREN):
|
||||
level += 1
|
||||
elif tkn.kind in (lx.RBRACKET, lx.RPAREN):
|
||||
level -= 1
|
||||
if level == 0:
|
||||
break
|
||||
tokens.append(tkn)
|
||||
self.next()
|
||||
if not tokens:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue