Przeglądaj źródła

Prevents caching values that are to be provided again next time anyway. (Most notably transformer, since those might not be picklable)

remotes/origin/gm/2021-09-23T00Z/github.com--lark-parser-lark/master
MegaIng 3 lat temu
rodzic
commit
a787ea83d7
3 zmienionych plików z 7 dodań i 5 usunięć
  1. +5
    -3
      lark/lark.py
  2. +1
    -1
      lark/parser_frontends.py
  3. +1
    -1
      tests/test_nearley/nearley

+ 5
- 3
lark/lark.py Wyświetl plik

@@ -3,7 +3,7 @@ import sys, os, pickle, hashlib
import tempfile
from typing import (
TypeVar, Type, List, Dict, Iterator, Callable, Union, Optional,
Tuple, Iterable, IO, Any, TYPE_CHECKING
Tuple, Iterable, IO, Any, TYPE_CHECKING, Collection
)
if TYPE_CHECKING:
from .parsers.lalr_interactive_parser import InteractiveParser
@@ -416,7 +416,7 @@ class Lark(Serialize):
assert cache_md5 is not None
f.write(cache_md5.encode('utf8') + b'\n')
pickle.dump(used_files, f)
self.save(f)
self.save(f, _LOAD_ALLOWED_OPTIONS)

if __doc__:
__doc__ += "\n\n" + LarkOptions.OPTIONS_DOC
@@ -451,12 +451,14 @@ class Lark(Serialize):
parser_conf = ParserConf(self.rules, self._callbacks, self.options.start)
return parser_class(self.lexer_conf, parser_conf, options=self.options)

def save(self, f):
def save(self, f, exclude_options: Collection[str] = ()):
"""Saves the instance into the given file object

Useful for caching and multiprocessing.
"""
data, m = self.memo_serialize([TerminalDef, Rule])
if exclude_options:
data["options"] = {n: v for n, v in data["options"].items() if n not in exclude_options}
pickle.dump({'data': data, 'memo': m}, f, protocol=pickle.HIGHEST_PROTOCOL)

@classmethod


+ 1
- 1
lark/parser_frontends.py Wyświetl plik

@@ -42,7 +42,7 @@ class MakeParsingFrontend:


class ParsingFrontend(Serialize):
__serialize_fields__ = 'lexer_conf', 'parser_conf', 'parser', 'options'
__serialize_fields__ = 'lexer_conf', 'parser_conf', 'parser'

def __init__(self, lexer_conf, parser_conf, options, parser=None):
self.parser_conf = parser_conf


+ 1
- 1
tests/test_nearley/nearley

@@ -1 +1 @@
Subproject commit 326831689826cb1b9a4d21d1ce0d5db9278e9636
Subproject commit a46b37471db486db0f6e1ce6a2934fb238346b44

Ładowanie…
Anuluj
Zapisz