knit_script.knit_script_interpreter.ks_element module
Module containing the KS_Element Super Class.
This module provides the KS_Element base class, which serves as the foundation for all parser elements in the KnitScript language. It provides common functionality for accessing parser node information, location data, and line number information that is essential for error reporting and debugging.
- class KS_Element(parser_node)[source]
Bases:
Debuggable_ElementSuperclass of all parser elements in KS.
The KS_Element class provides the base functionality for all elements created during knit script parsing as a part of the abstract syntax tree. It maintains a reference to the parser node that created the element and provides convenient access to location information for error reporting and debugging purposes.
This base class ensures that all knit script language elements have consistent access to their source location information, which is essential for providing meaningful error messages and debugging information to users.
- parser_node
The parser node that created this element.
- Type:
LRStackNode
- __init__(parser_node)[source]
Initialize the KS element with parser node information.
- Parameters:
parser_node (LRStackNode) – The parser node that created this element, containing location and context information.
- 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
- 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 file_name: str | None
Returns: str | None: The file name of the knitscript program this was parsed from or None if the program was passed as a string.
- property local_path: str | None
Returns: str | None: The path to the directory containing the file from which this element was parsed or None if the value was parsed from a python string.
- property location_str: str
Returns: str: The string referencing the line number and possible file name information about this element.
- property position_context: str
The position context string is the string from the knitscript program from which this element was parsed. The context string will begin at the start of this element and continue to the end of the line of knitscript or a semicolon on new line are reached.
- Returns:
The string used to contextualize this element in the knitscript program.
- Return type:
- classmethod __class_getitem__(params)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….
- associate_error(execution_method)[source]
- Parameters:
execution_method (Callable[[KS_Element,], Any]) – The wrapped method of a knitscript element to annotate associated errors.
- Returns:
The wrapped method.
- Return type:
Callable[[KS_Element,], Any]