Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MAXWIDTH instead of MAXREPEAT when available #1377

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_parse.MAXWIDTH that is used instead of MAXREPEAT
# See lark-parser/lark#1376 and python/cpython#109859
MAXWIDTH = getattr(sre_parse, "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
Loading