Skip to content

Commit

Permalink
Memoize get_regexp_width (Issue #413)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Jul 25, 2019
1 parent 0d164bd commit 7add0e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lark/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ class PatternRE(Pattern):
def to_regexp(self):
return self._get_flags(self.value)

_width = None
def _get_width(self):
if self._width is None:
self._width = get_regexp_width(self.to_regexp())
return self._width

@property
def min_width(self):
return get_regexp_width(self.to_regexp())[0]
return self._get_width()[0]
@property
def max_width(self):
return get_regexp_width(self.to_regexp())[1]
return self._get_width()[1]


class TerminalDef(Serialize):
Expand Down

0 comments on commit 7add0e1

Please sign in to comment.