knit_script.knit_script_interpreter.expressions.Gauge_Expression module

Expression for getting a sheet at a gauge.

This module provides the Gauge_Expression class, which handles the creation of sheet identifiers with specific gauge configurations. It allows knit script programs to specify sheet and gauge combinations for multi-sheet knitting operations.

class Gauge_Expression(parser_node, sheet, gauge)[source]

Bases: Expression

Manages gauge expressions.

The Gauge_Expression class handles the creation of Sheet_Identifier objects with specified sheet and gauge values. It provides a way to explicitly specify both the sheet number and gauge configuration, with automatic bounds checking and fallback to context values when needed.

This expression type is essential for multi-sheet knitting operations where different sheets need to be referenced with specific gauge configurations. It ensures that sheet numbers are valid for the specified gauge and provides sensible defaults from the execution context.

_sheet

The expression that evaluates to the sheet position.

Type:

Expression

_gauge

The expression that evaluates to the number of sheets (gauge).

Type:

Expression

Parameters:
__init__(parser_node, sheet, gauge)[source]

Initialize the Gauge_Expression.

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

  • sheet (Expression) – The expression that evaluates to the sheet position.

  • gauge (Expression) – The expression that evaluates to the number of sheets in the gauge configuration.

evaluate(context)[source]

Evaluate the expression to create a sheet identifier.

Evaluates the sheet and gauge expressions and creates a Sheet_Identifier with the resulting values. Provides fallback to context values when expressions evaluate to None and performs bounds checking to ensure the sheet number is valid for the gauge.

Parameters:

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

Returns:

The sheet identifier with the specified sheet and gauge parameters.

Return type:

Sheet_Identifier

Note

If the sheet number is greater than or equal to the gauge, it will be automatically adjusted to gauge-1 to ensure validity.

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