Coverage for src/renaissance/syntax_tree/node_protocol.py: 100%
19 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
1# Copyright (C) 2024-2026 TNO
2#
3# Licensed under the terms specified in the LICENSE file in the root directory
4# of this repository, also available at:
5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE
7"""AI: Structural protocol describing the interface consumed by generic syntax-tree algorithms."""
9from collections.abc import Mapping, Sequence
10from typing import Any, Protocol, Self, runtime_checkable
12from renaissance.syntax_tree.semantic_kind import SemanticKind
15@runtime_checkable
16class NodeProtocol(Protocol):
17 """Structural interface consumed by generic syntax-tree algorithms."""
19 # Read-only members keep the protocol covariant, so implementations may expose them as properties.
20 @property
21 def parser_kind(self) -> str:
22 """Node kind as reported by the underlying parser."""
23 ...
25 @property
26 def semantic_kind(self) -> SemanticKind:
27 """Language-independent classification of this node."""
28 ...
30 @property
31 def properties(self) -> Mapping[str, Any]:
32 """Parser-supplied attributes of this node."""
33 ...
35 @property
36 def parent(self) -> Self | None:
37 """Enclosing node, or None at the root."""
38 ...
40 @property
41 def children(self) -> Sequence[Self]:
42 """Direct child nodes, in source order."""
43 ...
45 @property
46 def signature(self) -> str:
47 """Source text of this node."""
48 ...
50 @property
51 def name(self) -> str:
52 """Declared name of this node, or an empty string if it has none."""
53 ...