diff --git a/lark/lark.py b/lark/lark.py index f0f3435..ecaa8da 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -163,8 +163,8 @@ class LarkOptions(Serialize): return cls(data) -_LOAD_ALLOWED_OPTIONS = {'postlex', 'transformer', 'use_bytes', 'debug', 'g_regex_flags', 'regex', 'propagate_positions', 'keep_all_tokens', - 'tree_class'} +_LOAD_ALLOWED_OPTIONS = {'postlex', 'transformer', 'use_bytes', 'debug', 'g_regex_flags', + 'regex', 'propagate_positions', 'keep_all_tokens', 'tree_class'} class Lark(Serialize): @@ -234,8 +234,9 @@ class Lark(Serialize): if FS.exists(cache_fn): logger.debug('Loading grammar from cache: %s', cache_fn) - for name in (set(LarkOptions._defaults) - _LOAD_ALLOWED_OPTIONS): - options.pop(name, None) + # Remove options that aren't relevant for loading from cache + for name in (set(options) - _LOAD_ALLOWED_OPTIONS): + del options[name] with FS.open(cache_fn, 'rb') as f: self._load(f, **options) return diff --git a/lark/parser_frontends.py b/lark/parser_frontends.py index 325315e..926603c 100644 --- a/lark/parser_frontends.py +++ b/lark/parser_frontends.py @@ -96,9 +96,9 @@ class WithLexer(_ParserFrontend): terminals = [item for item in memo.values() if isinstance(item, TerminalDef)] inst.lexer_conf.callbacks = _get_lexer_callbacks(options.transformer, terminals) inst.lexer_conf.re_module = regex if options.regex else re - inst.lexer_conf.skip_validation = True inst.lexer_conf.use_bytes = options.use_bytes inst.lexer_conf.g_regex_flags = options.g_regex_flags + inst.lexer_conf.skip_validation = True inst.init_lexer() return inst