knit_script.knit_script_interpreter.expressions.formatted_string module
Produces formatted strings.
This module provides the Formatted_String_Value class, which implements formatted string expressions following Python f-string conventions. It handles the evaluation and concatenation of mixed string literals and expressions within formatted string contexts.
- class Formatted_String_Value(parser_node, expressions)[source]
Bases:
Expression
Follows python fstring conventions.
The Formatted_String_Value class implements formatted string expressions that mirror Python’s f-string functionality. It takes a list of expressions that represent the components of a formatted string (both literal string parts and embedded expressions) and evaluates them in sequence to produce a concatenated result.
- This allows knit script programs to use dynamic string formatting similar to Python f-strings,
where expressions can be embedded within string literals and evaluated at runtime to produce formatted output.
- expressions
List of expressions in order for string formatting, including both string literals and embedded expressions.
- Type:
- Parameters:
parser_node (
LRStackNode
)expressions (
list
[Expression
])
- __init__(parser_node, expressions)[source]
Initialize the Formatted_String_Value.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
expressions (list[Expression]) – List of expressions in order for string formatting, representing the components of the formatted string.
- evaluate(context)[source]
Evaluate the expression to produce a formatted string.
Evaluates each component expression in sequence and concatenates their string representations to produce the final formatted string result.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter.
- Returns:
The concatenated result of evaluating all component expressions and converting them to strings.
- 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