AstNode
- class AstNode
The basic type of all AST nodes.
Children
Members defined in
AstNode(9 members)
RThe source CST node of
selfif one exists.
RThe
documentthat owns this node.
RReturns a view into all elements directly owned by this
Element.
RThe parent node of
self.
Identity based hash of this node.
cast(self, *type: type[TNode]) -> TNode
Chainable equivalent to
isintance(self, type)
Checked cast to
type. Attributes
- property cst_node: syside.CstNode | None
The source CST node of
selfif one exists.This is only available on nodes parsed from text sources, and only on nodes that have not been created implicitly to satisfy some constraints.
- property document: syside.Document
The
documentthat owns this node.In Syside, all AST nodes are attached to their owning documents, this improves performance and ergonomics in certain places at the cost of not being able to move nodes between documents.
Note that this assumes that the returned
documentand all of its transitive dependencies will not be accessed from other threads, e.g. by acquiring locks to all dependent (downstream) documents.
- property owned_elements: syside.LazyIterator[syside.Element]
Returns a view into all elements directly owned by this
Element.
- property parent: syside.Element | None
The parent node of
self.
Methods
- __hash__() int
Identity based hash of this node.
This is guaranteed to be unique or nearly unique globally (due to bit mixing). However, it is not stable across Python invocations, and erased elements may be reused internally with the same hash.
- __str__() str
- cast(type: tuple[syside.AstNode.cast.type[syside.TNode], ...]) syside.TNode
- cast(*type: type[syside.TNode]) syside.TNode
Checked cast to
type.Similar to
typing.cast(type, self)except this raisesTypeErrorif the cast fails.
- isinstance(type: syside.AstNode.isinstance.type[syside.TNode]) TypeGuard[syside.TNode]
Chainable equivalent to
isintance(self, type)
- isinstance(type: tuple[syside.AstNode.isinstance.type[syside.TNode], ...]) TypeGuard[syside.TNode]
- try_cast(type: tuple[syside.AstNode.try_cast.type[syside.TNode], ...]) syside.TNode | None
Checked cast to
type.Similar to
typing.cast(type, self)except this returnsNoneif the cast fails.
- try_cast(*type: type[syside.TNode]) syside.TNode | None
-