Coverage for kye/parser/assign_type_refs.py: 25%

16 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-13 15:17 -0700

1from kye.parser.kye_ast import * 

2 

3def get_defined_type_ref(node: AST): 

4 if isinstance(node, Model): 

5 return node.scope.path 

6 if isinstance(node, TypeAlias): 

7 return (node.scope.path + '.' if node.scope.path else '') + node.name 

8 

9def get_propagated_type_ref(node: AST): 

10 if isinstance(node, Edge): 

11 return node.type_ref + '.' + node.name 

12 return node.type_ref 

13 

14def assign_type_refs(node: AST, parent_type_ref=None): 

15 type_ref = get_defined_type_ref(node) or parent_type_ref 

16 

17 assert type_ref is not None or isinstance(node, Script), 'Type reference not found' 

18 node.type_ref = type_ref 

19 

20 for child in node.children: 

21 assign_type_refs(child, parent_type_ref=get_propagated_type_ref(node))