Skip to content

Commit

Permalink
Stop relying on the object identity of multiple instantiations of ().
Browse files Browse the repository at this point in the history
I don't think that's guaranteed across Python implementations.
  • Loading branch information
erikrose committed Jul 12, 2014
1 parent a1575e9 commit b98192d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions parsimonious/expressions.py
Expand Up @@ -13,6 +13,9 @@
from parsimonious.utils import StrAndRepr


MARKER = object()


class Expression(StrAndRepr):
"""A thing that can be matched against a piece of text"""

Expand Down Expand Up @@ -82,8 +85,8 @@ def _match(self, text, pos, cache, error):
# horrible idea for rules that need to backtrack internally a lot). (2)
# Age stuff out of the cache somehow. LRU? (3) Cuts.
expr_id = id(self)
node = cache.get((expr_id, pos), ()) # TODO: Change to setdefault to prevent infinite recursion in left-recursive rules.
if node is ():
node = cache.get((expr_id, pos), MARKER) # TODO: Change to setdefault to prevent infinite recursion in left-recursive rules.
if node is MARKER:
node = cache[(expr_id, pos)] = self._uncached_match(text,
pos,
cache,
Expand Down

0 comments on commit b98192d

Please sign in to comment.