knit_script.knit_script_interpreter.expressions.accessors module
Used to access attributes from instances in code.
This module provides the Attribute_Accessor_Expression class, which handles attribute access operations for knit script expressions. It supports accessing attributes from both knit script objects and underlying Python objects, including method calls, property access, and specialized handling for machine and sheet-specific needle collections.
- class Attribute_Accessor_Expression(parser_node, parent_path, attribute)[source]
Bases:
Expression
Accesses attributes of expression either from knit-script or underlying python.
This class handles complex attribute access operations in knit script, supporting both direct attribute access and method calls. It can access attributes from Python objects as well as specialized knit script objects like machines and sheet identifiers. The class supports chained attribute access and provides specialized handling for needle set expressions.
- parent
List of parent expressions in the access chain.
- Type:
- attribute
The attribute being accessed from the parent.
- Type:
- Parameters:
parser_node (
LRStackNode
)parent_path (
list
[Expression
] |Expression
)attribute (
Expression
)
- __init__(parser_node, parent_path, attribute)[source]
Initialize the Attribute_Accessor_Expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
parent_path (list[Expression] | Expression) – The expression to access an attribute from. Can be a single expression or a chain of expressions.
attribute (Expression) – The attribute of the parent expression. May produce more nested accessors.
- parent_path()[source]
Get the path to parent value as a dot-separated string.
- Returns:
Path to parent value with expressions separated by dots.
- Return type:
- 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:
- 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
- evaluate(context)[source]
Evaluate the expression to access the specified attribute.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter.
- Returns:
The accessed attribute value from the parent expression.
- Return type:
Any
- Raises:
AttributeError – If the attribute cannot be accessed from the parent object.