def _(expanding: ExpandingStitchRepeat, available: int) \ -> Generator[KnitError, None, None]: yield from _verify_counts(to_fixed_repeat(expanding), available - expanding.to_last.value) n = (available - expanding.to_last.value) // expanding.consumes yield from _exactly(n * expanding.consumes, available - expanding.to_last.value, expanding)
def _(pattern: Pattern, available: Optional[int] = None) -> Node: counted = infer_counts(to_fixed_repeat(pattern), available) assert isinstance(counted, RowRepeat) return replace(pattern, rows=counted.rows, consumes=counted.consumes, produces=counted.produces)
def _(row: Row, available: Optional[int] = None) -> Node: counted = infer_counts(to_fixed_repeat(row), available) assert isinstance(counted, FixedStitchRepeat) return replace(row, stitches=counted.stitches, consumes=counted.consumes, produces=counted.produces)
def _(row: Row, before: int) -> Node: fixed = _reverse(to_fixed_repeat(row), before) assert isinstance(fixed, FixedStitchRepeat) assert fixed.consumes == row.consumes assert fixed.produces == row.produces return replace(row, stitches=fixed.stitches, side=row.side.flip() if row.side else None)
def _(rep: ExpandingStitchRepeat, available: Optional[int] = None) -> Node: if available is None: raise InterpretError("ambiguous use of expanding stitch repeat", rep) fixed = infer_counts(to_fixed_repeat(rep), available - rep.to_last.value) assert isinstance(fixed, FixedStitchRepeat) n = (available - rep.to_last.value) // fixed.consumes return replace(rep, stitches=fixed.stitches, consumes=fixed.consumes * n, produces=fixed.produces * n)
def _(pattern: Pattern) -> Generator[KnitError, None, None]: return _verify_make(to_fixed_repeat(pattern))
def _(pattern: Pattern) -> str: return export_text(to_fixed_repeat(pattern))
def _(rep: ExpandingStitchRepeat) -> str: stitches = export_text(to_fixed_repeat(rep)) if rep.to_last.value == 0: return f"*{stitches}; rep from * to end" else: return f"*{stitches}; rep from * to last {rep.to_last.value}"
def _(pattern: Pattern) -> Node: rolled = _roll_repeated_rows(to_fixed_repeat(pattern)) assert isinstance(rolled, RowRepeat) return replace(pattern, rows=rolled.rows)
def _(row: Row) -> Node: fixed = _combine_stitches(to_fixed_repeat(row)) assert isinstance(fixed, FixedStitchRepeat) assert fixed.consumes == row.consumes assert fixed.produces == row.produces return replace(row, stitches=fixed.stitches)
def _(pattern: Pattern, side: Side = Side.Right) -> Node: rep = _alternate_sides(to_fixed_repeat(pattern), side) assert isinstance(rep, RowRepeat) assert rep.consumes == pattern.consumes assert rep.produces == pattern.produces return replace(pattern, rows=rep.rows)
def _(rep: ExpandingStitchRepeat, before: int) -> Node: fixed = _reverse(to_fixed_repeat(rep), before) assert isinstance(fixed, FixedStitchRepeat) return replace(rep, stitches=fixed.stitches, to_last=NaturalLit.of(before))
def _(pattern: Pattern, unroll: bool = False) -> Node: flattened = _flatten(to_fixed_repeat(pattern), unroll) assert isinstance(flattened, RowRepeat) assert flattened.consumes == pattern.consumes assert flattened.produces == pattern.produces return replace(pattern, rows=flattened.rows)
def _(row: Row, unroll: bool = False) -> Node: flattened = _flatten(to_fixed_repeat(row), unroll) assert isinstance(flattened, FixedStitchRepeat) assert flattened.consumes == row.consumes assert flattened.produces == row.produces return replace(row, stitches=flattened.stitches)
def _(row: Row, available: int) -> Generator[KnitError, None, None]: yield from _verify_counts(to_fixed_repeat(row), available)
def _(rep: ExpandingStitchRepeat) -> Node: fixed = _combine_stitches(to_fixed_repeat(rep)) assert isinstance(fixed, FixedStitchRepeat) return replace(rep, stitches=fixed.stitches)
def _(pattern: Pattern, available: int) -> Generator[KnitError, None, None]: yield from _verify_counts(to_fixed_repeat(pattern), available)
def _(pattern: Pattern, acc: int = 0) -> int: return count_rows(to_fixed_repeat(pattern), acc)