Skip to content

Commit ab11ead

Browse files
authored
Merge pull request #1377 from MegaIng/patch-5
Use MAXWIDTH instead of MAXREPEAT when available
2 parents 942366b + b31ef8f commit ab11ead

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lark/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ def get_regexp_width(expr: str) -> Union[Tuple[int, int], List[int]]:
149149
# sre_parse does not support the new features in regex. To not completely fail in that case,
150150
# we manually test for the most important info (whether the empty string is matched)
151151
c = regex.compile(regexp_final)
152+
# Python 3.11.7 introducded sre_parse.MAXWIDTH that is used instead of MAXREPEAT
153+
# See lark-parser/lark#1376 and python/cpython#109859
154+
MAXWIDTH = getattr(sre_parse, "MAXWIDTH", sre_constants.MAXREPEAT)
152155
if c.match('') is None:
153156
# MAXREPEAT is a none pickable subclass of int, therefore needs to be converted to enable caching
154-
return 1, int(sre_constants.MAXREPEAT)
157+
return 1, int(MAXWIDTH)
155158
else:
156-
return 0, int(sre_constants.MAXREPEAT)
159+
return 0, int(MAXWIDTH)
157160

158161
###}
159162

0 commit comments

Comments
 (0)