Skip to content

Commit

Permalink
Add as_text argument in P object to print patterns
Browse files Browse the repository at this point in the history
Adding the 'as_text' parameter to the Pat function in order to print
patterns in a textual format. This can be quite useful for debugging.
  • Loading branch information
Bubobubobubobubo committed Jun 16, 2024
1 parent 3b36295 commit b19877e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions sardine_core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,23 @@ def panic(*runners: AsyncRunner) -> None:
D("superpanic")


def Pat(pattern: str, i: int = 0, div: int = 1, rate: int = 1) -> Any:
def Pat(
pattern: str,
i: int = 0,
div: int = 1,
rate: int = 1,
as_text: bool = False
) -> Any:
"""
General purpose pattern interface. This function can be used to summon the global
parser stored in the fish_bowl. It is generally used to pattern outside of the
handler/sender system, if you are playing with custom libraries, imported code or
if you want to take the best of the patterning system without having to deal with
all the built-in I/O.
The as_text argument allows the study of patterns in textual format. If as_text is
true, the pattern will print from index 0 up to i.
Args:
pattern (str): A pattern to be parsed
i (int, optional): Index for iterators. Defaults to 0.
Expand All @@ -413,7 +422,14 @@ def Pat(pattern: str, i: int = 0, div: int = 1, rate: int = 1) -> Any:
int: The ith element from the resulting pattern
"""
result = bowl.parser.parse(pattern)
return Sender.pattern_element(result, i, div, rate)
if print:
pattern = []
for iterator in range(i):
pattern.append(Sender.pattern_element(result, iterator, div, rate))
print(pattern)
return pattern
else:
return Sender.pattern_element(result, i, div, rate)


class Delay:
Expand Down

0 comments on commit b19877e

Please sign in to comment.