knit_script.knit_script_interpreter.expressions.values module
Expression values that don’t need context to evaluate.
This module provides expression classes for literal values and context-free expressions in knit script programs. These expressions represent constants and literal values that can be evaluated without requiring access to the current execution context, including numbers, strings, booleans, and various enumerated types.
- class None_Value(parser_node)[source]
Bases:
_Context_Free_Value
Used to represent None values.
The None_Value class represents Python’s None literal in knit script expressions. It provides a constant None value that can be used in comparisons, assignments, and other operations where null values are needed.
- Parameters:
parser_node (
LRStackNode
)
- __init__(parser_node)[source]
Initialize the None_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
- context_free_evaluation()[source]
Get the None value.
- Returns:
Python’s None value.
- Return type:
None
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class Float_Value(parser_node, value)[source]
Bases:
_Context_Free_Value
Processes numerical string into floating point value.
The Float_Value class handles floating-point literal expressions in knit script programs. It parses numeric string representations and converts them to Python float values, handling various numeric formats and extracting valid numeric characters.
- Parameters:
parser_node (
LRStackNode
)value (
str
)
- __init__(parser_node, value)[source]
Initialize the Float_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
value (str) – String representation of the floating-point value.
- context_free_evaluation()[source]
Get the floating point value from the string representation.
Extracts valid numeric characters from the string and converts to a float value.
- Returns:
The floating-point value represented by the string.
- Return type:
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class Int_Value(parser_node, value)[source]
Bases:
Float_Value
Expression of a single integer (not numerical expression) that evaluates to integer value.
The Int_Value class extends Float_Value to handle integer literal expressions. It processes numeric strings and converts them to Python integer values, inheriting the numeric character extraction logic from Float_Value.
- Parameters:
parser_node (
LRStackNode
)value (
str
)
- __init__(parser_node, value)[source]
Initialize the Int_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
value (str) – String representation of the integer value.
- context_free_evaluation()[source]
Get the integer value from the string representation.
Uses the parent class’s float conversion and converts the result to an integer.
- Returns:
The integer value represented by the string.
- Return type:
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class Bed_Value(parser_node, bed_str)[source]
Bases:
_Context_Free_Value
Expression of Needle bed positions.
The Bed_Value class handles needle bed position literals in knit script programs. It converts string representations of bed positions into the corresponding Machine_Bed_Position enumeration values.
- Parameters:
parser_node (
LRStackNode
)bed_str (
str
)
- __init__(parser_node, bed_str)[source]
Initialize the Bed_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
bed_str (str) – String representing the bed position.
- context_free_evaluation()[source]
Get the Machine Bed Position from the string representation.
Converts the bed string to the appropriate Machine_Bed_Position enumeration value, handling capitalization and slider designations.
- Returns:
The machine bed position corresponding to the string (front, back, front_slider, or back_slider).
- Return type:
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class Boolean_Value(parser_node, bool_str)[source]
Bases:
_Context_Free_Value
Expressions of boolean values.
The Boolean_Value class handles boolean literal expressions in knit script programs. It converts string representations of boolean values (“True”/”False”) into Python boolean values.
- Parameters:
parser_node (
LRStackNode
)bool_str (
str
)
- __init__(parser_node, bool_str)[source]
Initialize the Boolean_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
bool_str (str) – String representing the boolean value (“True” or “False”).
- context_free_evaluation()[source]
Get the boolean value from the string representation.
Converts the string representation to the corresponding Python boolean value.
- Returns:
True if the string is “True”, False otherwise.
- Return type:
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class String_Value(parser_node, string)[source]
Bases:
_Context_Free_Value
Follows Python String Conventions.
The String_Value class handles string literal expressions in knit script programs. It stores and provides access to string values following Python’s string conventions and behavior.
- Parameters:
parser_node (
LRStackNode
)string (
str
)
- __init__(parser_node, string)[source]
Initialize the String_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
string (str) – The string content.
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class Machine_Position_Value(parser_node, position_str)[source]
Bases:
_Context_Free_Value
Used for evaluating Machine Position identifiers in headers.
The Machine_Position_Value class handles machine position literals used in knitout headers. It converts position string identifiers into the corresponding carriage pass direction values.
- Parameters:
parser_node (
LRStackNode
)position_str (
str
)
- __init__(parser_node, position_str)[source]
Initialize the Machine_Position_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
position_str (str) – String identifier for the machine position.
- context_free_evaluation()[source]
Get the carriage pass direction from the position string.
- Returns:
The carriage pass direction corresponding to the position identifier.
- Return type:
Carriage_Pass_Direction
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class Machine_Type_Value(parser_node, type_str)[source]
Bases:
_Context_Free_Value
Used for evaluating Machine Type identifiers in headers.
The Machine_Type_Value class handles machine type literals used in knitout headers. It converts type string identifiers into the corresponding Knitting_Machine_Type enumeration values.
- Parameters:
parser_node (
LRStackNode
)type_str (
str
)
- __init__(parser_node, type_str)[source]
Initialize the Machine_Type_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
type_str (str) – String identifier for the machine type.
- context_free_evaluation()[source]
Get the knitting machine type from the type string.
- Returns:
The machine type corresponding to the type identifier.
- Return type:
Knitting_Machine_Type
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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
- class Header_ID_Value(parser_node, hid_str)[source]
Bases:
_Context_Free_Value
Used for evaluating strings of header types.
The Header_ID_Value class handles header type identifiers used in knitout header specifications. It converts header ID strings into the corresponding Knitout_Header_Line_Type enumeration values.
- Parameters:
parser_node (
LRStackNode
)hid_str (
str
)
- __init__(parser_node, hid_str)[source]
Initialize the Header_ID_Value expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
hid_str (str) – String identifier for the header type.
- context_free_evaluation()[source]
Get the knitout header line type from the header ID string.
- Returns:
The header line type corresponding to the header ID.
- Return type:
Knitout_Header_Line_Type
- evaluate(context)
Evaluate the expression using context-free evaluation.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter (unused for context-free values).
- Returns:
The constant value represented by this expression.
- Return type:
Any
- 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