Browse Source

Small adjustments to PR

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.11.3
Erez Sh 3 years ago
parent
commit
6b67d5f5cd
3 changed files with 15 additions and 18 deletions
  1. +13
    -16
      lark/lark.py
  2. +1
    -1
      lark/utils.py
  3. +1
    -1
      setup.py

+ 13
- 16
lark/lark.py View File

@@ -23,10 +23,6 @@ try:
import regex
except ImportError:
regex = None
try:
import atomicwrites
except ImportError:
atomicwrites = None


###{standalone
@@ -283,19 +279,20 @@ class Lark(Serialize):
for name in (set(options) - _LOAD_ALLOWED_OPTIONS):
del options[name]
with FS.open(cache_fn, 'rb') as f:
file_md5 = f.readline().rstrip(b'\n')
if file_md5 == cache_md5.encode('utf8') and verify_used_files(pickle.load(f)):
old_options = self.options
try:
self._load(f, **options)
except Exception: # We should probably narrow done which errors we catch here.
logger.exception("Failed to load Lark from cache: %r. We will try to carry on." % cache_fn)
# In theory, the Lark instance might have been messed up by the call to `_load`.
# In practice the only relevant thing that might have been overriden should be `options`
self.options = old_options
else:
old_options = self.options
try:
file_md5 = f.readline().rstrip(b'\n')
cached_used_files = pickle.load(f)
if file_md5 == cache_md5.encode('utf8') and verify_used_files(cached_used_files):
cached_parser_data = pickle.load(f)
self._load(cached_parser_data, **options)
return
except Exception: # We should probably narrow done which errors we catch here.
logger.exception("Failed to load Lark from cache: %r. We will try to carry on." % cache_fn)
# In theory, the Lark instance might have been messed up by the call to `_load`.
# In practice the only relevant thing that might have been overriden should be `options`
self.options = old_options


# Parse the grammar file and compose the grammars


+ 1
- 1
lark/utils.py View File

@@ -294,7 +294,7 @@ class FS:
@staticmethod
def open(name, mode="r", **kwargs):
if atomicwrites and "w" in mode:
return atomicwrites.atomic_write(name, mode=mode, override=True, **kwargs)
return atomicwrites.atomic_write(name, mode=mode, overwrite=True, **kwargs)
else:
return open(name, mode, **kwargs)



+ 1
- 1
setup.py View File

@@ -17,7 +17,7 @@ setup(
extras_require = {
"regex": ["regex"],
"nearley": ["js2py"],
"atomicwrites": ["atomicwrites"],
"atomic_cache": ["atomicwrites"],
},

package_data = {'': ['*.md', '*.lark'], 'lark-stubs': ['*.pyi']},


Loading…
Cancel
Save