knit_script.knit_script_interpreter.expressions.machine_accessor module

Accessor for components of the machine state.

This module provides expression classes for accessing machine state and sheet components in knit script programs. It includes the Machine_Accessor for direct machine access and Sheet_Expression for referencing specific sheets with gauge configurations.

class Machine_Accessor(parser_node)[source]

Bases: Expression

Used to access machine state directly.

The Machine_Accessor class provides direct access to the knitting machine state from knit script expressions. It serves as the bridge between knit script code and the underlying machine state, allowing scripts to access machine properties and needle collections.

This accessor is typically used with attribute access operations to get specific machine components like needle sets, carrier systems, or machine configuration parameters.

__init__(parser_node)[source]

Initialize the Machine_Accessor.

Parameters:

parser_node (LRStackNode) – The parser node from the parse tree.

evaluate(context)[source]

Evaluate the expression to get the machine state.

Parameters:

context (Knit_Script_Context) – The current context of the knit_script_interpreter.

Returns:

The current machine state from the execution context.

Return type:

Knitting_Machine

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:

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 Sheet_Expression(parser_node, sheet_id, gauge_id=None)[source]

Bases: Expression

Identifies sheets.

The Sheet_Expression class handles the creation and evaluation of sheet identifiers in knit script programs. It supports both simple sheet references and complex sheet specifications with custom gauge values, parsing sheet identifier strings and creating appropriate Sheet_Identifier objects.

This expression type is essential for multi-sheet knitting operations where specific sheets need to be referenced with their gauge configurations. It handles various sheet identifier formats including embedded gauge specifications.

_sheet_id

The identifier of the sheet, either as an expression or string.

Type:

Expression | str

_gauge_id

Optional gauge identifier expression.

Type:

Expression | None

__init__(parser_node, sheet_id, gauge_id=None)[source]

Initialize the Sheet_Expression.

Parameters:
  • parser_node (LRStackNode) – The parser node from the parse tree.

  • sheet_id (Expression | str) – The identifier of the sheet, which can be a string with embedded gauge information or an expression.

  • gauge_id (Expression | None, optional) – The identifier of the gauge, defaults to current gauge if not specified. Defaults to None.

evaluate(context)[source]

Evaluate the expression to create a sheet identifier.

Processes the sheet identifier, extracting gauge information if embedded in the string format, and creates a Sheet_Identifier with the appropriate sheet and gauge values.

Parameters:

context (Knit_Script_Context) – The current context of the knit_script_interpreter.

Returns:

Identifier for the sheet at the specified or current gauge.

Return type:

Sheet_Identifier

Note

String sheet identifiers can include embedded gauge information in the format “s<sheet>:g<gauge>” where <sheet> and <gauge> are numeric values.

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:

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