knit_script.knit_script_interpreter.expressions.direction module

Accesses machine directions.

This module provides the Pass_Direction_Expression class, which handles the parsing and evaluation of carriage pass direction expressions in knit script code. It supports various direction keywords and contextual direction references, converting them into the appropriate Carriage_Pass_Direction objects.

class Pass_Direction_Expression(parser_node, dir_word)[source]

Bases: Expression

Expression of a Machine Pass Direction.

The Pass_Direction_Expression class handles the conversion of direction keywords in knit script source code into Carriage_Pass_Direction objects. It supports both explicit direction keywords (like “Leftward”, “Rightward”) and contextual references (like “current”, “reverse”) that depend on the current machine state.

This expression type is essential for carriage pass operations where the direction of needle processing must be specified. It provides flexibility in how directions are specified while ensuring they resolve to the correct machine direction values.

_dir_word

The direction keyword from the source code.

Type:

str

Parameters:
  • parser_node (LRStackNode)

  • dir_word (str)

__init__(parser_node, dir_word)[source]

Initialize the Pass_Direction_Expression.

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

  • dir_word (str) – Keyword for the direction, such as “Leftward”, “Rightward”, “current”, or “reverse”.

evaluate(context)[source]

Evaluate the expression to get the corresponding carriage pass direction.

Converts the direction keyword into the appropriate Carriage_Pass_Direction object, handling both explicit directions and contextual references that depend on the current machine state.

Parameters:

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

Returns:

The carriage pass direction corresponding to the keyword.

Return type:

Carriage_Pass_Direction

Note

Supported keywords: - “Leftward”, “Decreasing”: Returns leftward direction - “Rightward”, “Increasing”: Returns rightward direction - “current”: Returns the current direction from context - “reverse”: Returns the opposite of the current direction

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