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, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumNaming 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:
ExpressionEvaluates 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.
- __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.
- 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 evaluate methods in subclasses with appropriate error handling decorator.
This method is called whenever a class inherits from Expression. It checks if the subclass defines its own evaluate method and wraps it with the appropriate decorator.
- 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: