knit_script.knit_script_interpreter.expressions.needle_set_expression module
Expressions for accessing standard needle sets from the machine state.
This module provides expression classes for accessing predefined collections of needles from the knitting machine state. It includes the Needle_Sets enumeration that defines available needle collections and the Needle_Set_Expression class that evaluates to these collections based on the current sheet configuration.
- class Needle_Sets(value)[source]
Bases:
Enum
Naming of Needles sets on Machine State.
The Needle_Sets enumeration defines the available predefined needle collections that can be accessed from the knitting machine state. These collections provide convenient access to commonly used needle groupings for knitting operations.
- The enumeration includes collections for different bed positions (front/back), needle types (regular/slider), and needle states (all needles vs. only those with loops),
as well as special collections like the results from the last carriage pass.
- Last_Pass = 'Last_Pass'
- Needles = 'Needles'
- Front_Needles = 'Front_Needles'
- Back_Needles = 'Back_Needles'
- Sliders = 'Sliders'
- Front_Sliders = 'Front_Sliders'
- Back_Sliders = 'Back_Sliders'
- Loops = 'Loops'
- Front_Loops = 'Front_Loops'
- Back_Loops = 'Back_Loops'
- Slider_Loops = 'Slider_Loops'
- Front_Slider_Loops = 'Front_Slider_Loops'
- Back_Slider_Loops = 'Back_Slider_Loops'
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Needle_Set_Expression(parser_node, set_str)[source]
Bases:
Expression
Evaluates keywords to sets of needles on the machine.
The Needle_Set_Expression class handles the evaluation of needle set keywords in knit script programs. It converts string identifiers into the corresponding needle collections from the current sheet configuration, providing access to predefined needle groupings.
This expression type allows knit scripts to easily reference common needle collections without having to manually specify individual needles or ranges. The collections respect the current sheet and gauge settings, returning needles appropriate for the current knitting context.
- Parameters:
parser_node (
LRStackNode
)set_str (
str
)
- __init__(parser_node, set_str)[source]
Initialize the Needle_Set_Expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
set_str (str) – The string identifier for the needle set to retrieve, corresponding to a Needle_Sets enumeration value.
- property set_str: str
Get the string for the set of needles to collect.
- Returns:
String identifier for the set of needles to collect.
- Return type:
- evaluate(context)[source]
Evaluate the expression to get the specified needle set.
Converts the needle set string identifier into the corresponding collection of needles from the current sheet configuration. The returned collection type depends on the specific needle set requested.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter.
- Returns:
The specified set of needles from the current sheet, with type depending on the needle set requested. Dictionary return is used for Last_Pass results which may contain transfer mappings.
- Return type:
list[Needle] | dict[Needle, Needle | None] | list[Slider_Needle]
Note
All needle sets except Last_Pass return lists of needles. Last_Pass may return a dictionary mapping source needles to destination needles for transfer operations, or a simple list for other operations.
- 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 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