pylasu.model package
Submodules
pylasu.model.errors module
pylasu.model.model module
- class pylasu.model.model.CompositeDestination(elements: List[pylasu.model.model.Destination] = <factory>)[source]
Bases:
Destination
- elements: List[Destination]
- class pylasu.model.model.CompositeOrigin(elements: List[pylasu.model.model.Origin] = <factory>, position: Optional[pylasu.model.position.Position] = None, source_text: Optional[str] = None)[source]
Bases:
Origin
- source_text: str | None = None
- class pylasu.model.model.Concept(name, bases, namespace, /, **kwargs)[source]
Bases:
ABCMeta
- property node_properties
- class pylasu.model.model.InternalField(default, default_factory, init, repr, hash, compare, metadata, kw_only)[source]
Bases:
Field
- compare
- default
- default_factory
- hash
- init
- kw_only
- metadata
- name
- repr
- type
- class pylasu.model.model.Node(origin: Origin | None = None, parent: Node | None = None, position_override: Position | None = None)[source]
Bases:
Origin
,Destination
- assign_parents()
Sets or corrects the parent of all AST nodes.
Pylasu does not see set/add/delete operations on the AST nodes, so this function should be called manually after modifying the AST, unless you’ve taken care of assigning the parents yourself.
- Parameters:
self – the root of the AST subtree to start from.
- property children
- destination: Destination | None = None
- find_ancestor_of_type(target: type)
Returns the nearest ancestor of this node that is an instance of the target type.
Note that type is not strictly forced to be a subtype of Node. This is intended to support trait types like Statement or Expression. However, the returned value is guaranteed to be a Node, as only Node instances can be part of the hierarchy.
- Parameters:
self – the node from which to start the search.
target – the target type.
- replace_with(other: Node)
Replace this node with another (by modifying the children of the parent node). For this to work, this node must have a parent assigned.
- Parameters:
self – the node to replace.
other – the replacement node.
- search_by_type(target_type, walker=<function walk>)
- walk()
Walks the whole AST starting from this node, depth-first.
- walk_ancestors()
Iterator over the sequence of nodes from this node’s parent all the way up to the root node.
- walk_descendants(walker=<function walk>, restrict_to=<class 'pylasu.model.model.Node'>)
Walks the whole AST starting from the child nodes of this node.
- Parameters:
self – the node from which to start the walk, which is NOT included in the walk.
walker – a function that generates a sequence of nodes. By default this is the depth-first “walk” method.
For post-order traversal, use “walk_leaves_first”. :param restrict_to: optional type filter. By default, all nodes (i.e., subclasses of Node) are included, but you can limit the walk to only a subtype of Node.
- walk_leaves_first()
Performs a post-order (or leaves-first) node traversal starting with a given node.
- class pylasu.model.model.TextFileDestination(position: pylasu.model.position.Position | None = None)[source]
Bases:
Destination
- pylasu.model.model.internal_field(*, default=<dataclasses._MISSING_TYPE object>, default_factory=<dataclasses._MISSING_TYPE object>, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=False)[source]
Return an object to identify internal dataclass fields. The arguments are the same as dataclasses.field.
pylasu.model.naming module
- class pylasu.model.naming.Named(name: str)[source]
Bases:
PossiblyNamed
- name: str
- class pylasu.model.naming.ReferenceByName(name: str, referred: T | None = None)[source]
Bases:
Generic
[T
]- name: str
- referred: T | None = None
- class pylasu.model.naming.Scope(symbols: Dict[str, List[pylasu.model.naming.Symbol]] = <factory>, parent: Optional[ForwardRef('Scope')] = None)[source]
Bases:
object
- class pylasu.model.naming.Symbol(name: str)[source]
Bases:
PossiblyNamed
pylasu.model.position module
- class pylasu.model.position.Point(line: int, column: int)[source]
Bases:
object
- column: int
- line: int
- class pylasu.model.position.Position(start: Point, end: Point, source: Source = None)[source]
Bases:
object
An area in a source file, from start to end. The start point is the point right before the starting character. The end point is the point right after the last character. An empty position will have coinciding points.
Consider a file with one line, containing the text “HELLO”. The Position of such text will be Position(Point(1, 0), Point(1, 5)).
- class pylasu.model.position.SourceSet(name: str, root: pathlib.Path)[source]
Bases:
object
- name: str
- root: Path
- class pylasu.model.position.SourceSetElement(sourceSet: pylasu.model.position.SourceSet, relativePath: pathlib.Path)[source]
Bases:
Source
- relativePath: Path
pylasu.model.processing module
- pylasu.model.processing.assign_parents(self: Node)[source]
Sets or corrects the parent of all AST nodes.
Pylasu does not see set/add/delete operations on the AST nodes, so this function should be called manually after modifying the AST, unless you’ve taken care of assigning the parents yourself.
- Parameters:
self – the root of the AST subtree to start from.
- pylasu.model.processing.replace_with(self: Node, other: Node)[source]
Replace this node with another (by modifying the children of the parent node). For this to work, this node must have a parent assigned.
- Parameters:
self – the node to replace.
other – the replacement node.
pylasu.model.traversing module
- pylasu.model.traversing.find_ancestor_of_type(self: Node, target: type)[source]
Returns the nearest ancestor of this node that is an instance of the target type.
Note that type is not strictly forced to be a subtype of Node. This is intended to support trait types like Statement or Expression. However, the returned value is guaranteed to be a Node, as only Node instances can be part of the hierarchy.
- Parameters:
self – the node from which to start the search.
target – the target type.
- pylasu.model.traversing.walk(self: Node)[source]
Walks the whole AST starting from this node, depth-first.
- pylasu.model.traversing.walk_ancestors(self: Node)[source]
Iterator over the sequence of nodes from this node’s parent all the way up to the root node.
- pylasu.model.traversing.walk_descendants(self: ~pylasu.model.model.Node, walker=<function walk>, restrict_to=<class 'pylasu.model.model.Node'>)[source]
Walks the whole AST starting from the child nodes of this node.
- Parameters:
self – the node from which to start the walk, which is NOT included in the walk.
walker – a function that generates a sequence of nodes. By default this is the depth-first “walk” method.
For post-order traversal, use “walk_leaves_first”. :param restrict_to: optional type filter. By default, all nodes (i.e., subclasses of Node) are included, but you can limit the walk to only a subtype of Node.