knit_script.knit_script_interpreter.expressions.needle_expression module
Expression for identifying needles.
This module provides the Needle_Expression class, which handles the parsing and evaluation of needle identifier strings in knit script programs. It converts needle string literals into actual Needle objects that respect the current gauging configuration.
- class Needle_Expression(parser_node, needle_str)[source]
Bases:
Expression
Expression that evaluates to a Needle.
The Needle_Expression class handles the conversion of needle string identifiers in knit script source code into actual Needle objects. It parses needle identifiers that specify bed position, slider status, and needle position, creating the appropriate needle type based on the current gauging configuration.
Needle identifiers follow the format: [bed][slider][position] where: - bed: ‘f’ for front bed, ‘b’ for back bed - slider: ‘s’ for slider needles (optional) - position: numeric position on the bed
Examples: “f5” (front needle 5), “bs3” (back slider needle 3), “f10” (front needle 10)
- Parameters:
parser_node (
LRStackNode
)needle_str (
str
)
- __init__(parser_node, needle_str)[source]
Initialize the Needle_Expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
needle_str (str) – String to parse into a needle identifier, following the format [bed][slider][position].
- evaluate(context)[source]
Evaluate the expression to create a needle object.
- Parses the needle string identifier to extract bed position, slider status, and needle position,
then creates the appropriate Needle object using the current gauging configuration from the context.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter.
- Returns:
The evaluated Needle object based on the string identifier and current gauging configuration.
- Return type:
Needle
Note
The needle type (regular or sheet needle) depends on the current gauge setting in the context. The position is interpreted relative to the current sheet and gauge configuration.
- 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