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¶
True when |
|
True when |
|
Parse Python source into a lossless |
|
Parse a fragment for splicing into another tree. |
API¶
- simvx.core.scene_io.source_tree.is_node(node: parso.tree.NodeOrLeaf) TypeGuard[parso.tree.BaseNode][source]¶
True when
nodeis a composite node carrying achildrenlist.parso’s :class:
NodeOrLeafis a union of :class:BaseNode(which haschildren) and :class:Leaf(which hasvalue/prefixinstead). Narrow with this guard before touching.children.
- simvx.core.scene_io.source_tree.is_leaf(node: parso.tree.NodeOrLeaf) TypeGuard[parso.tree.Leaf][source]¶
True when
nodeis a terminal :class:Leafcarryingvalue.
- 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’, ‘_issues_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.
- property issues: list[simvx.core.scene_io.syntax.SyntaxIssue][source]¶
Every place parso could not read this source, classified, in order.
Empty when the source parses. Each carries the construct it holds where that is one of the ones the scene format documents as unreadable (:mod:
simvx.core.scene_io.syntax), so a refusal can name it.
- 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.