Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,14 @@ def process_advance_block_retry( # noqa: C901
if requirements_satisfied is False:
continue
break
except KeyboardInterrupt as exc:
raise exc from exc
except Exception as exc:
err_msg = traceback.format_exc()
do_retry = (
block.retry
and trial_idx + 1 < trial_total
and "Keyboard Interrupt" not in err_msg
)
do_retry = block.retry and trial_idx + 1 < trial_total
if block.fallback is None and not do_retry:
raise exc from exc
if do_retry:
err_msg = traceback.format_exc()
error = f"An error occurred in a PDL block. Error details: {err_msg}"
print(
f"\n\033[0;31m[Retry {trial_idx+1}/{max_retry}] {error}\033[0m\n",
Expand Down Expand Up @@ -1395,14 +1393,15 @@ def process_blocks( # pylint: disable=too-many-arguments,too-many-positional-ar
saved_background: LazyMessages = DependentContext([])
trace = []
pdl_context_init: LazyMessages = scope.data["pdl_context"]
is_last_of = isinstance(join_type, JoinLastOf)
try:
for i, block in enumerate(blocks):
iteration_state = iteration_state_init.with_iter(i)
scope = scope | {
"pdl_context": DependentContext([pdl_context_init, background])
}
new_loc = append(loc, "[" + str(i) + "]")
if isinstance(join_type, JoinLastOf) and state.yield_result:
if is_last_of and state.yield_result:
iteration_state = state.with_yield_result(i + 1 == len(blocks))
(
iteration_result,
Expand Down
2 changes: 2 additions & 0 deletions src/pdl/pdl_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from functools import lru_cache
from pathlib import Path
from typing import Any, Optional

Expand All @@ -20,6 +21,7 @@ def parse_file(pdl_file: str | Path) -> tuple[Program, PdlLocationType]:
return parse_str(prog_str, file_name=str(pdl_file))


@lru_cache(maxsize=128)
def parse_str(
pdl_str: str, file_name: Optional[str] = None
) -> tuple[Program, PdlLocationType]:
Expand Down
Loading