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

12 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: Protocol for a contiguous range of sibling syntax nodes.""" 

8 

9from collections.abc import Sequence 

10from typing import Protocol, runtime_checkable 

11 

12from renaissance.syntax_tree.syntax_node import SyntaxNode 

13from renaissance.syntax_tree.text_segment import TextSegment 

14 

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

16# or also the parser output? 

17 

18 

19@runtime_checkable 

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

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

22 

23 Siblings is a text segment. 

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

25 Yet, an offset within the text is available. 

26 

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

28 exposing only @property getters in the protocol 

29 """ 

30 

31 @property 

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

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

34 ... 

35 

36 @property 

37 def parent(self) -> SyntaxNode[NodeType]: 

38 """The syntax node containing these siblings. 

39 

40 Siblings only exist relative to a containing node, so the parent is never None, 

41 even when the range of siblings is empty. 

42 

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

44 """ 

45 ... 

46 

47 @property 

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

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

50 

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

52 """ 

53 ...