knit_script.knit_script_interpreter.statements.carrier_statements module
Statement that cuts a yarn.
This module provides statement classes for managing yarn carrier operations in knit script programs. It includes statements for cutting carriers (permanently removing them), releasing the yarn hook, and removing carriers from the working area without cutting the yarn.
- class Cut_Statement(parser_node, carriers)[source]
Bases:
StatementStatement for cutting yarn carriers.
Creates outhook operations that cut and remove yarn carriers from the machine permanently. If no carriers are specified, cuts the currently active working carrier. This operation terminates the yarn and removes it from the machine completely.
The cut operation is typically used at the end of knitting sections or when switching between different yarns that should not be connected. Unlike remove operations, cut operations permanently sever the yarn.
- _carriers
List of expressions that evaluate to carriers to cut.
- Type:
- __init__(parser_node, carriers)[source]
Initialize a cut statement.
- Parameters:
parser_node (LRStackNode) – The parser node from the abstract syntax tree.
carriers (list[Expression]) – List of expressions that evaluate to carriers to cut. Can be empty to cut the current working carrier.
- execute(context)[source]
Execute the cut operation on the specified carriers.
Evaluates all carrier expressions and generates outhook instructions to permanently cut and remove the specified carriers from the machine. If no carriers are specified, cuts the current working carrier.
- Parameters:
context (Knit_Script_Context) – The current execution context of the knit script interpreter.
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- classmethod __init_subclass__(**kwargs)
Automatically wrap execute methods in subclasses with appropriate error handling and debugging decorators.
This method is called whenever a class inherits from Statement. It checks if the subclass defines its own execute method and wraps it with the appropriate decorators
- Parameters:
**kwargs (Any) – Additional keyword arguments passed to super().__init_subclass__
- property file_name: str | None
Returns: str | None: The file name of the knitscript program this was parsed from or None if the program was passed as a string.
- 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:
- property local_path: str | None
Returns: str | None: The path to the directory containing the file from which this element was parsed or None if the value was parsed from a python string.
- 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
- property location_str: str
Returns: str: The string referencing the line number and possible file name information about this element.
- property position_context: str
The position context string is the string from the knitscript program from which this element was parsed. The context string will begin at the start of this element and continue to the end of the line of knitscript or a semicolon on new line are reached.
- Returns:
The string used to contextualize this element in the knitscript program.
- Return type:
- class Release_Statement(parser_node)[source]
Bases:
StatementStatement for releasing the yarn inserting hook.
Removes the current carrier from the yarn inserting hook or does nothing if no carrier is currently hooked. This operation releases the yarn from the hook mechanism without cutting or removing the carrier from the machine, allowing it to be manipulated or repositioned.
The release operation is typically used when the yarn hook needs to be cleared for racking operations or other machine movements that require the hook to be free.
- __init__(parser_node)[source]
Initialize a release statement.
- Parameters:
parser_node (LRStackNode) – The parser node from the abstract syntax tree.
- execute(context)[source]
Execute the release hook operation.
Checks if there is a currently hooked carrier and generates a releasehook instruction to release it from the yarn inserting hook.
- Parameters:
context (Knit_Script_Context) – The current execution context of the knit script interpreter.
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- classmethod __init_subclass__(**kwargs)
Automatically wrap execute methods in subclasses with appropriate error handling and debugging decorators.
This method is called whenever a class inherits from Statement. It checks if the subclass defines its own execute method and wraps it with the appropriate decorators
- Parameters:
**kwargs (Any) – Additional keyword arguments passed to super().__init_subclass__
- property file_name: str | None
Returns: str | None: The file name of the knitscript program this was parsed from or None if the program was passed as a string.
- 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:
- property local_path: str | None
Returns: str | None: The path to the directory containing the file from which this element was parsed or None if the value was parsed from a python string.
- 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
- property location_str: str
Returns: str: The string referencing the line number and possible file name information about this element.
- property position_context: str
The position context string is the string from the knitscript program from which this element was parsed. The context string will begin at the start of this element and continue to the end of the line of knitscript or a semicolon on new line are reached.
- Returns:
The string used to contextualize this element in the knitscript program.
- Return type:
- class Remove_Statement(parser_node, carriers)[source]
Bases:
StatementStatement for removing carriers from bed without cutting.
Equivalent to ‘out’ operations - removes carriers from the needle bed but does not cut the yarn, allowing the carrier to be brought back later with ‘in’ operations. This is useful for temporarily moving carriers out of the way without permanently terminating them.
The remove operation maintains the yarn connection but moves the carrier out of the active working area, making it available for later reactivation when needed.
- _carriers
List of expressions that evaluate to carriers to remove.
- Type:
- __init__(parser_node, carriers)[source]
Initialize a remove statement.
- Parameters:
parser_node (LRStackNode) – The parser node from the abstract syntax tree.
carriers (list[Expression]) – List of expressions that evaluate to carriers to remove. Can be empty to remove the current working carrier.
- execute(context)[source]
Execute the remove operation on the specified carriers.
Evaluates all carrier expressions and generates out instructions to remove the specified carriers from the working area without cutting them. If no carriers are specified, removes the current working carrier.
- Parameters:
context (Knit_Script_Context) – The current execution context of the knit script interpreter.
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- classmethod __init_subclass__(**kwargs)
Automatically wrap execute methods in subclasses with appropriate error handling and debugging decorators.
This method is called whenever a class inherits from Statement. It checks if the subclass defines its own execute method and wraps it with the appropriate decorators
- Parameters:
**kwargs (Any) – Additional keyword arguments passed to super().__init_subclass__
- property file_name: str | None
Returns: str | None: The file name of the knitscript program this was parsed from or None if the program was passed as a string.
- 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:
- property local_path: str | None
Returns: str | None: The path to the directory containing the file from which this element was parsed or None if the value was parsed from a python string.
- 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
- property location_str: str
Returns: str: The string referencing the line number and possible file name information about this element.
- property position_context: str
The position context string is the string from the knitscript program from which this element was parsed. The context string will begin at the start of this element and continue to the end of the line of knitscript or a semicolon on new line are reached.
- Returns:
The string used to contextualize this element in the knitscript program.
- Return type: