Skip to content

Commit

Permalink
Use MAXWIDTH instead of MAXREPEAT when available
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaIng authored Dec 7, 2023
1 parent 942366b commit e4dbb4f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,14 @@ def get_regexp_width(expr: str) -> Union[Tuple[int, int], List[int]]:
# sre_parse does not support the new features in regex. To not completely fail in that case,
# we manually test for the most important info (whether the empty string is matched)
c = regex.compile(regexp_final)
# Python 3.11.7 introducded sre_constants.MAXWIDTH that is used instead of MAXREPEAT
# See lark-parser/lark#1376 and python/cpython#109859
MAXWIDTH = getattr(sre_constants, "MAXWIDTH", sre_constants.MAXREPEAT)
if c.match('') is None:
# MAXREPEAT is a none pickable subclass of int, therefore needs to be converted to enable caching
return 1, int(sre_constants.MAXREPEAT)
return 1, int(MAXWIDTH)
else:
return 0, int(sre_constants.MAXREPEAT)
return 0, int(MAXWIDTH)

###}

Expand Down

0 comments on commit e4dbb4f

Please sign in to comment.