summaryrefslogtreecommitdiffstats
path: root/Tools/cases_generator/parser.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2023-02-08 01:35:55 (GMT)
committerGitHub <noreply@github.com>2023-02-08 01:35:55 (GMT)
commitb2b85b5db9cfdb24f966b61757536a898abc3830 (patch)
treeb5f09e352132a15f5e782e75ce6205b3da0552b1 /Tools/cases_generator/parser.py
parentaacbdb0c650492756738b044e6ddf8b72f89a1a2 (diff)
downloadcpython-b2b85b5db9cfdb24f966b61757536a898abc3830.zip
cpython-b2b85b5db9cfdb24f966b61757536a898abc3830.tar.gz
cpython-b2b85b5db9cfdb24f966b61757536a898abc3830.tar.bz2
gh-98831: Modernize FORMAT_VALUE (#101628)
Generator update: support balanced parentheses and brackets in conditions and size expressions.
Diffstat (limited to 'Tools/cases_generator/parser.py')
-rw-r--r--Tools/cases_generator/parser.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Tools/cases_generator/parser.py b/Tools/cases_generator/parser.py
index ced66fa..c7c8d8a 100644
--- a/Tools/cases_generator/parser.py
+++ b/Tools/cases_generator/parser.py
@@ -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: