Coverage for src/renaissance/syntax_tree/siblings.py: 0%

12 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-10-02 13:12 +0000

1"""AI: Protocol for a contiguous range of sibling syntax nodes.""" 

2 

3from collections.abc import Sequence 

4from typing import Protocol, Self, runtime_checkable 

5 

6from renaissance.syntax_tree.syntax_node import SyntaxNode 

7from renaissance.syntax_tree.text_segment import TextSegment 

8 

9# TODO: Do we only want to wrap the AST sequence matches in AST pattern matching? 

10# or also the parser output? 

11 

12 

13@runtime_checkable 

14class Siblings[NodeType](TextSegment, Protocol): 

15 """Protocol for contiguous siblings, i.e., a range of syntax nodes. 

16 

17 Siblings is a text segment. 

18 When the range of siblings is empty, the start and end offset of the text segment are the same. 

19 Yet, an offset within the text is available. 

20 

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

22 exposing only @property getters in the protocol 

23 """ 

24 

25 @property 

26 def syntax_nodes(self) -> Sequence[SyntaxNode[NodeType]]: 

27 """The sequence of SyntaxNodes corresponding to these siblings.""" 

28 ... 

29 

30 @property 

31 def parent(self) -> Self: 

32 """The parent of these siblings. 

33 

34 The property 'parent' is not used to compare siblings. 

35 """ 

36 ... 

37 

38 @property 

39 def original_nodes(self) -> Sequence[NodeType]: 

40 """The sequence of original nodes of these siblings as produced by the parser. 

41 

42 The property 'original_nodes' is not used to compare siblings. 

43 """ 

44 ...