knit_script.knit_script_interpreter.expressions.xfer_pass_racking module

Calculates racking for xfers.

This module provides the Xfer_Pass_Racking class, which handles the calculation of racking values for transfer operations in knit script programs. It supports both direct across-bed transfers (zero racking) and offset transfers with specified distances and directions.

class Xfer_Pass_Racking(parser_node, distance_expression=None, direction_expression=None)[source]

Bases: Expression

Structures racking direction for transfer operations.

The Xfer_Pass_Racking class calculates the appropriate racking value for transfer operations between needle beds. It supports both direct across-bed transfers (where needles are directly opposite each other) and offset transfers where needles are shifted by a specified distance in a particular direction.

Transfer operations require precise racking calculations to ensure that loops are transferred to the correct target needles. This class handles the complexity of converting directional distance specifications into the numeric racking values required by the knitting machine.

_distance_expression

Optional expression for the needle offset distance.

Type:

Expression | None

_direction_expression

Optional expression for the offset direction.

Type:

Expression | None

Parameters:
__init__(parser_node, distance_expression=None, direction_expression=None)[source]

Initialize the Xfer_Pass_Racking expression.

Parameters:
  • parser_node (LRStackNode) – The parser node from the parse tree.

  • distance_expression (Expression | None, optional) – The needle offset distance expression for transfer operations. If None, indicates a direct across-bed transfer. Defaults to None.

  • direction_expression (Expression | None, optional) – The direction expression indicating which way the offset should be applied.

  • None. (Required when distance_expression is provided. Defaults to)

property is_across: bool

Check if this represents a direct across-bed transfer.

Returns:

True if the transfer occurs with zero racking (directly across beds) and does not depend on any variable expressions.

Return type:

bool

evaluate(context)[source]

Evaluate the expression to calculate the racking value.

Calculates the appropriate racking value for the transfer operation. For across-bed transfers, returns zero. For offset transfers, evaluates the distance and direction expressions and calculates the racking needed to align the source and target needles.

Parameters:

context (Knit_Script_Context) – The current context of the knit_script_interpreter.

Returns:

The racking integer value needed to align needles for the transfer operation.

Return type:

int

Raises:
  • TypeError – If the direction expression does not evaluate to a Carriage_Pass_Direction.

  • AssertionError – If distance_expression is None when is_across is False, or if direction_expression is None when distance is specified.

property line_number: int

Get the line number of the symbol that generated this statement.

Returns:

The line number where this element appears in the source file.

Return type:

int

property location: Location

Get the location of this symbol in KnitScript file.

Returns:

The location of this symbol in the source file, including file name, line number, and position information.

Return type:

Location