simvx.core.scene_io.source_tree¶
Lossless parse and re-emit of Python source via parso.
parse_source returns a SourceTree whose dump() is byte-identical to the
input when nothing has been edited. Edits are applied directly to the
underlying parso tree (see simvx.core.scene_io.edits); dump() serialises
the current state via parso’s get_code().
Module Contents¶
Classes¶
A parsed Python source file with byte-perfect re-emit. |
Functions¶
Parse Python source into a lossless |
|
Parse a fragment for splicing into another tree. |
API¶
- simvx.core.scene_io.source_tree.parse_source(text: str, *, error_recovery: bool = True) SourceTree[source]¶
Parse Python source into a lossless
SourceTree.With
error_recovery=True(default), broken sources still return a tree and any parser issues are exposed via :attr:SourceTree.errors. Witherror_recovery=False, malformed input raisesparso.ParserSyntaxError.
- simvx.core.scene_io.source_tree.parse_snippet(text: str) parso.tree.NodeOrLeaf[source]¶
Parse a fragment for splicing into another tree.
Accepts whole statements, single expressions, or suites. Returns the lifted inner node — the first child of the wrapping
file_inputmodule, with the trailingendmarkerstripped — not the module itself. Caller is responsible for prefix/indent fixup before insertion (see- Mod:
simvx.core.scene_io.edits).
- class simvx.core.scene_io.source_tree.SourceTree(module: parso.python.tree.Module, *, original_text: str)[source]¶
A parsed Python source file with byte-perfect re-emit.
Holds the parso :class:
Moduleplus the original source text so callers can detect a no-op round-trip via :meth:is_unchangedwithout diffing bytes themselves.Initialization
- __slots__¶
(‘_module’, ‘_original_text’, ‘_errors_cache’)
- property module: parso.python.tree.Module[source]¶
The underlying parso module. Edit in place via
scene_io.edits.
- dump() str[source]¶
Return current source text via parso’s
get_code().Round-trip identity is guaranteed when no edits have been made — see
- Meth:
is_unchanged.
- find_class(name: str) parso.python.tree.Class | None[source]¶
First top-level class with matching name, else None.
- iter_classes() collections.abc.Iterator[parso.python.tree.Class][source]¶
Yield top-level class definitions in source order.