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.

__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

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__

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 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:

int

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:

str

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.

_value

The original string representation of the floating-point number.

Type:

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:

float

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__

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 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:

int

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:

str

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.

__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:

int

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__

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 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:

int

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:

str

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.

_bed_str

The string representation of the bed position.

Type:

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:

Machine_Bed_Position

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__

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 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:

int

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:

str

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.

_bool_str

The string representation of the boolean value.

Type:

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:

bool

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__

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 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:

int

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:

str

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.

_string

The string value content.

Type:

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.

context_free_evaluation()[source]

Get the string value.

Returns:

The string content.

Return type:

str

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__

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 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:

int

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:

str

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.

_position_str

The string representation of the machine position.

Type:

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

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__

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 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:

int

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:

str

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.

_type_str

The string representation of the machine type.

Type:

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

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__

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 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:

int

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:

str

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.

hid_str

The string representation of the header ID.

Type:

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

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__

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 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:

int

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:

str