knit_script.knit_script_interpreter.expressions.carrier module

Carrier expression.

This module provides the Carrier_Expression class, which handles the parsing and evaluation of carrier string literals in knit script code. It converts carrier string identifiers (like “c1”, “c2”, etc.) into the corresponding Yarn_Carrier objects from the knitting machine’s carrier system.

class Carrier_Expression(parser_node, carrier_str)[source]

Bases: Expression

Used for processing carrier strings.

The Carrier_Expression class handles the conversion of carrier string literals in knit script source code into actual Yarn_Carrier objects. It parses carrier identifiers that follow the pattern “c” followed by a number (e.g., “c1”, “c2”, “c10”) and retrieves the corresponding carrier from the knitting machine’s carrier system.

This expression type is essential for yarn carrier operations in knit script programs, allowing developers to reference specific carriers by their conventional string identifiers.

_carrier_str

The original carrier string identifier from the source code.

Type:

str

Parameters:
  • parser_node (LRStackNode)

  • carrier_str (str)

__init__(parser_node, carrier_str)[source]

Initialize the Carrier_Expression.

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

  • carrier_str (str) – The string to identify the carrier from, typically in the format “c” followed by a number (e.g., “c1”, “c2”).

evaluate(context)[source]

Evaluate the expression to get the corresponding yarn carrier.

Parses the carrier string to extract the carrier ID number and retrieves the corresponding Yarn_Carrier object from the knitting machine’s carrier system.

Parameters:

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

Returns:

The carrier object with the specified ID from the machine’s carrier system.

Return type:

Yarn_Carrier

Raises:
  • ValueError – If the carrier string format is invalid or cannot be parsed.

  • KeyError – If the extracted carrier ID does not exist in the machine’s carrier system.

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