Skip to content

Commit bd2e59e

Browse files
committed
Add the ability to specify a callback directly after Spec unpickling
This allows making decisions such as adding more logging or aborting further Spec processing.
1 parent c4ce270 commit bd2e59e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

parsing/automaton.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ def __init__(
311311
logFile: Optional[str] = None,
312312
graphFile: Optional[str] = None,
313313
verbose: bool = False,
314+
unpickleHook: Callable[[Spec, SpecCompatibility], None] | None = None,
314315
) -> None:
315316
"""
316317
modules : Either a single module, or a list of modules, wherein to
@@ -479,7 +480,7 @@ def __init__(
479480
self._nImpure = 0 # Number of LR impurities (does not affect GLR).
480481

481482
# Generate parse tables.
482-
self._prepare(pickleFile, pickleMode, logFile)
483+
self._prepare(pickleFile, pickleMode, logFile, unpickleHook)
483484

484485
def __repr__(self) -> str:
485486
if self._skinny:
@@ -599,12 +600,15 @@ def _prepare(
599600
pickleFile: Optional[str],
600601
pickleMode: PickleMode,
601602
logFile: Optional[str],
603+
unpickleHook: Callable[[Spec, SpecCompatibility], None] | None = None,
602604
) -> None:
603605
"""
604606
Compile the specification into data structures that can be used by
605607
the Parser class for parsing."""
606608
# Check for a compatible pickle.
607609
compat = self._unpickle(pickleFile, pickleMode)
610+
if unpickleHook is not None:
611+
unpickleHook(self, compat)
608612

609613
if self._verbose and compat in ["itemsets", "incompatible"]:
610614
start = time.monotonic()

0 commit comments

Comments
 (0)