knit_script.knit_script_interpreter.statements.Print module
Print Statements.
This module provides the Print statement class, which handles output operations in knit script programs. It evaluates expressions and outputs their values both to the console for debugging and to the knitout as comments for documentation and traceability.
- class Print(parser_node, string)[source]
Bases:
Statement
Prints content to Python console and knitout comments.
- Evaluates an expression and prints the result both to the Python console (prefixed with “KS:”) and as a comment line in the generated knitout.
This provides both immediate feedback during script execution and documentation in the final knitout file.
The print statement is essential for debugging knit script programs and for adding explanatory comments to the generated knitout that help document the knitting process and make the output more understandable.
- _string
The expression to evaluate and print.
- Type:
- Parameters:
parser_node (
LRStackNode
)string (
Expression
)
- __init__(parser_node, string)[source]
Initialize a print statement.
- Parameters:
parser_node (LRStackNode) – The parser node from the abstract syntax tree.
string (Expression) – The expression to evaluate and print to both console and knitout.
- execute(context)[source]
Execute the print by evaluating and outputting the expression.
Evaluates the string expression, prints it to the console with “KS:” prefix, and adds it as a comment to the knitout with proper line break handling for multi-line content.
- Parameters:
context (Knit_Script_Context) – The current execution context of the knit script interpreter.
- Return type:
- __str__()[source]
Return string representation of the print statement.
- Returns:
A string showing the expression to be printed.
- Return type:
- __repr__()[source]
Return detailed string representation of the print statement.
- Returns:
Same as __str__ for this class.
- 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