knit_script.knit_script_interpreter.statements.in_direction_statement module

Used to translate lists of knitting instructions in a single carriage pass.

This module provides the In_Direction_Statement class, which handles the execution of multiple needle instructions within a single carriage pass in a specified direction. It coordinates instruction evaluation, carriage pass creation, and proper handling of special operations like split instructions.

class In_Direction_Statement(parser_node, direction, instructions)[source]

Bases: Statement

Statement that sets the machine direction for a set of instructions.

Creates a carriage pass with the specified direction and executes all needle instructions within that pass. Handles special cases like split operations that return second needles and provides proper scope management for direction changes.

This statement is fundamental to knit script execution, as it coordinates multiple needle operations that must be performed together in a single carriage pass. It ensures that all operations are compatible and executed in the correct sequence based on the specified direction.

_direction

Expression that evaluates to the carriage pass direction.

Type:

Expression

_instructions

List of needle instruction expressions to execute.

Type:

list[Needle_Instruction_Exp]

Parameters:
__init__(parser_node, direction, instructions)[source]

Initialize a directional instruction statement.

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

  • direction (Expression) – Expression that evaluates to the carriage pass direction for executing the instructions.

  • instructions (list[Needle_Instruction_Exp]) – List of needle instruction expressions to execute in the specified direction.

execute(context)[source]

Execute all instructions in the specified direction.

Creates a new scope, evaluates the direction, processes all instructions into a carriage pass specification, and executes the pass. Handles special result handling for split operations and stores pass results for potential use by subsequent operations.

Parameters:

context (Knit_Script_Context) – The current execution context of the knit script interpreter.

Raises:

No_Declared_Carrier_Exception – If no working carrier is set when instructions require one for yarn-based operations.

Return type:

None

__str__()[source]

Return string representation of the directional statement.

Returns:

A string showing the direction and instructions.

Return type:

str

__repr__()[source]

Return detailed string representation of the directional statement.

Returns:

Same as __str__ for this class.

Return type:

str

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