The parser cache in RAM has now grammar versioning.

This commit is contained in:
Dave Halter
2017-05-26 12:48:59 -04:00
parent f997b91a12
commit dafffdc9b4
4 changed files with 25 additions and 28 deletions

View File

@@ -28,7 +28,7 @@ class Grammar(object):
self._parser = parser
self._tokenizer = tokenizer
self._diff_parser = diff_parser
self._sha256 = hashlib.sha256(text.encode("utf-8")).hexdigest()
self._hashed = hashlib.sha256(text.encode("utf-8")).hexdigest()
def parse(self, code=None, **kwargs):
"""
@@ -77,7 +77,7 @@ class Grammar(object):
# With the current architecture we cannot load from cache if the
# code is given, because we just load from cache if it's not older than
# the latest change (file last modified).
module_node = load_module(self._sha256, path, cache_path=cache_path)
module_node = load_module(self._hashed, path, cache_path=cache_path)
if module_node is not None:
return module_node
@@ -91,7 +91,7 @@ class Grammar(object):
raise TypeError("You have to define a diff parser to be able "
"to use this option.")
try:
module_cache_item = parser_cache[path]
module_cache_item = parser_cache[self._hashed][path]
except KeyError:
pass
else:
@@ -99,7 +99,7 @@ class Grammar(object):
old_lines = module_cache_item.lines
if old_lines == lines:
# TODO remove this line? I think it's not needed. (dave)
save_module(self._sha256, path, module_node, lines, pickling=False,
save_module(self._hashed, path, module_node, lines, pickling=False,
cache_path=cache_path)
return module_node
@@ -107,7 +107,7 @@ class Grammar(object):
old_lines=old_lines,
new_lines=lines
)
save_module(self._sha256, path, new_node, lines, pickling=cache,
save_module(self._hashed, path, new_node, lines, pickling=cache,
cache_path=cache_path)
return new_node
@@ -126,7 +126,7 @@ class Grammar(object):
remove_last_newline(root_node)
if cache or diff_cache:
save_module(self._sha256, path, root_node, lines, pickling=cache,
save_module(self._hashed, path, root_node, lines, pickling=cache,
cache_path=cache_path)
return root_node