Skip to content

Commit

Permalink
gh-106510: Fix DEBUG output for atomic group (GH-106511)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Jul 8, 2023
1 parent ec7180b commit 74ec02e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Lib/re/_parser.py
Expand Up @@ -113,7 +113,6 @@ def __init__(self, state, data=None):
self.width = None

def dump(self, level=0):
nl = True
seqtypes = (tuple, list)
for op, av in self.data:
print(level*" " + str(op), end='')
Expand All @@ -135,6 +134,9 @@ def dump(self, level=0):
if item_no:
print(level*" " + "ELSE")
item_no.dump(level+1)
elif isinstance(av, SubPattern):
print()
av.dump(level+1)
elif isinstance(av, seqtypes):
nl = False
for a in av:
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_re.py
Expand Up @@ -2489,7 +2489,10 @@ def test_debug_flag(self):

def test_atomic_group(self):
self.assertEqual(get_debug_out(r'(?>ab?)'), '''\
ATOMIC_GROUP [(LITERAL, 97), (MAX_REPEAT, (0, 1, [(LITERAL, 98)]))]
ATOMIC_GROUP
LITERAL 97
MAX_REPEAT 0 1
LITERAL 98
0. INFO 4 0b0 1 2 (to 5)
5: ATOMIC_GROUP 11 (to 17)
Expand Down
@@ -0,0 +1 @@
Improve debug output for atomic groups in regular expressions.

0 comments on commit 74ec02e

Please sign in to comment.