Coverage for src/renaissance/syntax_tree/node_protocol.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-15 10:34 +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 

6 

7"""AI: Structural protocol describing the interface consumed by generic syntax-tree algorithms.""" 

8 

9from collections.abc import Mapping, Sequence 

10from typing import Any, Protocol, Self, runtime_checkable 

11 

12from .semantic_kind import SemanticKind 

13 

14 

15@runtime_checkable 

16class NodeProtocol(Protocol): 

17 """Structural interface consumed by generic syntax-tree algorithms.""" 

18 

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 ... 

24 

25 @property 

26 def semantic_kind(self) -> SemanticKind: 

27 """Language-independent classification of this node.""" 

28 ... 

29 

30 @property 

31 def properties(self) -> Mapping[str, Any]: 

32 """Parser-supplied attributes of this node.""" 

33 ... 

34 

35 @property 

36 def children(self) -> Sequence[Self]: 

37 """Direct child nodes, in source order.""" 

38 ... 

39 

40 @property 

41 def signature(self) -> str: 

42 """Source text of this node.""" 

43 ... 

44 

45 @property 

46 def name(self) -> str: 

47 """Declared name of this node, or an empty string if it has none.""" 

48 ...