[docs]classSourceCode:"""Represents a parsed source code. Parses the given source text into a translation unit and provides access to recognized top-level node elements. Parameters ---------- source: Source text to be parsed. lazy_parsing: If True, the underlying `PyTranslationUnit` will **not** be created during construction. Instead, parsing is deferred until the translation unit or other derived properties (like `.content`) are first accessed. .. versionadded:: 0.1.3 """def__init__(self,source:str,lazy_parsing:bool=False)->None:self._source=sourceself._unit:Optional[PyTranslationUnit]=Noneiflazy_parsingelse(PyTranslationUnit.from_source(lib=get_native_library(),source=source))self._content:Optional[list[INodeElement]]=Noneself._errors:Optional[list[ErrorReport]]=Nonedef__repr__(self)->str:returnf"SourceFile(size={len(self._source)})"@propertydefcontent(self)->list[INodeElement]:"""A list of top-level elements parsed from the source string."""ifself._contentisNone:self._content=[]fornodeinself.unit.root_nodes():fornode_typeinself.types:ifnode_type.is_node_valid(node):self._content.append(node_type.from_node(node))returnself._content@propertydeferrors(self)->list[ErrorReport]:"""A list of error reports that occurred during parsing this file."""ifself._errorsisNone:self._errors=self.unit.errors()returnself._errors@propertydefunit(self)->PyTranslationUnit:""" The parsed translation unit for this source. .. versionadded:: 0.1.3 """ifself._unitisNone:self._unit=PyTranslationUnit.from_source(lib=get_native_library(),source=self._source)returnself._unit@propertydeftypes(self)->tuple[type[INodeElement],...]:"""Supported top-level node element types."""returnTestDeclaration,FunctionDeclaration,VariableDeclaration