**__
) -> list[tuple[str, str]]:
candidates = [
- (_SEP_2.join((index_str, _TOK_IDX_REPEAT, sub_index_str)),
- line)
+ [_SEP_2.join((index_str, _TOK_IDX_REPEAT, sub_index_str)),
+ line]
for sub_index_str, line in fragments[insert_args[0]]]
- if len(insert_args) == 1:
- return candidates
- idx_in, idx_out = ((int(val) if val else None)
- for val in insert_args[1].split(_SEP_2))
- candidates = candidates[idx_in:idx_out]
- n_bump = int(insert_args[2]) if len(insert_args) > 2 else None
- if n_bump is None:
- return candidates
- to_bump = []
- start_offset: Optional[int] = None
- for candidate in candidates:
- cmd_name, remains = candidate[1].split(_SEP_0, maxsplit=1)
- cmd_args_idx = _SIGNATURE_FOR_CMD[cmd_name][1]
- cmd_args: list[str | tuple[int, ...]]
- cmd_args = list(self._args_for_cmd(cmd_name, remains))
- if cmd_args_idx is not None and len(cmd_args) > cmd_args_idx:
- cmd_arg = cmd_args[cmd_args_idx]
- assert isinstance(cmd_arg, str)
- vals = tuple(int(n) for n in cmd_arg.split(_SEP_1) if n)
- if len(vals) > 0:
- start_offset = min(vals if start_offset is None
- else (vals + (start_offset,)))
- cmd_args[cmd_args_idx] = vals
- to_bump += [(candidate[0], cmd_name, cmd_args)]
- bumped_offset = n_bump - (start_offset or 0)
- inserts = []
- for new_index_str, cmd_name, cmd_args in to_bump:
- to_join = [cmd_name]
- for cmd_arg in cmd_args:
- if isinstance(cmd_arg, str):
- to_join += [cmd_arg]
- else:
- to_join += [
- _SEP_1.join(str(n + bumped_offset) for n in cmd_arg)
- or ',']
- inserts += [(new_index_str, _SEP_0.join(to_join))]
- return inserts
+ if len(insert_args) >= 2:
+ idx_in, idx_out = ((int(val) if val else None)
+ for val in insert_args[1].split(_SEP_2))
+ candidates = candidates[idx_in:idx_out]
+ if len(insert_args) >= 3:
+ n_bump = int(insert_args[2])
+ to_bump = []
+ start_offset: Optional[int] = None
+ for candidate in candidates:
+ cmd_name, remains = candidate[1].split(_SEP_0, maxsplit=1)
+ cmd_args_idx = _SIGNATURE_FOR_CMD[cmd_name][1]
+ cmd_args: list[str | tuple[int, ...]]
+ cmd_args = list(self._args_for_cmd(cmd_name, remains))
+ if cmd_args_idx is not None\
+ and len(cmd_args) > cmd_args_idx:
+ cmd_arg = cmd_args[cmd_args_idx]
+ assert isinstance(cmd_arg, str)
+ vals = tuple(int(n) for n in cmd_arg.split(_SEP_1)
+ if n)
+ if len(vals) > 0:
+ start_offset = min(vals if start_offset is None
+ else (vals + (start_offset,)))
+ cmd_args[cmd_args_idx] = vals
+ to_bump += [(cmd_name, cmd_args)]
+ bumped_offset = n_bump - (start_offset or 0)
+ for idx, candidate in enumerate(candidates):
+ cmd_name, cmd_args = to_bump[idx]
+ to_join = [cmd_name]
+ for cmd_arg in cmd_args:
+ if isinstance(cmd_arg, str):
+ to_join += [cmd_arg]
+ else:
+ to_join += [_SEP_1.join(str(n + bumped_offset)
+ for n in cmd_arg)
+ or ',']
+ candidate[1] = _SEP_0.join(to_join)
+ return [(c[0], c[1]) for c in candidates]
def expand_inserts() -> None:
fragments: dict[str, tuple[tuple[str, str], ...]] = {}