Skip to content

Commit

Permalink
helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-usielski committed Jan 13, 2025
1 parent ab7ce08 commit 36cb771
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions moler/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ def regexp_without_anchors(regexp):
:param regexp: compiled regexp
:return: compiled regexp without anchors
"""
print(f"passed regexp: '{regexp}'")
regexp_str = regexp.pattern.strip()
org_regexp_str = regexp_str
if len(org_regexp_str) >= 2:
Expand Down Expand Up @@ -654,7 +655,7 @@ def _delete_empty_states(sm: dict) -> None:
del sm[state]


def remove_state_hops_from_sm(source_hops: dict, state_to_remove: str, additional_hops: dict = None) -> dict:
def remove_state_hops_from_sm(source_hops: dict, state_to_remove: str, additional_hops: dict = None, forbidden: dict = None) -> dict:
"""
Remove a state from a state machine dict.
:param source_sm: a dict with state machine description
Expand All @@ -673,7 +674,10 @@ def remove_state_hops_from_sm(source_hops: dict, state_to_remove: str, additiona
if source_hops[state_to_remove][dest_state] == from_state:
msg = f"Found cycle from '{from_state}' to '{dest_state}' via '{source_hops[state_to_remove][dest_state]}'. Please verify state hops: {source_hops}"
raise MolerException(msg)
new_hops[from_state][dest_state] = source_hops[state_to_remove][dest_state]
if not forbidden or from_state not in forbidden or forbidden[from_state] != dest_state:
new_hops[from_state][dest_state] = source_hops[state_to_remove][dest_state]
# if forbidden and dest_state in forbidden and forbidden[dest_state] == new_hops[from_state][dest_state]:
# del new_hops[from_state][dest_state]
else:
del new_hops[from_state][dest_state]

Expand All @@ -686,6 +690,6 @@ def remove_state_hops_from_sm(source_hops: dict, state_to_remove: str, additiona

_delete_empty_states(new_hops)
if additional_hops:
new_hops.update(additional_hops)
update_dict(new_hops, additional_hops)

return new_hops

0 comments on commit 36cb771

Please sign in to comment.