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

14 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-09-09 14:04 +0000

1"""Protocol defining syntax nodes such as AST, CST, and parse tree nodes.""" 

2 

3from typing import Any, Protocol, Self, runtime_checkable 

4 

5from renaissance.syntax_tree.text_segment import TextSegment 

6 

7 

8@runtime_checkable 

9class SyntaxNode[NodeType](TextSegment, Protocol): 

10 """Protocol for anything that represents syntax nodes. 

11 

12 Syntax nodes include AST nodes, CST nodes, and parse tree nodes. 

13 A syntax node is a text segment. 

14 

15 Read-only access is enforced "as much as possible" by 

16 exposing only @property getters in the protocol 

17 """ 

18 

19 @property 

20 def kind(self) -> str: 

21 """The textual representation of the kind of this node. 

22 

23 The property 'kind' is used to compare syntax nodes. 

24 """ 

25 ... 

26 

27 @property 

28 def children(self) -> list[Self]: 

29 """The children of this node. 

30 

31 The property 'children' is used to compare syntax nodes. 

32 """ 

33 ... 

34 

35 @property 

36 def syntax_attributes(self) -> dict[str, Any]: 

37 """The syntax attributes of this node. 

38 

39 The property 'syntax_attributes' is used to compare syntax nodes. 

40 """ 

41 ... 

42 

43 @property 

44 def parent(self) -> Self | None: 

45 """The parent of this node. 

46 

47 The parent should only be None when the node represents the top of a tree, 

48 such as a compilation unit. 

49 

50 The property 'parent' is not used to compare syntax nodes. 

51 """ 

52 ... 

53 

54 @property 

55 def original_node(self) -> NodeType: 

56 """The original node as produced by the parser. 

57 

58 The property 'original_node' is not used to compare syntax nodes. 

59 """ 

60 ...